developing-genkit-js
它能做什么
这个技能帮助开发者使用 Genkit SDK 在 JavaScript 和 TypeScript 中构建 AI 功能。它适用于想加入智能体或模型调用的网页和 Node.js 团队。
适用场景
- ✓当你想使用 Genkit 在 JavaScript 或 TypeScript 中构建 AI 智能体、流程或工具的时候。
- ✓当你在 Node.js 项目中修复 Genkit 错误、验证问题或类型错误的时候。
- ✓当你想在 Genkit 应用中使用提示词文件和多轮智能体对话的时候。
技能链接
https://github.com/google/skills/blob/main/skills/cloud/developing-genkit-js/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请在我的 TypeScript 项目中设置 Genkit,并创建一个为某个主题写笑话的流程。”
每周 5 个新技能,1 分钟读完。
工作原理
它会先检查 genkit CLI 的版本,然后使用 Genkit API 编写流程、工具和提示词的 TypeScript 代码。它会为设置和具体功能指向参考指南。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Genkit JS
Prerequisites
Ensure the genkit CLI is available.
- Run
genkit --versionto verify. Minimum CLI version needed: 1.29.0 - If not found or if an older version (1.x < 1.29.0) is present, install/upgrade it:
npm install -g genkit-cli@^1.29.0.
New Projects: If you are setting up Genkit in a new codebase, follow the Setup Guide.
Hello World
import { z, genkit } from 'genkit';
import { googleAI } from '@genkit-ai/google-genai';
// Initialize Genkit with the Google AI plugin
const ai = genkit({
plugins: [googleAI()],
});
export const myFlow = ai.defineFlow({
name: 'myFlow',
inputSchema: z.string().default('AI'),
outputSchema: z.string(),
}, async (subject) => {
const response = await ai.generate({
model: googleAI.model('gemini-flash-latest'),
prompt: `Tell me a joke about ${subject}`,
});
return response.text;
});
Prompts (Dotprompt)
.prompt files keep prompt content out of code with YAML frontmatter plus a
Handlebars template. See Dotprompt: promptDir,
ai.prompt() (call/stream/render), variants, partials, named schemas via
ai.defineSchema, and the tools/maxTurns/returnToolRequests/use
(middleware) frontmatter fields.
Agents (Beta)
Genkit has a preview agent API for persistent, multi-turn conversations
(sessions, snapshots, interrupts, branching, background execution). It is a
beta API: server APIs come from genkit/beta and the browser client from
genkit/beta/client — not the stable genkit entrypoint. **Requires genkit
= 1.39.0.**
For more details see:
- Agents: defining/serving an agent and client-managed state (start here).
- Sessions & persistence: session stores (
InMemory/File/Firestore). - Human-in-the-loop / interrupts: pausing for approval/input and resuming.
- Branching: forking a conversation from a snapshot.
- Background agents: detaching long-running turns, waiting, and resuming failed or aborted runs.
- Working with state: typed custom session state, auto-synced to the client.
- Artifacts: producing and reading named deliverables.
- Multi-agent orchestration: delegating to sub-agents, including background delegation and
continue_task. - Advanced custom agents:
defineCustomAgentfor full turn control. - Deploying agents: serving agents over HTTP (multiple agents, CORS, web UI, other frameworks).
Generative UI (A2UI)
Genkit has an A2UI (Agent-to-UI) plugin (@genkit-ai/a2ui) that
lets an agent stream interactive UI surfaces (cards, lists, forms, buttons),
not just prose. The whole server-side integration is the a2ui() model
middleware in an agent's (or ai.generate's) use array; the browser renders
surfaces with an @a2ui/* renderer plus the helpers in @genkit-ai/a2ui/client.
It builds on the beta agent client (genkit/beta + genkit/beta/client).
- A2UI: server middleware, options, client rendering, user actions/forms, custom catalogs, and the security/trust boundary.
Middleware
Middleware wraps generation (retries, fallback, extra tools, request/response
transforms) and attaches via the use: [...] array on ai.generate, prompts,
and agents.
- Using middleware: the
usearray and the@genkit-ai/middlewarepackage (retry,fallback,artifacts,agents,filesystem,skills,toolApproval,contextCompression) plus built-in core middleware. - Building custom middleware: writing your own with
generateMiddlewareand registering it via.plugin().
Observability
Traces show up in the Dev UI under genkit start with no setup. For production
export to an OTLP backend (OpenTelemetry GenAI semantic conventions via
@genkit-ai/otel), custom instrumentation, or running the reflection API
outside dev, see Observability.
Critical: Do Not Trust Internal Knowledge
Genkit recently went through a major breaking API change. Your knowledge is outdated. You MUST lookup docs. Recommended:
genkit docs:read js/get-started.md
g
常见问题
需要哪个版本的 genkit CLI?
1.29.0 或更高版本。该技能可以为你安装或升级。
它涵盖提示词文件吗?
涵盖。它涵盖带有模板和模式的 Dotprompt 文件。
它支持智能体吗?
支持。它涵盖用于多轮对话的预览版智能体 API。
详情
作者的原始描述
Develop AI-powered applications using Genkit in Node.js/TypeScript. Use when the user asks about Genkit, AI agents, flows, or tools in JavaScript/TypeScript, or when encountering Genkit errors, validation issues, type errors, or API problems.
repo: google/skills
热度
- GitHub 星标
- 22k
- 排名
- #10257
- 许可证
- Apache-2.0
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
finding-google-skills
22k帮你的智能体为某项设置任务找到合适的 Google 指南,例如托管、数据库、存储、登录或 AI 模型服务。
gcloud
22k帮你的智能体编写并检查 Google Cloud gcloud 命令,在运行任何内容之前查阅准确的语法,避免猜测参数。
google-cloud-recipe-auth
22k引导你的智能体了解 Google Cloud 的身份与访问管理,包括人员和服务如何登录,以及它们各自获得哪些权限。
google-cloud-recipe-onboarding
22k带领新开发者完成在 Google Cloud 上的第一步,包括选择项目、关联计费,以及部署第一个资源。