Documentation
¶
Overview ¶
This sample demonstrates the agent APIs by defining seven agents in different styles, one per file, behind a single CLI:
- pirate (pirate.go): DefineAgent with the prompt declared inline.
- chef (chef.go): DefinePromptAgent, which defaults to the prompt registered under the agent's name, ./prompts/chef.prompt.
- coder (coder.go): DefineCustomAgent, with the per-turn loop wired by hand.
- banker (banker.go): a prompt agent with an interruptible tool, so a turn pauses for approval before moving money and resumes with the answer.
- barista (barista.go): an Agent[BaristaOrder] whose system instruction is a function. A tool writes the order into session state and the prompt reads it back, so each turn knows what earlier ones established.
- orchestrator (orchestrator.go): delegates to sub-agents through per-agent tools, merging their artifacts into its own session.
- commander (commander.go): the same middleware with Async set, so an incident commander starts its investigators in the background, keeps posting status updates while they work, and collects the results after.
cli.go holds the CLI: it lists the agents, streams each turn, renders tool calls as they happen, and routes interrupts. Conversation state persists to a per-agent FileSessionStore under ./.genkit/snapshots/<agent>/, except for the orchestrator's sub-agents, which run statelessly per delegation. The commander's investigators do keep stores, which is what lets them run in the background.
Run it:
go run .
Or with the Dev UI, which keeps the CLI on the terminal and adds a trace of every turn at http://localhost:4000/traces:
curl -sL cli.genkit.dev | bash # install the Genkit CLI, once genkit start -- go run .
Pick an agent, resume from its last snapshot or start fresh, then chat. Inside a chat:
(text) send a message and stream the reply
/detach (text...) send the text, then leave it running in the background
and return to the agent list. Re-pick the agent to wait
for the snapshot, or to stop it and resume from the
turns it finished.
/back return to the agent list
/quit exit
Four worth trying: "/detach write me a long pirate story", then re-pick pirate to wait on it; banker with "send $200 to alice" (over the $150 balance) or "send $120 to bob" (large enough to need approval); barista, where ordering a drink and later asking "what have I ordered?" is answered from session state rather than from the transcript; and commander with "checkout-api is throwing 500s and customers can't pay", which posts its first status update while its investigators are still running.