Routing Workflow
Route incoming tasks to the most appropriate specialized agent.Overview
Copy
┌─────────────┐
│ Router │
└──────┬──────┘
┌───────────────┼───────────────┐
▼ ▼ ▼
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Technical │ │ Sales │ │ Support │
│ Agent │ │ Agent │ │ Agent │
└─────────────┘ └─────────────┘ └─────────────┘
Implementation
Copy
from praisonaiagents import Agent, Task, PraisonAIAgents
from praisonaiagents.agent import RouterAgent
# Create specialized agents
technical_agent = Agent(
name="Technical",
instructions="Handle technical questions about APIs and code."
)
sales_agent = Agent(
name="Sales",
instructions="Handle pricing and purchase inquiries."
)
support_agent = Agent(
name="Support",
instructions="Handle general support and troubleshooting."
)
# Create router
router = RouterAgent(
name="Router",
agents=[technical_agent, sales_agent, support_agent],
routing_instructions="""
Route to:
- Technical: API questions, code issues, integration help
- Sales: Pricing, plans, purchases, billing
- Support: General help, troubleshooting, account issues
"""
)
# Process a request
result = router.route("How do I integrate the API with Python?")
print(result) # Routed to Technical agent
Using Workflows Module
Copy
from praisonaiagents.workflows import RoutingWorkflow
workflow = RoutingWorkflow(
agents={
"technical": technical_agent,
"sales": sales_agent,
"support": support_agent
},
router_model="gpt-4o-mini"
)
result = workflow.run("What's the pricing for enterprise?")
# Automatically routed to sales_agent
Custom Routing Logic
Copy
from praisonaiagents import Agent
def custom_router(query: str) -> str:
"""Return agent name based on query content."""
query_lower = query.lower()
if any(word in query_lower for word in ["api", "code", "integrate"]):
return "technical"
elif any(word in query_lower for word in ["price", "cost", "buy"]):
return "sales"
else:
return "support"
# Use custom routing
agent_name = custom_router("How much does it cost?")
agents = {"technical": technical_agent, "sales": sales_agent, "support": support_agent}
result = agents[agent_name].start("How much does it cost?")
Related
- RouterAgent Module - Router agent reference
- Workflows Module - Workflows reference

