Documentation
¶
Overview ¶
This sample demonstrates the agent APIs by defining six 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.
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.
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 and resume from the final state.
/back return to the agent list
/quit exit
Three 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); and barista, where ordering a drink and later asking "what have I ordered?" is answered from session state rather than from the transcript.