Agent Handoffs
Agent handoffs enable seamless task delegation between specialised agents, allowing you to build sophisticated multi-agent systems where each agent focuses on its area of expertise.Overview
Handoffs in PraisonAI allow agents to transfer control to other agents based on the conversation context. This pattern is particularly useful for:- Customer service routing
- Specialised task delegation
- Complex workflow orchestration
- Escalation scenarios
How Handoffs Work
When you specify handoffs for an agent, PraisonAI automatically:- Converts each handoff into a tool that the agent can use
- Adds instructions to the agent’s prompt about available handoffs
- Passes the full conversation history when transferring control
Basic Usage
Simple Handoff
Advanced Features
Custom Callbacks
Execute custom code when handoffs occur:Structured Input
Use Pydantic models to pass typed data during handoffs:Input Filters
Control what conversation history is passed to the target agent:Custom Tool Names
Override the default handoff tool name and description:Complete Example
Best Practices
- Clear Agent Responsibilities: Each agent should have a well-defined role and expertise area
- Minimal Context: Use filters to pass only relevant conversation history
- Structured Data: Use Pydantic models for complex handoff scenarios
- Monitoring: Implement callbacks to track handoff patterns
- Graceful Fallbacks: Always have a path for unhandled scenarios
Implementation Details
Under the hood, handoffs are converted to tools:Common Patterns
Customer Service Router
Escalation Chain
Skill-based Routing
Troubleshooting
Handoff Not Triggering
- Ensure the agent’s LLM supports tool calling
- Check that handoff agents are properly configured
- Verify the conversation context clearly indicates need for transfer
Context Loss
- Use input filters to preserve important context
- Consider using structured input models
- Implement callbacks to track what information is passed
Circular Handoffs
- Design clear handoff hierarchies
- Implement logic to prevent infinite loops
- Use callbacks to detect circular patterns