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
- Router Node Reached - The workflow detects
is_router=Trueon the currentNodeConfig - Route Evaluation - The workflow calls
BaseRouter.route(), which iterates through eachRouterNodeand callsdetermine_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
- Class Resolution - The selected node instance is converted back to its class and used as the next workflow node
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