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.

referencesagents-deployment.md

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

Deploying / Serving Agents over HTTP

Uses GenkitRouter (package:genkit/io.dart) with addAgent (package:genkit/experimental_io.dart). Read agents.md first. For general HTTP serving (standalone, shelf, auth), see genkit_shelf.md.

addAgent(agent) mounts the agent's routes, defaulting to /<agent name>:

  • POST <path>: runs a turn (streams with ?stream=true). Always.
  • POST <path>/getSnapshot: reads a snapshot. Only for server-managed agents (defined with a store). Needed for snapshot restore and background polling.
  • POST <path>/abort: cancels a background turn. Only when the store can signal the running turn.

So a client-managed (stateless) agent gets only its turn route. These paths match the remoteAgent client defaults (${url}/getSnapshot, ${url}/abort), so a client only needs the base url. hideGetSnapshot: true / hideAbort: true remove supported routes; they can't force unsupported ones.


Serving several agents (shelf)

import 'dart:io';

import 'package:genkit/experimental_io.dart'; // addAgent
import 'package:genkit/io.dart'; // GenkitRouter, CorsOptions
import 'package:genkit_shelf/genkit_shelf.dart'; // asShelfHandler
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as io;
import 'package:shelf_router/shelf_router.dart';

import 'package:agents_sample/background_agent.dart';
import 'package:agents_sample/weather_agent.dart';
import 'package:agents_sample/weather_agent_stateless.dart';

void main() async {
  final api = GenkitRouter()
    ..addAgent(weatherAgent) // turn + /getSnapshot (+ /abort if supported)
    ..addAgent(backgroundAgent)
    ..addAgent(weatherAgentStateless) // turn only
    // Plain flows used by the UI, on custom paths:
    ..addAction(listWorkspaceFiles, path: '/workspace/files');

  final router = Router()
    // `mount` strips the prefix: agents are at /api/<agentName>.
    ..mount(
      '/api/',
      api.asShelfHandler(
        // Browser clients on another origin (Jaspr/Flutter web dev server).
        cors: const CorsOptions(
          allowedHeaders: ['Content-Type', 'Accept', 'X-Genkit-Stream-Id'],
        ),
      ),
    );

  final port = int.tryParse(Platform.environment['PORT'] ?? '') ?? 8080;
  final server = await io.serve(
    const Pipeline().addMiddleware(logRequests()).addHandler(router.call),
    InternetAddress.anyIPv4,
    port,
  );
  print('Agents API server running on http://localhost:${server.port}');
}

Without shelf, skip the Router and call api.serve(cors: const CorsOptions(...)); pass path: '/api/weatherAgent' to addAgent to keep the /api prefix.

Auth

addAgent(agent, contextProvider: bearerAuth) applies the provider to every route of that agent, so reading or aborting a snapshot is authorized like a turn. See genkit_shelf.md.

CORS for browser clients

Pass CorsOptions to serve() / asShelfHandler() (no shelf_cors_headers). Browser streaming clients send X-Genkit-Stream-Id, which is not in the default allowedHeaders, so list it explicitly as above.

Registering agents/flows

Agents register with Genkit when their defining top-level final is evaluated. Importing the module (e.g. in your server's bin/server.dart) and referencing the agent, as addAgent(...) does, ensures the defineAgent call runs. Agents referenced only by name (e.g. sub-agents for agents(...) middleware) must be touched explicitly before use.

Notes

  • The wire body matches the Genkit client: { "data": <input>, "init": <init> }.
  • For persistence across restarts, use FileSessionStore (package:genkit/experimental_io.dart) or FirestoreSessionStore (package:genkit_google_cloud) instead of InMemorySessionStore. See sessions.
  • Consuming these endpoints from Dart/Flutter/web uses remoteAgent from package:genkit/experimental_client.dart (alongside package:genkit/client.dart) — see agents.md.

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