from praisonaiagents import Agent, handoff
from pydantic import BaseModel
# Define context model
class CustomerInfo(BaseModel):
name: str
account_id: str
issue_description: str
# Create specialised agents
billing_agent = Agent(
name="BillingExpert",
role="Billing specialist",
goal="Resolve billing issues",
backstory="10 years experience in billing",
tools=[check_balance, process_payment]
)
technical_agent = Agent(
name="TechSupport",
role="Technical support",
goal="Solve technical problems",
backstory="Expert in troubleshooting",
tools=[check_logs, restart_service]
)
manager_agent = Agent(
name="Manager",
role="Customer service manager",
goal="Handle escalations",
backstory="Experienced in conflict resolution"
)
# Configure handoffs with advanced features
handoffs = [
# Simple handoff
billing_agent,
# Handoff with callback
handoff(
agent=technical_agent,
on_handoff=lambda f, t, c: log_transfer(f.name, t.name)
),
# Handoff with structured input and filters
handoff(
agent=manager_agent,
name="escalate_to_management",
description="Escalate serious issues to management",
input_model=CustomerInfo,
filter={"keep_last_n_messages": 3}
)
]
# Create main agent with handoffs
support_agent = Agent(
name="Support",
role="Customer support",
goal="Help customers with their issues",
backstory="First point of contact",
handoffs=handoffs
)
# Use in conversation
result = support_agent.chat("My payment failed and now I can't access my account")