Skip to main content

Agent Handoff System

The handoff system enables seamless task delegation between specialized agents, allowing complex workflows where each agent contributes their expertise.

Overview

When an agent encounters a task outside its expertise, it can dynamically hand off the conversation to a more suitable agent, ensuring optimal task completion.

Quick Start

1
Install praisonaiagents
2
Import required components
3
Create specialist agents
4
Create main agent with handoff capabilities
5
Use handoffs naturally in conversation

How Handoffs Work

1. Handoff Detection

Agents identify when they need to delegate based on:
  • Task complexity beyond their expertise
  • Specific keywords or patterns in user requests
  • Explicit handoff instructions in their role

2. Target Selection

The system selects the best agent using:
  • Predefined handoff targets in agent configuration
  • Dynamic selection based on agent capabilities
  • Custom selection logic via callbacks

3. Context Transfer

When handing off, the system:
  • Packages the entire conversation history
  • Includes any relevant metadata
  • Maintains user context and preferences

4. Seamless Continuation

The receiving agent:
  • Gets full context of the conversation
  • Continues naturally without user intervention
  • Can hand back or to another agent if needed

Basic Usage

Handoff Configuration

Parameters

Handoff Filters

Control what conversation data is passed during handoff:

Agent-Level Filters

Advanced Usage

Custom Handoff Names

Handoff Callbacks

Structured Input with Pydantic

Complete Example

Common Use Cases

Customer Support System

Multi-Department Routing

Language-Based Routing

Best Practices

Clear Handoff Criteria

Define explicit criteria for when agents should handoff:
  • Specific keywords or phrases
  • Task complexity thresholds
  • User requests for specialists
  • Error or uncertainty conditions

Context Preservation

Ensure important context is maintained:
  • Include conversation summary in handoffs
  • Pass relevant user preferences
  • Maintain task state and progress
  • Include any gathered information

Prevent Loops

Avoid infinite handoff loops:
  • Implement handoff history tracking
  • Set maximum handoff limits
  • Use handoff filters appropriately
  • Design clear agent responsibilities

User Experience

Make handoffs seamless for users:
  • Inform users about handoffs when appropriate
  • Maintain conversation continuity
  • Preserve user context and preferences
  • Minimize repetition of information

Troubleshooting

API Reference

See the Handoff API documentation for detailed information about:
  • The Handoff class
  • The handoff() function
  • HandoffInputData structure
  • Built-in handoff filters
  • Callback signatures

Next Steps

Build complex multi-agent workflows

Add persistent memory to your agents