Skip to main content
This node enables dynamic routing by selecting the next node based on routing rules. Each rule is a 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

  1. Router Node Reached - The workflow detects is_router=True on the current NodeConfig
  2. Route Evaluation - The workflow calls BaseRouter.route(), which iterates through each RouterNode and calls determine_next_node()
  3. First Match Wins - The first router rule that returns a node determines the next step
  4. Fallback Handling - If no rules match, the router uses the fallback node
  5. 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

Configuration in WorkflowSchema