LangChainLangChain 1.4 · Python 3.10+
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
46 small wins to finish your pathNext lesson →

Routing with a router node

A router is a classification step that sends each question to one specialist and then steps aside.

Last updated: 27 Sep, 2026 · LangChain 1.4

The supervisor in lesson 30 is a model deciding every turn. A router is a single classification step, often one model call or plain rules, that sends the question on and steps out of the way. With plain rules it is ordinary Python. It is cheaper and more predictable, and it cannot combine answers.

One router, two specialists
A questionorders or policiesThe routerone rule, no modelOrders agentShopModellookup_orderorder statusesPolicies agentHelpModelsearch_policiesscore 0.3 and up
Hover or tap a piece to see what it is and which lesson built it.
Follow a question

Pick one to watch it run, step by step.

The two specialists come from the previous lesson: orders_agent looks up orders and policies_agent answers from the policy documents. Here a router sends each question to one of them.

The route function

python
def route(question):
    if some_rule(question):             # one classification step
        return "orders", orders_agent
    return "policies", policies_agent   # the default specialist

Routing by an order id

route picks a specialist by looking for an order id. Nothing decides here except a regular expression.

python
import re

from specialists import last_reply, orders_agent, policies_agent


def route(question):
    if re.search(r"\b[A-Z]\d+\b", question):   # an order id, like A17
        return "orders", orders_agent
    return "policies", policies_agent            # everything else

The answer function

answer hands the question to the chosen agent and returns which one replied.

python
def answer(question):
    name, agent = route(question)               # pick one specialist
    return name, last_reply(agent, question)    # pass the question straight through

Running three questions through the router

Three questions through the router: two that fit one specialist, and one that needs two.

Example
from router import answer

for question in ["Where is A17?", "Is shipping free?", "Where is A17, and how long does a refund take?"]:
    name, reply = answer(question)
    print(f"{name:<8} {reply.splitlines()[-1]}")

Where the router hands off, and where it slips

  • The first two questions reached the right agent with no model deciding anything; a rule did it.
  • The third shows the limit: it mentions an order, so the whole sentence went to the orders agent alone.
  • That agent read "refund" as a refund request, a tool it does not have, so neither half was answered.
  • A router makes one choice: a question that needs two agents needs the supervisor from lesson 30, or a router that fans out and merges the answers, which the docs build with LangGraph.

Router vs supervisor

RouterSupervisor
DecisionOne step, up frontThe model, every turn
CostOne call, or plain rulesA model call per turn
Two areas at onceCannot combineAsks each and joins
PredictableSame route every time with rulesDepends on the model

When a router beats a supervisor

  • Sending each question to exactly one specialist by its topic.
  • A cheap first pass that escalates only the hard cases to a supervisor.
Watch out. A router sends the whole question to one agent, so a question that spans two areas gets half an answer. When two areas can appear together, route to a supervisor instead.
Try it yourself
  • Route questions that contain "refund" and an order id to the policies agent, and test both kinds.
  • Add a third specialist for account questions and a rule for it.
  • Print how many model calls answer makes for one question.

Every expert started right here.