basic-agents

command
v1.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 26, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

This sample demonstrates Genkit's agent APIs by defining five agents in different styles and exposing all of them through a single CLI. Each agent lives in its own file so the styles can be compared side by side:

  • "pirate" (pirate.go) uses DefineAgent + aix.InlinePrompt. The prompt is declared inline next to the agent.
  • "chef" (chef.go) uses DefinePromptAgent. With no source option it defaults to the prompt registered under the agent's name, loaded from ./prompts/chef.prompt.
  • "coder" (coder.go) uses DefineCustomAgent. The per-turn loop (model selection, history management, streaming) is wired by hand.
  • "banker" (banker.go) uses DefinePromptAgent (prompt loaded from ./prompts/banker.prompt) with an interruptible tool. It pauses mid-turn to ask the user for approval before moving money, then resumes the tool with their answer. This exercises the tool interrupt / resume flow through the same CLI.
  • "orchestrator" (orchestrator.go) uses the experimental Agents middleware to delegate to specialized sub-agents (researcher, engineer) through per-agent tools, merging their artifacts into its own session.

The interactive CLI lives in cli.go: it lists the agents, streams each turn, renders tool calls inline as the agent makes them, and routes tool interrupts to the right handler.

The first four agents persist their conversation state to a per-agent FileSessionStore under ./.genkit/snapshots/<agent>/; the orchestrator does too, while its sub-agents run statelessly per delegation.

To run:

go run .

The CLI prints a numbered list of agents. Pick one, choose to resume from the last snapshot or start fresh, and chat. Inside a chat:

(text)             send a message and stream the reply
/detach (text...)  send the text (optional) as the final input, then
                   detach. The server keeps processing in the
                   background; you get a pending snapshot ID and
                   return to the agent list. Re-pick the agent later
                   to wait for the snapshot to finalize and resume
                   from the cumulative final state.
/back              return to the agent list (snapshot is still
                   written by the agent's normal turn-end hook)
/quit              exit the program

Tip: try "/detach write me a long pirate story" to see the detach loop end-to-end. After the CLI returns to the agent list, pick "pirate" again; if the snapshot is still pending, you'll get a three-way menu (wait, start new, back). Picking wait blocks on the in-process status subscription and resumes from the cumulative final state.

Tip: pick "banker" and try "send $200 to alice" (more than the $150 balance) or "send $120 to bob" (a large transfer) to see the tool interrupt flow: the turn pauses, the CLI asks you to approve or adjust, and the tool resumes with your answer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL