Routing Workflow

Send requests to the right specialist agent

Classify each request and hand it to the specialist agent best suited to answer.

python
from praisonaiagents import Agent

router = Agent(name="Classifier", instructions="Route requests to billing, tech, or general support.")
router.start("My API key returns 401—who should handle this?")

The user defines routing rules, maps intents to agents, and returns the specialist response.

Diagram

Input

Agent

Output

Routing Workflow

Like a receptionist directing calls to the right department.

Diagram
graph TB
    Input([📝 User Request]) --> Classifier[🧠 Classifier]
    Classifier --> Router{🔀 route()}

    Router -->|"technical"| Tech[🔧 Tech Support]
    Router -->|"billing"| Billing[💳 Billing Team]
    Router -->|"general"| General[💬 General Help]

    Tech --> Output([✅ Response])
    Billing --> Output
    General --> Output

    classDef io fill:#8B0000,stroke:#7C90A0,color:#fff
    classDef classifier fill:#F59E0B,stroke:#7C90A0,color:#fff
    classDef router fill:#6366F1,stroke:#7C90A0,color:#fff
    classDef agent fill:#189AB4,stroke:#7C90A0,color:#fff

    class Input,Output io
    class Classifier classifier
    class Router router
    class Tech,Billing,General agent
    classDef agent fill:#8B0000,color:#fff
    classDef tool fill:#189AB4,color:#fff

How It Works

Diagram
TechAgentRouterClassifierUserTechAgentRouterClassifierUser“How do I integrate the API?”“technical”Route to tech support“Here’s how to integrate…”

Pattern Matching

Diagram

Previous Output: ‘priority: high’

✅ matches

❌ no match

‘high’

high route

‘low’

skipped

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


Code

python
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:

Diagram

approve

reject

🔀 route

✓ Validate

📧 Notify

💾 Save

📝 Log

📧 Notify User


Nested Routes

For complex decisions:

Diagram

A

B

A1

A2

Category?

Sub-type?

Handler B

Handler A1

Handler A2


Use Cases

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

Related