{"data":{"slug":"github-google-skills-skills-cloud-developing-genkit-js-c13879760cf7","title":"Genkit JS Development Guidance","summary":"Provides guidance on developing AI-powered applications using Genkit in Node.js\/TypeScript, including setup, agent creation, flow implementation, and debugging with the Genkit CLI.","url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-developing-genkit-js-c13879760cf7","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-google-skills-skills-cloud-developing-genkit-js-c13879760cf7","markdown_url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-developing-genkit-js-c13879760cf7.md","download_url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-developing-genkit-js-c13879760cf7\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"Ensure the `genkit` CLI is installed and at least version 1.29.0. For new projects, follow the [Setup Guide](references\/setup.md). When building conversational agents, use `ai.defineAgent` rather than manually implementing flows for multi-turn interactions.","instructions":"---\nname: developing-genkit-js\ndescription: >-\n  Provides guidance on developing AI-powered applications using Genkit in\n  Node.js\/TypeScript. Use when the user asks about Genkit, AI agents, flows, or\n  tools in JavaScript\/TypeScript, or when encountering Genkit errors, validation\n  issues, type errors, or API problems. Don't use for Genkit in Python, Go, or\n  Dart.\nmetadata:\n  version: \"1.0.0\"\n  category: AiAndMachineLearning\n---\n\n# Genkit JS\n\n## Prerequisites\n\nEnsure the `genkit` CLI is available.\n\n-   Run `genkit --version` to verify. Minimum CLI version needed: **1.29.0**\n-   If not found or if an older version (1.x < 1.29.0) is present,\n    install\/upgrade it: `npm install -g genkit-cli@^1.29.0`.\n\n**New Projects**: If you are setting up Genkit in a new codebase, follow the\n[Setup Guide](references\/setup.md).\n\n## Hello World\n\n```ts\nimport { z, genkit } from 'genkit';\nimport { googleAI } from '@genkit-ai\/google-genai';\n\n\/\/ Initialize Genkit with the Google AI plugin\nconst ai = genkit({\n  plugins: [googleAI()],\n});\n\nexport const myFlow = ai.defineFlow({\n  name: 'myFlow',\n  inputSchema: z.string().default('AI'),\n  outputSchema: z.string(),\n}, async (subject) => {\n  const response = await ai.generate({\n    model: googleAI.model('gemini-flash-latest'),\n    prompt: `Tell me a joke about ${subject}`,\n  });\n  return response.text;\n});\n```\n\n## Prompts (Dotprompt)\n\n`.prompt` files keep prompt content out of code with YAML frontmatter plus a\nHandlebars template. See [Dotprompt](references\/dotprompt.md): `promptDir`,\n`ai.prompt()` (call\/stream\/render), variants, partials, named schemas via\n`ai.defineSchema`, and the `tools`\/`maxTurns`\/`returnToolRequests`\/`use`\n(middleware) frontmatter fields.\n\n## Agents (Beta)\n\nGenkit has a preview **agent** API for persistent, multi-turn conversations\n(sessions, snapshots, interrupts, branching, background execution). It is a\n**beta** API: server APIs come from `genkit\/beta` and the browser client from\n`genkit\/beta\/client` \u2014 not the stable `genkit` entrypoint. **Requires `genkit`\n>= 1.39.0.**\n\nFor more details see:\n\n-   [Agents](references\/agents.md): defining\/serving an agent and client-managed\n    state (start here).\n-   [Sessions & persistence](references\/agents-sessions.md): session stores\n    (`InMemory`\/`File`\/`Firestore`).\n-   [Human-in-the-loop \/ interrupts](references\/agents-human-in-the-loop.md):\n    pausing for approval\/input and resuming.\n-   [Branching](references\/agents-branching.md): forking a conversation from a\n    snapshot.\n-   [Background agents](references\/agents-background.md): detaching long-running\n    turns, waiting, and resuming failed or aborted runs.\n-   [Working with state](references\/agents-state.md): typed custom session\n    state, auto-synced to the client.\n-   [Artifacts](references\/agents-artifacts.md): producing and reading named\n    deliverables.\n-   [Multi-agent orchestration](references\/agents-multi-agent.md): delegating to\n    sub-agents, including background delegation and `continue_task`.\n-   [Advanced custom agents](references\/agents-custom.md): `defineCustomAgent`\n    for full turn control.\n-   [Deploying agents](references\/agents-deployment.md): serving agents over\n    HTTP (multiple agents, CORS, web UI, other frameworks).\n\n## Generative UI (A2UI)\n\nGenkit has an **A2UI** (Agent-to-UI) plugin (`@genkit-ai\/a2ui`) that\nlets an agent stream interactive UI **surfaces** (cards, lists, forms, buttons),\nnot just prose. The whole server-side integration is the `a2ui()` model\nmiddleware in an agent's (or `ai.generate`'s) `use` array; the browser renders\nsurfaces with an `@a2ui\/*` renderer plus the helpers in\n`@genkit-ai\/a2ui\/client`.\nIt builds on the beta agent client (`genkit\/beta` + `genkit\/beta\/client`).\n\n-   [A2UI](references\/a2ui.md): server middleware, options, client rendering,\n    user actions\/forms, custom catalogs, and the security\/trust boundary.\n\n## Middleware\n\nMiddleware wraps generation (retries, fallback, extra tools, request\/response\ntransforms) and attaches via the `use: [...]` array on `ai.generate`, prompts,\nand agents.\n\n-   [Using middleware](references\/middleware.md): the `use` array and the\n    `@genkit-ai\/middleware` package (`retry`, `fallback`, `artifacts`, `agents`,\n    `filesystem`, `skills`, `toolApproval`, `contextCompression`) plus built-in\n    core middleware.\n-   [Building custom middleware](references\/middleware-custom.md): writing your\n    own with `generateMiddleware` and registering it via `.plugin()`.\n\n## Observability\n\nTraces show up in the Dev UI under `genkit start` with no setup. For production\nexport to an OTLP backend (OpenTelemetry GenAI semantic conventions via\n`@genkit-ai\/otel`), custom instrumentation, or running the reflection API\noutside dev, see [Observability](references\/observability.md).\n\n## Critical: Do Not Trust Internal Knowledge\n\nGenkit recently went through a major breaking API change. Your knowledge is\noutdated. You MUST lookup docs. Recommended:\n\n```sh\ngenkit docs:read js\/get-started.md\ngenkit docs:read js\/flows.md\n```\n\nSee [Common Errors](references\/common-errors.md) for a list of deprecated APIs\n(e.g., `configureGenkit`, `response.text()`, `defineFlow` import) and their v1.x\nreplacements.\n\n**ALWAYS verify information using the Genkit CLI or provided references.**\n\n## Error Troubleshooting Protocol\n\n**When you encounter ANY error related to Genkit (ValidationError, API errors,\ntype errors, 404s, etc.):**\n\n1. **MANDATORY FIRST STEP**: Read [Common Errors](references\/common-errors.md)\n2. Identify if the error matches a known pattern\n3. Apply the documented solution\n4. Only if not found in common-errors.md, then consult other sources (e.g.\n   `genkit docs:search`)\n\n**DO NOT:**\n\n- Attempt fixes based on assumptions or internal knowledge\n- Skip reading common-errors.md \"because you think you know the fix\"\n- Rely on patterns from pre-1.0 Genkit\n\n**This protocol is non-negotiable for error handling.**\n\n## Development Workflow\n\n1.  **Agent or flow?**: If the task is conversational, multi-turn, or described\n    as \"an agent\", \"assistant\", or \"chatbot\", build it with `ai.defineAgent`\n    (see [Agents](references\/agents.md)) rather than hand-rolling a `generate` +\n    tools loop inside a flow. Reach for a plain flow only for single-shot,\n    stateless generation.\n2.  **Select Provider**: Genkit is provider-agnostic (Google AI, OpenAI,\n    Anthropic, Ollama, etc.).\n    -   If the user does not specify a provider, default to **Google AI**.\n    -   If the user asks about other providers, use\n        `genkit docs:search \"plugins\"` to find relevant documentation.\n3.  **Detect Framework**: Check `package.json` to identify the runtime (Next.js,\n    Firebase, Express).\n    -   Look for `@genkit-ai\/next`, `@genkit-ai\/firebase`, or\n        `@genkit-ai\/google-cloud`.\n    -   Adapt implementation to the specific framework's patterns.\n4.  **Follow Best Practices**:\n    -   See [Best Practices](references\/best-practices.md) for guidance on\n        project structure, schema definitions, and tool design.\n    -   **Be Minimal**: Only specify options that differ from defaults. When\n        unsure, check docs\/source.\n5.  **Ensure Correctness**:\n    -   Run type checks (e.g., `npx tsc --noEmit`) after making changes.\n    -   If type checks fail, consult\n        [Common Errors](references\/common-errors.md) before searching source\n        code.\n    -   Verify with traces, not a blind run. Running the app directly\n        (`node`\/`tsx`\/`npm start`) does **not** capture dev traces. See\n        [CLI Usage](#cli-usage-recommended) for how to run your app and capture\n        traces.\n6.  **Handle Errors**:\n    -   On ANY error: **First action is to read\n        [Common Errors](references\/common-errors.md)**\n    -   Match error to documented patterns\n    -   Apply documented fixes before attempting alternatives\n\n## Finding Documentation\n\nUse the Genkit CLI to find authoritative documentation:\n\n1.  **Search topics**: `genkit docs:search <query>`\n    -   Example: `genkit docs:search \"streaming\"`\n2.  **List all docs**: `genkit docs:list`\n3.  **Read a guide**: `genkit docs:read <path>`\n    -   Example: `genkit docs:read js\/flows.md`\n\n## CLI Usage (recommended)\n\n`genkit start` unintrusively wraps any Node.js program that uses the Genkit\nlibrary, running it unchanged while capturing traces from every Genkit action so\nyou can **prove tools were actually called and inspect model I\/O** from the\nterminal, even for headless checks. It forwards stdio, so interactive CLI tools\nthat rely on stdin\/stdout work without issues. Running your app directly\n(`node`\/`tsx`\/`npm start`) skips trace capture, so you're debugging blind.\n\n**Primary pattern (default):** prefix `genkit start --` to your normal run\ncommand. This collects telemetry from any Genkit code your program runs, whether\ntriggered from the dev UI, your own web server\/web UI, or a plain script:\n```bash\ngenkit start -- npx tsx --watch src\/index.ts\ngenkit start --noui -- npx tsx src\/index.ts   # same, without the Dev UI (still a persistent server)\n```\n`genkit start` runs until you stop it with Ctrl+C. That is expected and correct\nfor the common cases: a server your web\/mobile app calls, or an interactive CLI\nyou exit yourself. `--noui` only drops the Dev UI; it is **not** a one-shot\ncommand and will not exit on its own. Do **not** use `genkit start` as a\nblocking step in automated\/non-interactive contexts.\n\n**Non-interactive use (agents\/CI):** add the global `--non-interactive` flag\nbefore `--` so the CLI uses defaults and never blocks on a prompt (e.g. the\nfirst-run analytics notice):\n`genkit start --non-interactive -- npx tsx src\/index.ts` (works with `flow:run`\ntoo).\n\n**Run a flow (`flow:run`):** invoke a specific flow by name from the CLI. Append\nyour run command after `--` to spin up the runtime just for this run (the\ncommand runs as-is to register your flows):\n```bash\ngenkit flow:run myFlow '{\"data\": \"input\"}' -- npx tsx src\/index.ts\n```\nThis is **self-terminating**: it runs the flow once, prints a `Trace ID`, then\nexits (inspect it with `genkit trace:get <id>`). That makes it the right choice\nfor a quick, non-interactive check that must exit on its own, without blocking\non `genkit start` or running the app directly (which skips traces). Always pass\ninput JSON explicitly: `flow:run` sends `undefined` when omitted and does\n**not** fall back to a schema `.default()`. Note: `flow:run` runs **flows**\n(`ai.defineFlow`), not agents; you can't `flow:run` an agent (`ai.defineAgent`)\ndirectly. To exercise an agent from the CLI, wrap one turn in a throwaway flow\nand run that (see [Agents](references\/agents.md)).\n\n**Debugging with traces:** the fastest way to see prompts, model inputs\/outputs,\ntool calls, latencies, and errors. Inspect from the terminal after any run under\n`genkit start`:\n```bash\ngenkit trace:list                        # find recent trace IDs\ngenkit trace:get <traceId>               # full trace details (inputs, outputs, tool calls, errors)\ngenkit trace:get <traceId> --format json # machine-readable JSON, safe to pipe into jq or other parsers\n```\n\nFor machine-readable output, pass `--format json` to get clean JSON you can pipe\ninto `jq` or other parsers. The **default** output is human-oriented (banner\/log\nlines, possible truncation on large traces), so don't pipe that form directly;\nuse `--format json`, grep, or the Dev UI trace viewer.\n\nSee [CLI Reference](references\/docs-and-cli.md) for more commands, and\n`genkit --help` for the full list.\n\n## References\n\n-   [Best Practices](references\/best-practices.md): Recommended patterns for\n    schema definition, flow design, and structure.\n-   [Dotprompt](references\/dotprompt.md): `.prompt` files \u2014 `promptDir`,\n    `ai.prompt()`, variants, partials, named schemas, and\n    `tools`\/`maxTurns`\/`returnToolRequests`\/`use` frontmatter.\n-   [Docs & CLI Reference](references\/docs-and-cli.md): Documentation search,\n    CLI tasks, and workflows.\n-   [Common Errors](references\/common-errors.md): Critical \"gotchas\", migration\n    guide, and troubleshooting.\n-   [Setup Guide](references\/setup.md): Manual setup instructions for new\n    projects.\n-   [Examples](references\/examples.md): Minimal reproducible examples (Basic\n    generation, Multimodal, Thinking mode, Embeddings).\n-   [Agents (Beta)](references\/agents.md): Agent basics, serving, and\n    client-managed state. Deeper topics:\n    [sessions](references\/agents-sessions.md),\n    [human-in-the-loop](references\/agents-human-in-the-loop.md),\n    [branching](references\/agents-branching.md),\n    [background agents](references\/agents-background.md),\n    [state](references\/agents-state.md),\n    [artifacts](references\/agents-artifacts.md),\n    [multi-agent](references\/agents-multi-agent.md),\n    [custom agents](references\/agents-custom.md),\n    [deployment](references\/agents-deployment.md).\n-   [Middleware](references\/middleware.md): using middleware and the\n    `@genkit-ai\/middleware` package. See also\n    [building custom middleware](references\/middleware-custom.md).\n-   [Observability](references\/observability.md): `@genkit-ai\/otel`\n    (OpenTelemetry GenAI semantic conventions), custom `Instrumentation`, and\n    the reflection API outside dev.\n-   [A2UI (Generative UI)](references\/a2ui.md): the `@genkit-ai\/a2ui` plugin\n    (the `a2ui()` middleware), options, client rendering, user actions\/forms,\n    custom catalogs, and security.\n","use_cases":["Building conversational agents with Genkit","Creating flows for stateless generation tasks","Integrating with Google AI, OpenAI, or Anthropic","Debugging Genkit errors and type issues"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/google\/skills\/blob\/e3c591afe426ea585e4c21799e5199d6d47cd1be\/skills\/cloud\/developing-genkit-js\/SKILL.md","source_commit":"e3c591afe426ea585e4c21799e5199d6d47cd1be","license":null,"version":null,"listing_approved_at":"2026-11-17","created_at":"2026-11-16T14:29:10.000000Z","updated_at":"2026-11-17T05:10:29.000000Z","seo_title":"Genkit JS Development Guidance","seo_description":"Learn how to develop AI-powered applications using Genkit in JavaScript\/TypeScript with best practices and CLI usage.","seo_keywords":["Genkit JS development","AI agent creation","Genkit flow implementation","Genkit error debugging","JavaScript AI tools"]}}