Conditional Routing

Conditional routing is driven by edge when values and node return values.

Edge syntax

TS
edges: [ ["route", "askChoice", { when: "choice" }], ["route", "askMulti", { when: "multi" }], ["route", "askText", { when: "text" }], ]

Node return

TS
return { condition: "multi", data: { mode: "multi" }, };

createLangGraph matches in this order:

  1. state.lastCondition
  2. state.lastIntent

If no condition matches for that conditional group, runtime falls back to an internal __end__ mapping for that source node.

Example loop

TS
edges: [ ["todo", "todo", { when: "more" }], ["todo", "final", { when: "done" }], ["final", "__end__"], ]
TS
return { condition: hasMore ? "more" : "done", data: { idx: nextIdx }, };

Workflow transition (different from edge routing)

Use transitionTo to jump to another workflow id:

TS
return { transitionTo: "general-chat", data: { reason: "fallback" }, };

The orchestrator emits a transition chunk and loads the target workflow with selectWorkflow.