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

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

Agent Branching

Requires a session store so snapshots are persistent. Read agents.md first.

A snapshotId is an immutable checkpoint, like a git commit. You can fork as many independent timelines as you want from the same snapshot — each turn from a snapshot creates a new, independent snapshot; the original is unchanged.

To branch, open a new chat attached to an earlier snapshot via agent.chat(snapshotId: ...).


Server-side branching

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

import 'genkit.dart';

final assistant = ai.defineAgent(
  name: 'assistant',
  system: 'You are a helpful assistant.',
  store: InMemorySessionStore(),
);

final root = assistant.chat();
final res1 = await root.send(text: 'Hello!');
final checkpoint = res1.snapshotId; // branch point

// Branch A - forks from `checkpoint`.
final branchA = assistant.chat(snapshotId: checkpoint);
await branchA.send(text: 'My name is Bob.');
final resA = await branchA.send(text: 'What is my name?'); // -> Bob

// Branch B - forks from the SAME `checkpoint`, fully independent.
final branchB = assistant.chat(snapshotId: checkpoint);
await branchB.send(text: 'My name is John.');
final resB = await branchB.send(text: 'What is my name?'); // -> John

Client-side branching ("pick a variant")

A common pattern: generate two variants from the same checkpoint in parallel, let the user pick one, and continue from the chosen snapshot.

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

final agent = remoteAgent(url: '/api/branchingAgent');
String? snapshotId; // current branch point

Future<(AgentResponse, AgentResponse)> twoVariants(String text) async {
  // Each variant gets its own chat branching from the same snapshot
  // (or a fresh session when there's no branch point yet).
  AgentChat makeChat() =>
      snapshotId != null ? agent.chat(snapshotId: snapshotId) : agent.chat();

  final results = await Future.wait([
    makeChat().send(text: text),
    makeChat().send(text: text),
  ]);
  // results[0].snapshotId != results[1].snapshotId - both branch from the
  // same point.
  return (results[0], results[1]);
}

// When the user picks a variant, its snapshotId becomes the new branch point:
void pick(String chosenSnapshotId) {
  snapshotId = chosenSnapshotId;
}

Restoring history from a snapshot

Use agent.getSnapshot(snapshotId: ...) to read a snapshot's state without starting a turn — handy for restoring a UI after a reload (e.g. a snapshotId stored in the URL). The server must expose the agent's getSnapshotDataAction (see agents.md).

getSnapshot(...) returns an AgentSnapshot<State> — a typed veneer that surfaces .messages, .artifacts, and typed .custom state directly (use .sessionState for the raw SessionState if you need it).

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

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

final snapshot = await agent.getSnapshot(snapshotId: snapshotId);
final history = (snapshot?.messages ?? [])
    .where((m) => m.role == Role.user || m.role == Role.model)
    .map((m) => (
          role: m.role.value,
          text: m.content.map((p) => p.text ?? '').join(),
        ))
    .toList();

Abandoned branches simply remain in the store as immutable snapshots; nothing is overwritten when you branch.

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