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-background.md

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

Background Agents / Detaching

Detaching requires a session store — the server needs somewhere to write the result when background work finishes. Read agents.md first.

Detaching runs a turn in the background: the server saves a pending snapshot and returns a snapshotId immediately, keeps processing, then updates the snapshot to a terminal status (completed / failed / aborted / expired). The client polls for completion and can abort.


Define the agent (store required)

import 'package:genkit/genkit.dart';
import 'package:genkit/experimental.dart'; // defineAgent, InMemorySessionStore

import 'genkit.dart';

final backgroundAgent = ai.defineAgent(
  name: 'backgroundAgent',
  system: 'You are a senior research analyst. Produce a comprehensive '
      'markdown report.',
  use: [retry()],
  store: InMemorySessionStore(), // REQUIRED for detach
);

Expose its companion actions so the client can poll/abort (see agents.md):

import 'package:genkit/experimental_io.dart';
import 'package:genkit/io.dart';

// The store makes addAgent mount /getSnapshot and /abort next to the turn route.
final genkit = GenkitRouter()
  ..addAgent(backgroundAgent, path: '/api/backgroundAgent');

Client-side: detach, poll, and abort

On the client (package:genkit/client.dart), chat.detach(text: ...) (or chat.detach(...)) resolves immediately with a DetachedTask carrying the snapshotId. task.poll(...) yields AgentSnapshots until a terminal status; task.abort() cancels the background work. Each AgentSnapshot surfaces .status, .messages, .artifacts, and typed .custom state directly.

import 'package:genkit/client.dart';
import 'package:genkit/experimental_client.dart'; // remoteAgent, DetachedTask

final agent = remoteAgent(url: '/api/backgroundAgent');

// Submit - resolves immediately with a handle.
final task = await agent.chat().detach(text: 'Quantum computing impact');
print(task.snapshotId);

// Poll until a terminal status.
await for (final snap in task.poll(interval: Duration(milliseconds: 1500))) {
  final status = snap.status?.value ?? 'pending';
  if (status == 'completed') {
    final messages = snap.messages;
    final lastModel =
        messages.where((m) => m.role == Role.model).lastOrNull;
    final text =
        (lastModel?.content ?? []).map((p) => p.text ?? '').join();
    print(text);
    break;
  } else if (status == 'failed') {
    throw Exception('Background task failed on the server.');
  } else if (status == 'aborted' || status == 'expired') {
    break;
  }
  // 'pending' → keep polling
}

// Abort an in-flight task at any time:
await task.abort();

Server-side: detach and wait

You can also detach from a server-side chat and wait for the result. task.wait polls the store until a terminal state and resolves with the final snapshot.

final chat = backgroundAgent.chat();
final task = await chat.detach(text: 'Write a report on renewable energy trends');
print(task.snapshotId); // available immediately

final snapshot = await task.wait(interval: Duration(seconds: 2));
print(snapshot?.status?.value); // 'completed' | 'failed' | 'aborted' | 'expired'

Status values

  • pending — still processing.
  • completed — completed successfully (read the result from snapshot.messages).
  • failed — error during processing.
  • aborted — cancelled by the client via abort().
  • expired — the background worker stopped responding (e.g. server restart); terminal, the task can never complete.

Equivalent low-level wire protocol: the client sends { detach: true } with the message; poll/wait hit the agent's getSnapshot action, and abort hits the abort action. remoteAgent wraps all of this for you.

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