Skip to main content

Routing Workflow

Like a receptionist directing calls to the right department.

How It Works


Pattern Matching

The router looks for keywords in the previous step’s output.

Code

from praisonaiagents import Agent, AgentFlow
from praisonaiagents import route

# Classifier decides where to route
def classify(ctx):
    text = ctx.input.lower()
    if "api" in text or "code" in text:
        return StepResult(output="technical")
    elif "price" in text or "bill" in text:
        return StepResult(output="billing")
    return StepResult(output="general")

# Specialist agents
tech = Agent(name="Tech", instructions="Handle technical questions")
billing = Agent(name="Billing", instructions="Handle billing questions")
general = Agent(name="General", instructions="Handle general questions")

# Create routing workflow
flow = AgentFlow(steps=[
    classify,
    route({
        "technical": [tech],
        "billing": [billing],
        "general": [general],
        "default": [general]
    })
])

result = flow.start("How do I integrate the API?")

Multi-Step Routes

Each route can have multiple agents:

Nested Routes

For complex decisions:

Use Cases

ScenarioRoutes
Customer supportTechnical, Billing, General
Content moderationSafe, Review, Block
Approval workflowApprove, Reject, Escalate
Language routingEnglish, Spanish, French