Conditional Routing
Fixed edges cannot say 'if billing, go to refund; if done, finish'. Conditional routing is the if/else of the graph — visible, testable, and checkpointed between hops.
A station switch: the dispatcher reads the ticket color and throws the track. The train does not decide the map.
Visual Workflows
Start here — scroll inside each diagram frame to explore, then use + / − to zoom up to 200% if needed.
Overview
Scroll inside the frame to explore · use + / − to zoom up to 200%
Scroll inside the frame to explore · use + / − to zoom up to 200%
The agent loop as a graph
Scroll inside the frame to explore · use + / − to zoom up to 200%
This is ReAct, drawn. The loop is an edge back, not a Python while True you cannot pause.
Fan-out with Send
Scroll inside the frame to explore · use + / − to zoom up to 200%
One planner, many parallel workers, then join. Each worker is a node run with its own payload.
Key Takeaways
- 1.A conditional edge is a function that reads state and returns the name of the next node.
- 2.This is how graphs loop: assistant → tools → assistant until the model stops calling tools.
- 3.Command can update state and choose the next node in one return — use it when the node already knows the destination.
- 4.Send fans one state out to many workers (map-reduce). Do not fake fan-out with a for-loop inside a node.
- 5.add_conditional_edges(source, path_fn, path_map) maps return values to node names. path_fn must be deterministic from state.
Learn elsewhere
- →Tools in the Graph — next
- →Human-in-the-Loop
Real Example
Scenario
After classify, ticket_type is billing or tech. path_fn returns 'billing' or 'tech'. Those strings must match node names in the path map.
What you would do
Write the route function so it only returns known labels. Unknown label = bug, not a silent Finish. Cap loops with a step counter in state.
Commands
Commands to Remember
add_conditional_edges(node, path_fn, path_map)path_fn reads state, returns a node nameAlways include a done pathSend = fan-out, not a for-loop inside a node
Cheat Sheet
Quick recap
quick ref- •path_fn → node name
- •Loops are edges back
- •Done path required
- •Send for parallel
Common Mistakes
- ✕Returning a node name that does not exist in the path map
- ✕An agent loop with no max steps or done condition
- ✕Hiding branching inside one giant node so you cannot checkpoint between cases
