RouterNode
. If no rule matches, the router uses a fallback node.
Router components:
- BaseRouter - Orchestrates routing decisions and manages the routing process
- RouterNode - Individual routing rules implementing conditional logic
Router Classes
BaseRouter
RouterNode
How routing works
- Process Method Called - The BaseRouter’s
process()
method runs during workflow execution - Route Evaluation - The router iterates through each
RouterNode
, callingdetermine_next_node()
- First Match Wins - The first router rule that returns a node determines the next step
- Fallback Handling - If no rules match, the router uses the fallback node
- Result Storage - The selected next node is stored in the task context
Implementation example
Main Router
Router rule examples
Best practices
- Order Matters - Arrange router nodes in order of priority; first match wins
- Clear Conditions - Keep routing conditions explicit and easy to reason about
- Fallback Strategy - Provide a meaningful fallback node
- Test Coverage - Test all routing paths