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

/developing-genkit-dart

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

Provides guidance on developing AI-powered applications using the Genkit Dart SDK. Use when the user asks to build AI agents in Dart, use Genkit flows, or integrate LLMs into Dart/Flutter applications. Don't use for Genkit in JavaScript/TypeScript, Go, or Python.

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

Nothing lands on disk. Nothing to clean up.

Fork this Skill

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

referencesdotprompt.md

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

Dotprompt (.prompt files) — Genkit Dart


What it is

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

Where files live

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

import 'package:genkit/genkit.dart';
import 'package:genkit_google_genai/genkit_google_genai.dart';

final ai = Genkit(
  plugins: [googleAI()],
  promptDir: './prompts', // default
);

File format

prompts/greeting.prompt:

---
model: googleai/gemini-flash-latest
input:
  schema:
    name: string
    style: string
---
{{role "system"}}
You are a {{style}} greeter.

{{role "user"}}
Greet {{name}}.

Schema fields use Picoschema (the compact form above) or you can reference a named schema registered with defineSchema. A top-level type or properties key makes it plain JSON Schema instead.

Picoschema follows the spec, same as JS/Go/Python:

schema:
  name: string, the person to greet     # description goes after a comma
  nickname?: string                      # optional (and nullable)
  tags(array, relevant tags): string     # array of strings
  steps(array):                          # array of objects
    instruction: string
  address?(object):                      # nested object
    city: string
  status(enum, approval status): [PENDING, APPROVED]
  extra?: any
  (*): string                            # wildcard: additionalProperties

The parenthetical is only for a type keyword (array, object, enum) plus an optional description. email(the user email): string is invalid; write email: string, the user email. A prompt with an invalid schema logs a warning when the folder loads and throws GenkitException (invalidArgument) when it is rendered; other prompts keep working. A schema name that is still not registered with defineSchema at render time throws too (failedPrecondition); names may be registered after the folder loads.

Loading and calling a prompt

ai.prompt(name, {variant}) returns a Future<Prompt<Input, Output>>. The resolved Prompt is a callable object: invoke it like a function. The input is a positional argument (there is no input: named parameter).

// Non-streaming
final greetingPrompt = await ai.prompt('greeting');
final response = await greetingPrompt({
  'name': 'World',
  'style': 'cheerful',
});
print(response.text);

Per-call generation options are named parameters after the input, with the same names as ai.generate: config, model, messages, tools, toolNames, toolChoice, returnToolRequests, maxTurns, output, context, use, cancel (render takes all but context/cancel). There is no options object to wrap them in.

final followUp = await greetingPrompt(
  {'name': 'World', 'style': 'cheerful'},
  config: {'temperature': 0.2}, // merged per key with the prompt's config
  messages: history, // prior turns
  tools: [lookupTool], // appended to the prompt's tools (same for toolNames/use)
  use: [retry()],
);

Typed output

response.output is typed by the prompt's Output. A .prompt file's output.schema has no Dart type, so pass outputParserSchema to parse into one (it is never sent to the model; the file's schema is):

// Inferred as Prompt<dynamic, Recipe>
final recipePrompt = await ai.prompt(
  'recipe',
  outputParserSchema: Recipe.$schema,
);
final Recipe? recipe = (await recipePrompt({'food': 'pasta'})).output;

// Code-defined with outputSchema: already typed, just name the types.
final joke = await ai.prompt<JokeInput, Joke>('joke');

ai.definePrompt(..., outputSchema: Joke.$schema) returns a Prompt<JokeInput, Joke> directly. A prompt's .ref is a PromptRef (name, metadata).

Streaming

final storyPrompt = await ai.prompt('story');
final stream = storyPrompt.stream({'subject': 'a robot'});
await for (final chunk in stream) {
  print(chunk.text);
}

Render without generating

Returns GenerateActionOptions (messages, model, config) without calling the model — useful for building ai.generate calls or evals:

final greetingPrompt = await ai.prompt('greeting');
final rendered = await greetingPrompt.render({'name': 'World', 'style': 'casual'});
rendered.model;    // resolved model
rendered.messages; // rendered messages

Registering named schemas

Reference a schema by name in .prompt frontmatter (input.schema / output.schema) after registering it with defineSchema (a JSON Schema map):

ai.defineSchema('Recipe', {
  'type': 'object',
  'properties': {
    'title': {'type': 'string'},
    'steps': {'type': 'array', 'items': {'type': 'string'}},
  },
  'required': ['title', 'steps'],
});

Then in recipe.prompt:

---
model: googleai/gemini-flash-latest
input:
  schema:
    food: string
output:
  schema: Recipe
  format: json
---
Generate a recipe for {{food}}.

For code-defined prompts (ai.definePrompt) you typically pass a schemantic-generated schema (e.g. JokeInput.schema) as inputSchema.

Variants

Name the file <name>.<variant>.prompt — e.g. greeting.formal.prompt. Load with the variant argument:

final formalPrompt = await ai.prompt('greeting', variant: 'formal');
final response = await formalPrompt({'name': 'Dr. Smith', 'title': 'Professor'});

Partials

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

prompts/_signature.prompt referenced from another template:

Write a short email to {{recipient}} about {{subject}}.

{{> signature}}

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. This is based on prompts/tripPlanner.prompt from the agents testapp (with returnToolRequests shown for completeness):

---
model: googleai/gemini-flash-latest
input:
  schema:
    tone: string
tools:
  - getAttractions
  - getFlightInfo
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. Use the available tools to provide
accurate, up-to-date 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. retry (above) is built in; for genkit_middleware names, register the plugin so the name is available:
import 'package:genkit_middleware/skills.dart';

final ai = Genkit(
  plugins: [
    googleAI(),
    SkillsPlugin(), // makes `use: [skills]` resolve
  ],
  promptDir: './prompts',
);

See genkit_middleware for the middleware package.

Backing an agent with a .prompt file

definePromptAgent wires an agent directly to a .prompt file by name. The frontmatter (tools, maxTurns, use, ...) applies to the agent, and promptInput supplies template variables:

final tripPlannerAgent = ai.definePromptAgent(
  promptName: 'tripPlanner',            // -> prompts/tripPlanner.prompt
  promptInput: {'tone': 'enthusiastic'}, // fills {{tone}}
  store: InMemorySessionStore(),
);

See Agents for defining and serving 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.

1 alert2d4 checks · Risk SAFE
  • Gen Agent Trust Hub3d

    The Genkit Dart skill provides comprehensive documentation and examples for building AI agents and flows using the Genkit framework. It includes guidance on using A2UI for interactive interfaces, managing agent sessions, and implementing middleware for filesystem access and multi-agent orchestration. While the skill includes instructions for installing the Genkit CLI from a vendor-controlled domain, its primary security considerations involve the attack surface for indirect prompt injection created by agents that ingest external data while possessing capabilities such as file modification and command execution.

  • Socket2d

    No alerts

  • Snyk3d

    Risk: CRITICAL · 2 issues

  • Runlayer8mo

    2/11 files flagged

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 5 days ago
metadata
{
  "version": "1.0.0",
  "category": "AiAndMachineLearning"
}

README badge

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