Skip to main content
You now have a support workflow — but today it behaves like a straight line: every incoming message runs through the exact same sequence of nodes and an answer comes out the other side. That design treats all messages identically. Monday arrives and different customers send different problems:
  • “Why was I charged twice this month?”
  • “The app crashes every time I hit Save.”
  • “Where do I find my past orders?”
These are distinct issues, yet the current pipeline sends them down a single path: billing checks receive crash reports, technical steps look for duplicate charges, and the general handler sits idle. To route different messages to the right handler, you need a router node. A router is a node that inspects input and selects a branch. It behaves like a function node — it runs code — but instead of returning data for the next node to process, it returns a route label: a short string that tells the runtime which branch to take. Key points:
  • Router returns an Event (or similar) with a route field set to a route label (string).
  • The workflow must declare a route map that maps route labels to target nodes.
  • Always include a fallback route (for example, "GENERAL") so unknown inputs still get processed.
Always provide a fallback route so the workflow can handle unexpected or unknown inputs without failing.

Example router function (Python)

This simple router looks for keywords and returns matching route labels:
Notes:
  • The router returns an Event whose route field is a string label.
  • Route labels are compared exactly (case-sensitive) against the route map keys — be consistent in casing.

Mapping routes to nodes

A sequential edge is simply a list of nodes to run in order. A routing edge contains the router node and a dictionary that maps route labels to destination nodes. You declare all branches up front in the workflow’s edges so the runtime knows every allowed path before messages arrive. Example workflow definition with a route map:
Table: route map example Remember: the dictionary keys (route labels) must match the string returned by the router exactly.

Visualization: how the graph changes

Think of the graph transforming from a single line into a fork: start → process_message → Router → { BILLING → billing_handler, TECHNICAL → technical_handler, GENERAL → general_handler } When a message flows through:
  • A customer sends: “I was charged twice for this same order this month.”
    The workflow runs START → process_message → route_message. The router inspects the text and returns route="BILLING". The runtime looks up "BILLING" in the route map and runs only the billing branch; the technical and general handlers are not executed.
A dark-themed flowchart titled "A Billing Message" with a customer complaint reading "I was charged twice for this same order this month." It shows a start → process_message → Router flow that branches to Billing, Technical, and General handlers.
  • Marcus sends: “The app crashes every time I hit Save.”
    The router returns route="TECHNICAL", and the runtime follows the technical branch. The same graph and same code run — only the router’s returned label differs.

Best practices and common pitfalls

  • Use clear, consistent route labels (e.g., uppercase constants like "BILLING"). Route label matching is exact — "billing" ≠ "BILLING".
  • Always include a fallback route (e.g., "GENERAL") to avoid dead-ends for unexpected input.
  • Keep router logic focused on routing decisions (keywords, intent classification, simple heuristics). Heavy processing should remain in handler nodes.
  • Log the chosen route for observability and easier debugging.
  • If you support many routes, consider using structured classification (ML model or intent detection) rather than a large chain of keyword checks.

Quick checklist

  • Router returns an Event with a route string.
  • Workflow edges include a route map that lists all allowed labels.
  • Include a fallback route like "GENERAL".
  • Route label keys and router return values match exactly (case-sensitive).
  • Handlers are focused on resolving the routed issue.
What you implemented is conditional routing: the graph itself remains static (branches declared up front), while the runtime selects the predefined path that best fits each incoming message.

Watch Video