Genkit Dart 0.15.0
Agents
This release introduces Agents: a first-class way to build stateful, multi-turn AI experiences in Dart. Agents wrap generate with durable sessions, tool calling, human-in-the-loop interrupts, sub-agent delegation, and a transport-agnostic client — so you can go from a one-shot prompt to a full conversational agent (running locally or served over HTTP) with a few lines of code.
Defining an agent is one call. It handles the model, tools, and session state for you:
import 'package:genkit/genkit.dart';
import 'package:genkit/io.dart';
import 'package:genkit_google_genai/genkit_google_genai.dart';
final ai = Genkit(
plugins: [googleAI()],
model: googleAI.gemini('gemini-flash-latest'),
);
final getWeather = ai.defineTool(
name: 'getWeather',
description: 'Get the current weather for a given location.',
inputSchema: GetWeatherInput.$schema,
outputSchema: GetWeatherOutput.$schema,
fn: (input, _) async =>
GetWeatherOutput(weather: 'Sunny in ${input.location}', temperature: '71F'),
);
final weatherAgent = ai.defineAgent(
name: 'weatherAgent',
system: 'You are an assistant helping with weather information. '
'Use the getWeather tool.',
tools: [getWeather],
store: FileSessionStore('.sessions'), // durable, multi-turn state
);Talk to it - streaming, multi-turn, with state carried automatically between turns:
final chat = weatherAgent.chat(sessionId: 'user-123');
// Stream the first turn.
final turn = chat.sendStream(text: 'What is the weather like in Tokyo?');
await for (final chunk in turn.stream) {
stdout.write(chunk.text);
}
// Follow-up turn — prior context is threaded automatically.
final res = await chat.send(text: 'What about Paris?');
print(res.text);Serve it over HTTP with genkit_shelf, and any client (Dart, JS, browser) can
drive it:
router.post('/api/weatherAgent', shelfHandler(weatherAgent.action));// From a Dart CLI or Flutter/web app — no server-side deps required.
import 'package:genkit/client.dart';
final weather = remoteAgent(url: 'http://localhost:8080/api/weatherAgent');
final chat = weather.chat(sessionId: 'user-123');
await for (final chunk in chat.sendStream(text: 'Weather in Tokyo?').stream) {
stdout.write(chunk.text);
}What agents give you
- Durable sessions & snapshots - server- or client-managed state, with
pluggable stores:InMemorySessionStore,FileSessionStore
(package:genkit/io.dart), andFirestoreSessionStore(new
genkit_google_cloudpackage). Load any past turn from a snapshot, or fork a
conversation into a variant. - Streaming multi-turn chat -
send/sendStream, with session state
threaded automatically across turns. - Tools & human-in-the-loop interrupts - tools can pause for approval
(ctx.interrupt(...)) and be resumed/restarted with an approval payload, so
security-critical checks live inside the tool where the model can't bypass
them. - Typed custom state - define a
stateSchemaand mutate structured session
state from tools; each change streams a livecustomPatchchunk to the client. - Sub-agent delegation - the new
agents()middleware auto-injects
delegate_to_*tools, discovers sub-agent descriptions, and adds guard rails
(maxDelegations,historyLength) for orchestrator/worker patterns. - Prompt-file agents -
definePromptAgentwires a.prompt(dotprompt) file
into a multi-turn agent, customizable viapromptInput. - Custom & background agents -
defineCustomAgentfor multi-step flows with
live status, plusdetach+ status polling + abort for long-running
background work. - Transport-agnostic client -
remoteAgentfrompackage:genkit/client.dart
is browser-safe and wire-compatible with the Genkit client across SDKs
(verified by a cross-SDK conformance suite).
See the full runnable showcase in testapps/agents - 11 demo pages covering
chat, interrupts, artifacts, background/detach, branching, task state, research,
delegation, and coding agents.
Agents changelog
- feat(agents): agent & session schema types (1/8) by @pavelgj in #310
- feat(agents): session & snapshot storage + JSON Patch (2/8) by @pavelgj in #311
- feat(agents): dart:io FileSessionStore (3/8) by @pavelgj in #312
- feat(agents): transport-agnostic client core (4/8) by @pavelgj in #313
- feat(agents): server-side agent runtime (5/8) by @pavelgj in #314
- feat(agents): HTTP / remote agent client (6/8) by @pavelgj in #315
- test(agents): cross-SDK conformance suite (7/8) by @pavelgj in #316
- docs(agents): demo server + web UI (8/8) by @pavelgj in #317
- feat(google-cloud): add genkit_google_cloud with a FirestoreSessionStore by @pavelgj in #318
- feat(middleware): add agents sub-agent delegation middleware by @pavelgj in #324
- feat(genkit): type-safe agent State with schemantic parsing + agent API polish by @pavelgj in #330
- docs(testapps/agents): add reasoning display and file viewer to agents app by @pavelgj in #334
Other changes
Providers & models
- feat(genkit_firebase_ai): Support Vertex AI Gemini API by @goderbauer in #296
- feat(genkit_vertexai): support Gemini and multimodal embedders by @CorieW in #261
- feat(vertexai): curated known-model metadata + P0 Gemini 3.x registrations by @cabljac in #320
- refactor(google_genai,vertexai): model curated Gemini catalog as an enum by @cabljac in #323
- fix(genkit_openai): send non-image media as OpenAI file content parts by @irangarcia in #297
Core & prompts
- feat!: pass middleware context with GenkitAI to factories by @pavelgj in #319
- fix(core): forward init (and context) from reflection runAction to actions by @pavelgj in #321
- fix(prompt): carry resolved middleware refs on rendered options by @pavelgj in #325
- feat(prompt): surface middleware and generate options in prompt loader by @pavelgj in #333
Schemantic
- feat(schemantic): add serialize to convert typed values to JSON by @pavelgj in #332
- docs: add documentation to schemantic_builder entry point by @pavelgj in #294
Breaking changes
- feat!: pass middleware context with GenkitAI to factories (#319) - middleware factories now receive the middleware context via
GenkitAI.
New Contributors
- @goderbauer made their first contribution in #296
Full Changelog: genkit-v0.14.1...genkit-v0.15.0