Index of every page on this site: llms.txt
All skills
genkit-ai avatar

/developing-genkit-js

@d12c988
by Genkitgenkit-ai/skills40 stars
13
Run it yourself

Provides guidance on developing 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. Don't use for Genkit in Python, Go, or Dart.

Use this Skill: https://skilld.dev/gh/genkit-ai/skills/developing-genkit-js

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesdotprompt.md

≈1.5k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Dotprompt (.prompt files) — Genkit JS


What it is

.prompt files combine YAML frontmatter (model, config, schemas, tools, middleware) with a Handlebars template. They keep prompt logic out of your TypeScript code and make variants and iteration easy.

Where files live

By default Genkit loads .prompt files from ./prompts. Configure with the promptDir option (set to null to disable auto-loading):

import { genkit } from 'genkit';
import { googleAI } from '@genkit-ai/google-genai';

const ai = genkit({
  plugins: [googleAI()],
  promptDir: './prompts', // default
});

File format

prompts/recipe.prompt:

---
model: googleai/gemini-pro-latest
input:
  schema:
    food: string
    ingredients?(array): string   # ? = optional
output:
  schema: Recipe                  # references a schema registered via ai.defineSchema
---
You are a chef famous for creative recipes.

Generate a recipe for {{food}}.

{{#if ingredients}}
Make sure to include the following ingredients:
{{list ingredients}}
{{/if}}

Schema fields use Picoschema (the compact form above) or you can reference a named schema registered with ai.defineSchema.

Loading and calling a prompt

ai.prompt(name, { variant? }) returns an ExecutablePrompt. The returned object is callable and also has .stream(), .render(), and .asTool().

// Non-streaming: call it like a function with the input object.
const recipePrompt = ai.prompt('recipe');
const { output } = await recipePrompt({ food: 'banana bread' });

// With a typed output schema
const RecipeSchema = ai.defineSchema('Recipe', z.object({
  title: z.string(),
  steps: z.array(z.string()),
}));
const result = await ai.prompt<any, typeof RecipeSchema>('recipe')({ food: 'banana bread' });
result.output; // typed as Recipe

Streaming

const storyPrompt = ai.prompt('story');
const { response, stream } = storyPrompt.stream({ subject: 'a robot' });
for await (const chunk of stream) {
  console.log(chunk.text);
}
const final = await response;

Render without generating

Useful for building ai.generate calls or LLM-judge evals:

const rendered = await ai.prompt('recipe').render({ food: 'banana bread' });
// rendered is a GenerateOptions object (messages, model, config, ...)

Registering named schemas

Reference a schema by name in .prompt frontmatter (input.schema / output.schema) after registering it:

import { z } from 'genkit';

const RecipeSchema = ai.defineSchema(
  'Recipe',
  z.object({
    title: z.string().describe('recipe title'),
    ingredients: z.array(z.object({ name: z.string(), quantity: z.string() })),
    steps: z.array(z.string()).describe('the steps required'),
  })
);

Variants

Name the file <name>.<variant>.prompt — e.g. recipe.robot.prompt. Call with the variant option:

await ai.prompt('recipe', { variant: 'robot' })({ food: 'oil cake' });

Partials

Reusable template fragments. Name a partial file _<name>.prompt and include it with {{>name param=value}}.

prompts/_style.prompt:

{{ role "system" }}
You should speak as if you are a {{#if personality}}{{personality}}{{else}}pirate{{/if}}.
{{role "user"}}

prompts/story.prompt:

---
model: googleai/gemini-pro-latest
input:
  schema:
    subject: string
    personality?: string
---
{{>style personality=personality}}

Tell me a story about {{subject}}.

Helpers

Register a function callable inside templates:

ai.defineHelper('list', (data: any) =>
  Array.isArray(data) ? data.map((item) => `- ${item}`).join('\n') : ''
);

Then use {{list ingredients}} in the template.

Tools, tool-loop control, and middleware

.prompt frontmatter can configure tool calling and attach middleware, so an agent-style prompt is fully described in the file:

---
model: googleai/gemini-flash-latest
input:
  schema:
    tone: string
tools:
  - getAttractions
  - getFlightInfo
toolChoice: auto          # auto | required | none
maxTurns: 20              # max tool-call loop iterations
returnToolRequests: false # return tool requests instead of running them
use:
  - name: retry           # bare string also works: `- retry`
    config:
      maxRetries: 4
---
{{role "system"}}
You are a friendly trip planning assistant. Help users plan trips by suggesting
attractions and looking up flight information. Keep your tone {{tone}}.

{{history}}
  • tools: list of registered tool names.
  • toolChoice, maxTurns, returnToolRequests: same semantics as the equivalent ai.generate options.
  • use: list of middleware refs. Each entry is a bare string (middleware name) or a map with name and optional config. Names resolve against middleware registered on the Genkit instance — register the middleware plugin so the name is available:
import { retry } from '@genkit-ai/middleware';

const ai = genkit({
  plugins: [googleAI(), retry.plugin()],
  promptDir: './prompts',
});

See Using middleware for the full list of built-in middleware.

Relationship to agents

Agents (defineAgent) share the same dotprompt frontmatter — system/prompt, tools, maxTurns, returnToolRequests, and use. A .prompt file with {{history}} and tools can back an agent directly. See Agents.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts13d5 checks · Risk SAFE
  • Gen Agent Trust Hub14d

    The skill is a comprehensive development guide for the Genkit JS framework. It provides technical instructions, code examples, and troubleshooting steps. All referenced tools and packages are official or standard industry dependencies. No security risks were identified.

  • Socket13d

    No alerts

  • Snyk14d

    Risk: LOW · No issues

  • Runlayer8mo

    6 files scanned · No issues

  • ZeroLeaks7mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at d12c988. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 4 days ago.

Activeupdated 2 weeks ago
metadata
{
  "version": "1.0.0",
  "category": "AiAndMachineLearning"
}
  • TypeScript
  • genkit
  • nodejs
  • ai-agents
  • flows
  • llm
  • google-ai
  • openai
  • anthropic

README badge

README badge for genkit-ai/skills/developing-genkit-js

Develop AI-powered applications using Genkit in Node.js and TypeScript, including flows, tools, and multi-model integrations. Covers Genkit CLI setup, flow definition with schema validation, provider selection (Google AI, OpenAI, Anthropic, Ollama), and error troubleshooting for version 1.29.0 and later.

Generated from the current SKILL.md.

What Genkit CLI version does this skill require?
Minimum CLI version 1.29.0. Verify with `genkit --version` and upgrade with `npm install -g genkit-cli@^1.29.0` if needed.
Does this skill cover pre-1.0 Genkit or older versions?
No. Genkit went through a major breaking API change. This skill assumes v1.x (1.29.0+) and will not reliably handle pre-1.0 code or deprecated APIs.
What AI providers does this skill support?
Genkit is provider-agnostic and supports Google AI, OpenAI, Anthropic, Ollama, and others. The skill defaults to Google AI if no provider is specified.
How should I troubleshoot Genkit errors?
Always read the Common Errors reference first to identify known patterns and their fixes. Use `genkit docs:search` only if the error is not documented there.
Does this skill work with Next.js, Firebase, or Express?
Yes. The skill detects your framework via package.json and adapts the implementation to framework-specific patterns like @genkit-ai/next or @genkit-ai/firebase.

Generated from the current SKILL.md. These answers refresh after source changes.