Why Multiple Agents?
| Approach | Pros | Cons |
|---|---|---|
| Single agent | Simple, less latency | Prompt becomes too complex |
| Multiple agents | Focused prompts, easier to maintain | More coordination needed |
- Different tasks require different prompts or tools
- You need to route users to specialists
- Workflows have distinct phases
The Router Pattern
A lightweight router node analyzes intent and directs traffic:Implementation
Setting Up the Graph
The Handoff Pattern
An agent explicitly transfers control when it reaches its limits:Implementation
Shared Context
When handing off, pass relevant context:LLM-Based Routing
For complex routing, use an LLM:Fallback Agents
Add a fallback for unhandled cases:Monitoring Handoffs
Log handoffs for debugging:Tips
Start with keyword routing
Start with keyword routing
Simple keyword matching covers most cases. Add LLM routing only if needed.
Pass context on handoff
Pass context on handoff
Include what the previous agent learned so users don’t repeat themselves.
Always have a fallback
Always have a fallback
Route to a general agent if no specialist matches. Never leave users hanging.

