Multi-agent systems enable sophisticated workflows where specialized agents collaborate, transfer conversations, and handle different aspects of complex tasks.
Overview
The Multi-Agent primitive allows you to orchestrate multiple specialized agents within a single workflow or conversation. Instead of one generalist agent handling everything, you can deploy domain experts that collaborate, transfer work between each other, and provide specialized capabilities for different parts of your application. Multi-agent systems are essential for:- Specialized Expertise: Different agents with deep knowledge in specific domains
- Conversation Routing: Intelligent transfer between support, sales, technical agents
- Complex Workflows: Breaking down large tasks across multiple specialized agents
- Parallel Processing: Multiple agents working simultaneously on different subtasks
- Scalable Architecture: Add new agent specialists without modifying existing ones
Seamless Handoffs
Agents can transfer conversations to other specialists while maintaining full context
Domain Experts
Each agent can have specialized knowledge, tools, and behavioral patterns
Automatic Routing
Main agent intelligently determines which specialist should handle each request
Shared Context
All agents in a session share conversation history and can build on each other’s work
How Multi-Agent Works
When you configure multiple agents:- Main Agent: Acts as coordinator, receives initial requests
- Agent Discovery: Main agent knows about available specialists and their capabilities
- Intelligent Routing: Determines which specialist is best suited for the current task
- Transfer: Hands off conversation to specialist while preserving full context
- Specialist Handling: Specialist agent takes over and handles the request
- Return or Continue: Specialist can return control to main agent or continue handling
Context Preservation: When agents transfer conversations, the entire message history and context is preserved. The specialist agent has full visibility into everything that was discussed before.
Code Examples
Basic Multi-Agent Setup
Sales and Support Routing
Multi-Agent with Custom Tools
Continuing Multi-Agent Conversations
Use Cases
1. Customer Service Hub
Multi-tier support with specialized agents:2. Sales Pipeline
Route through sales stages with specialized agents:3. Content Production Workflow
Coordinate content creation across specialists:4. Development Team Simulation
Specialized development agents:5. Healthcare Triage System
Medical domain specialists:6. Financial Advisory Service
Financial domain specialists:Best Practices
Agent Design
Clear Specialization
Clear Specialization
Descriptive Names
Descriptive Names
Detailed Descriptions
Detailed Descriptions
Routing Strategy
Performance Optimization
Limit Agent Count
Use 3-5 specialized agents per workflow for optimal performance
Smart Routing
Design clear routing criteria to minimize unnecessary transfers
Session Reuse
Keep multi-agent sessions alive for related conversations
Tool Scoping
Give each agent access only to tools they need
Error Handling
Handle Ambiguous Requests
Handle Ambiguous Requests
Fallback Agents
Fallback Agents
Integration with Other Primitives
With Prompts
Each agent can have specialized system prompts:With Custom Tools
Different agents can access different tools:With Sessions
All agents in a session share context:With Parallelization
Run multiple agents in parallel:Performance Considerations
Agent Count Impact
- 2-3 Agents: Optimal performance, clear routing
- 4-6 Agents: Good performance, more specialization
- 7+ Agents: Consider if all are necessary, may slow routing decisions
Routing Efficiency
Clear routing reduces transfer overhead:Tool Access Optimization
Only provide tools relevant to each agent:Troubleshooting
Agent Not Transferring
Agent Not Transferring
Problem: Main agent not routing to specialistsSolutions:
- Make agent descriptions more specific
- Add explicit routing guidance in system prompt
- Ensure agent names clearly indicate their purpose
Wrong Agent Selected
Wrong Agent Selected
Problem: Requests routed to incorrect specialistSolutions:
- Improve agent descriptions to be more distinct
- Add routing examples in system prompt
- Use clear, non-overlapping specializations
Context Lost After Transfer
Context Lost After Transfer
Problem: Specialist doesn’t seem to have previous contextSolution: This shouldn’t happen - verify you’re using same session
Too Many Transfers
Too Many Transfers
Problem: Request bounces between multiple agentsSolutions:
- Design clear, non-overlapping specializations
- Give guidance on edge cases
- Use a generalist fallback agent
Related Primitives
Prompts
Specialized system prompts for each agent
Sessions
Shared context across all agents
Custom Tools
Domain-specific tools for specialists
Parallelization
Run multiple agents concurrently
Additional Resources
API Reference
Agents parameter documentation
Use Cases
Multi-agent implementation examples