Conditional edges
A conditional edge calls a routing function after a node finishes. The function reads the updated state and returns the next node name, END, or a list of destinations.1
Tiny example
Section titled “Tiny example”from typing import Literalfrom langgraph.graph import END
def route_refund(state: RefundState) -> Literal["approve", "review", END]: if state["policy_violation"]: return "review" if state["eligible"]: return "approve" return END
builder.add_conditional_edges("check_policy", route_refund)Remember the order:
- Node returns an update.
- LangGraph applies the update.
- Router reads the new state.
- Router returns the destination.
Failure note
Section titled “Failure note”Every loop needs a tested stop condition. Otherwise the graph eventually reaches its recursion limit instead of completing normally.
Related
Section titled “Related”Footnotes
Section titled “Footnotes”-
LangChain, Graph API overview. ↩