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.

referencesgenkit_middleware.md

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

Genkit Middleware (genkit_middleware)

A collection of useful middleware for Genkit Dart to enhance your agent's capabilities. Register plugins when initializing Genkit:

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

void main() {
  final ai = Genkit(
    plugins: [
      FilesystemPlugin(),
      SkillsPlugin(),
      ToolApprovalPlugin(),
    ],
  );
}

Filesystem Middleware

Allows the agent to list, read, write, and search/replace files within a restricted root directory.

final response = await ai.generate(
  prompt: 'Check the logs in the current directory.',
  use: [
    filesystem(rootDirectory: '/path/to/secure/workspace'),
  ],
);

Tools Provided:

  • list_files, read_file, write_file, search_and_replace

Skills Middleware

Injects specialized instructions (skills) into the system prompt from SKILL.md files located in specified directories.

final response = await ai.generate(
  prompt: 'Help me debug this issue.',
  use: [
    skills(skillPaths: ['/path/to/skills']),
  ],
);

Tools Provided:

  • use_skill: Retrieve the full content of a skill by name.

Tool Approval Middleware

Intercepts tool execution for specified tools and requires explicit approval. Returns FinishReason.interrupted.

A tool is allowed through only if it is in the approved list or its request's resumed payload carries { 'tool-approved': true }. To approve on resume, re-issue the paused ToolRequestPart with .restart({'tool-approved': true}) — the builder nests the payload under metadata.resumed, exactly what the middleware reads.

final response = await ai.generate(
  prompt: 'Delete the database.',
  use: [
    // Require approval for all tools EXCEPT those below
    toolApproval(approved: ['read_file', 'list_files']),
  ],
);

if (response.finishReason == FinishReason.interrupted) {
  // `response.interrupts` is a List<ToolRequestPart>.
  final interrupt = response.interrupts.first;

  // Ask user for approval
  final isApproved = await askUser();

  if (isApproved) {
    final resumeResponse = await ai.generate(
      messages: response.messages, // Pass history
      toolChoice: ToolChoice.none, // Prevent immediate re-call
      interruptRestart: [
        // `.restart(...)` nests the payload under `metadata.resumed`.
        interrupt.restart({'tool-approved': true}),
      ],
    );
  }
}

Agent-side resume. When resuming an agent chat rather than a raw ai.generate call, the interrupts are AgentInterrupts; pass the same .restart(...) builder directly to chat.resume: chat.resume(restart: [interrupt.restart({'tool-approved': true})]). See human-in-the-loop.

Custom Middleware (core package:genkit)

Extend GenerateMiddleware and override the hooks you need (generate, model, tool). Register it with ai.defineGenerateMiddleware and call the returned definition to build the ref for use:. create runs once per generate call; ctx.ai is a GenkitAI the middleware can use for its own calls (classifiers, guardrails).

class LoggingMiddleware extends GenerateMiddleware {
  @override
  Future<ModelResponse> model(
    ModelRequest request,
    ActionFnArg<ModelResponseChunk, ModelRequest, void> ctx,
    Future<ModelResponse> Function(
      ModelRequest request,
      ActionFnArg<ModelResponseChunk, ModelRequest, void> ctx,
    ) next,
  ) async {
    print('Calling the model with ${request.messages.length} messages');
    return next(request, ctx);
  }
}

final logging = ai.defineGenerateMiddleware<void>(
  name: 'logging',
  create: (config, ctx) => LoggingMiddleware(),
);

await ai.generate(prompt: 'Hello', use: [logging(), retry(maxRetries: 2)]);

For typed config, pass configSchema: MyOptions.$schema (a schemantic type) and call logging(MyOptions(...)).

To ship middleware in a plugin, build the definition with the top-level generateMiddleware (it does not register anything) and return it from GenkitPlugin.middleware(). The definition is callable, so a named-parameter helper is a one-liner:

final loggerDef = generateMiddleware<LoggerOptions>(
  name: 'logger',
  configSchema: LoggerOptions.$schema,
  create: (config, ctx) => LoggerMiddleware(verbose: config?.verbose ?? false),
);

class LoggerPlugin extends GenkitPlugin {
  @override
  String get name => 'logger';

  @override
  List<GenerateMiddlewareDef> middleware() => [loggerDef];
}

GenerateMiddlewareRef<LoggerOptions> logger({bool? verbose}) =>
    loggerDef(LoggerOptions(verbose: verbose));

There is no defineMiddleware. Prefer calling the definition over middlewareRef(name: ...), which is only needed to reference middleware by name without its definition.

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