The handoff system enables seamless task delegation between specialized agents, allowing complex workflows where each agent contributes their expertise.
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.
# Technical support specialisttech_support = Agent( name="TechnicalSupport", instructions="You are a technical support specialist. Resolve technical issues.")# Billing specialistbilling = Agent( name="Billing", instructions="You are a billing specialist. Handle payment and subscription issues.")
4
Create main agent with handoff capabilities
# Customer service agent that can handoff to specialistscustomer_service = Agent( name="CustomerService", instructions="You are a customer service agent. For technical issues, handoff to TechnicalSupport.", handoffs=[tech_support, billing] # Pass agent instances)
5
Use handoffs naturally in conversation
# Customer service agent automatically hands off when neededresponse = customer_service.chat("I'm having trouble installing the software")# This will trigger a handoff to TechnicalSupport
from praisonaiagents.agent.handoff import handoff_filters# Default filters available: ["all", "none", "self", "other", "team:"]agent = Agent( name="TeamLead", handoff_filter="team:support", # Only handoff to support team handoffs=["Agent1", "Agent2", "Agent3"])# Filter examples:# "all" - Can receive from any agent (default)# "none" - Cannot receive handoffs# "self" - Can only receive from itself# "other" - Can receive from any agent except itself# "team:xyz" - Can only receive from agents in team 'xyz'
from praisonaiagents import Agent, handoff# Create handoff with custom nametransfer_to_human = handoff( name="transfer_to_human", description="Transfer the conversation to a human agent when the user requests it")chatbot = Agent( name="Chatbot", instructions="You are an AI assistant. Transfer to human when requested.", tools=[transfer_to_human])
from praisonaiagents import Agentfrom praisonaiagents.agent.handoff import handoff, handoff_filtersfrom pydantic import BaseModel# Specialist agentsorder_agent = Agent( name="Order Management", instructions="You help with order status and tracking.", tools=[check_order_status, track_shipment])refund_agent = Agent( name="Refund Specialist", instructions="You process refunds and handle return requests.", tools=[process_refund, check_refund_policy])technical_agent = Agent( name="Technical Support", instructions="You solve technical issues and provide guidance.", tools=[diagnose_issue, create_ticket])# Escalation with structured inputclass EscalationRequest(BaseModel): issue_type: str severity: str description: strescalation_agent = Agent( name="Senior Manager", instructions="You handle escalated issues requiring management attention.")# Main triage agenttriage_agent = Agent( name="Customer Service", instructions="""You are the first point of contact. Route customers to the right specialist: - Order issues → Order Management - Refunds → Refund Specialist - Technical problems → Technical Support - Complex issues → Escalate to management """, handoffs=[ order_agent, refund_agent, technical_agent, handoff( escalation_agent, tool_name_override="escalate_to_management", input_type=EscalationRequest, on_handoff=lambda src, data: log_escalation(src.name, data) ) ])# Start the serviceresponse = triage_agent.chat("I need a refund for order #12345")
# Multi-department organizationreception = Agent( name="Reception", role="Virtual Receptionist", handoffs=["Sales", "Support", "HR", "Finance", "Legal"])# Each department can hand back to reception or to other departmentssales = Agent( name="Sales", role="Sales Department", handoffs=["Reception", "Finance", "Support"])
# Multilingual support systemlanguage_detector = Agent( name="LanguageRouter", role="Language Detection and Routing", instructions="Detect user language and route to appropriate agent.", handoffs=["EnglishSupport", "SpanishSupport", "FrenchSupport"])