Workflow Routing
Route workflows to different paths based on the output of a decision step. This pattern is also known as Agentic Routing or Conditional Branching.Quick Start
API Reference
route()
Parameters
| Parameter | Type | Description |
|---|---|---|
routes | Dict[str, List] | Dictionary mapping patterns to step lists |
default | Optional[List] | Steps to execute if no pattern matches |
How Matching Works
The router checks if any route key (case-insensitive) is contained in the previous step’s output:Examples
Multi-Step Routes
Each route can contain multiple steps:Chained Routing
Routes can be chained for complex decision trees:With Agents
Routes can include Agent instances:Use Cases
| Use Case | Description |
|---|---|
| Request Triage | Route support tickets to appropriate teams |
| Content Moderation | Route content based on classification |
| Approval Workflows | Different paths for approved/rejected items |
| A/B Testing | Route to different processing pipelines |
| Error Handling | Route based on success/failure status |
How It Works
| Phase | What happens |
|---|---|
| 1. Classify | A step (function or agent) returns a string label as its output |
| 2. Match | route() looks up the label in the routes dict; uses "default" if no key matches |
| 3. Execute | The matched handler list runs sequentially within the chosen branch |
| 4. Continue | Execution resumes with the next workflow step after the route block |
Best Practices
Always include a default route
Always include a default route
Handle unexpected classifier output gracefully instead of failing the workflow.
Use unambiguous route keys
Use unambiguous route keys
Short, distinct keys reduce mis-routing when LLM output is noisy.
Keep each route focused
Keep each route focused
One clear purpose per branch simplifies testing and observability.
Log routing decisions
Log routing decisions
Record which route was taken to debug triage and moderation pipelines.
Related
Workflow Patterns
Overview of routing, parallel, loop, and repeat
Workflow Parallel
Run independent steps concurrently
Workflow Loop
Iterate over lists and files
Workflow Repeat
Repeat until a condition is met

