Skip to main content
Main agent delegates to a MathSpecialist sub-agent on its own task queue. Tool and delegation approval events from the specialist fan in to the main agent’s stream. Source: examples/agent_with_subagents/

What it demonstrates

  • WithSubAgents registering a specialist with its own tools and task queue
  • Delegation approval (CUSTOM delegation events) and tool approval from sub-agent streams
  • Separate Temporal task queues per agent when AGENT_RUNTIME=temporal

Run

From examples/:
go run ./agent_with_subagents "Use the math specialist to compute 847 * 293"
Approve delegation and tool calls when prompted on stdin.

Key code

mathAgent, err := agent.NewAgent(
    agent.WithName("MathSpecialist"),
    agent.WithTaskQueue(mathQueue),
    agent.WithToolRegistry(mathReg),
    agent.WithLLMClient(llmClient),
)

mainAgent, err := agent.NewAgent(
    agent.WithName("MainAgent"),
    agent.WithTaskQueue(mainQueue),
    agent.WithSubAgents(map[string]agent.SubAgentConfig{
        "math": {Agent: mathAgent, Description: "Handles arithmetic"},
    }),
    agent.WithLLMClient(llmClient),
)
Each sub-agent needs its own worker polling its task queue in Temporal mode. See Sub-agents.

Expected output

Delegating to MathSpecialist...
Approve delegation to MathSpecialist? [y/n]: y
Tool call: calculator({"expression":"847*293"})
Approve? [y/n]: y
847 × 293 = 248,171
The main agent emits a delegation approval event before calling the sub-agent. The sub-agent then calls its tools and approval events fan in to the main agent’s stream.

Learn more

Sub-agents

Depth limits, policies, streaming fan-in

Approvals

Delegation and tool approval

Multiple Agents

Multiple root agents in one process