Routing
When to Use Routing
Pattern
Example
Why DAGs Fail
Binary Branching with @ifelse
Basic If/Else
Early Termination with END
When to Use @ifelse vs @route
Use @ifelse when...
Use @route when...
Flexible Routing with @route
Route to One of Several Targets
Terminate Early with END
Real-World Example: RAG with Diagram Detection
Agentic Loops
Multi-Turn RAG with Refinement
Quality Gate with Retry
Multi-Target Routing
Fallback Targets
Validation and Error Handling
Build-Time Validation
Invalid Return Values at Runtime
Type Safety
Patterns and Best Practices
Keep Routing Functions Simple
Use Descriptive Targets
Chained Gates
Next Steps
Last updated