Multi-Agent Handoffs
Multi-Agent Handoffs enable complex agentic architectures by allowing an active agent to dynamically delegate control to specialized sub-agents.
Why Use Multi-Agent Handoffs?
Single monolithic agents with dozens of tools and long system prompts suffer from prompt distraction, tool hallucination, and high token costs.
By breaking workflows into specialized sub-agents:
- Triage Router: Identifies user intent and routes to specialists.
- Billing Specialist: Has billing tools and refund policies.
- Tech Support Specialist: Has log analysis tools and technical diagnostics.
Handoffs keep system prompts lightweight and ensure tools are scoped strictly to the active specialist.
How Handoffs Work Under the Hood
createHandoff(targetAgent)generates a special handoff tool namedtransfer_to_<agent_name>.- When the active agent calls this handoff tool,
Runnerintercepts the execution loop. Runnerupdates the active agent totargetAgent, appends a handoff transition message to conversation history, and invokes the new specialist agent seamlessly.
Complete Multi-Agent Workflow Example
typescript
Inspecting Handoff Traces
The RunResult object returned by runner.run() contains full transparency into agent transfers:
typescript
Best Practices
- Clear Specialist Descriptions: Provide clear persona guidelines so the triage router knows exactly when to initiate a handoff.
- Bi-Directional Handoffs: Allow specialist agents to hand off back to the
Triage Routeror to other specialists if the conversation topic shifts. - Preserve Memory State: Handoffs share the same
RunContextandSessionmemory, ensuring context is never lost during transfers.