Nodes, Edges, Send, Command and Subgraphs
A LangGraph graph is nodes that return partial updates, wired by static edges, conditional edges, `Send` and `Command`, and executed by the Pregel runtime in super-steps. Know who runs in which step, how fan-in really behaves, how `Command` interacts with static edges, and how subgraphs exchange state.
Key points
- 1
add_edge(START, n)sets the entry andadd_edge(n, END)marks a terminal node;set_entry_point/set_finish_pointare older equivalents.STARTcan only be an edge source andENDonly a target, compile fails without an edge fromSTART, and a node with no outgoing edge simply ends the run. - 2
add_node(fn)names the node after the function. Names must be unique;__start__/__end__and the characters:and|are reserved. A compiled graph can itself be added as a node. - 3
Conditional edges:
add_conditional_edges(src, route, path_map_or_list). The router returns a node name, a list of names,ENDorSendobjects. With a path map, an unmapped return raisesKeyErrorat run time; without one, an unknown name is dropped with a warning and the run ends quietly. - 4
Execution follows the Pregel / bulk synchronous parallel model: plan (pick triggered nodes), execute in parallel (writes invisible to siblings), update channels through reducers. Parallel siblings read the same pre-step snapshot; checkpoints are saved at step boundaries.
- 5
A super-step is transactional: if one parallel branch raises, none of that step's updates are applied. With a checkpointer the successful branches' writes are saved and are not re-run when the thread resumes.
- 6
Fan-in: separate edges run the target once per step in which a branch finishes (twice for unequal branch lengths);
add_edge([a, b], d)runsdonce after all listed nodes, and never if one is skipped;defer=Truerunsdonce after all pending work in the whole graph. - 7
Send(node, payload)starts one invocation per object with only the payload as input, all in the next super-step. It can come from any conditional edge (including fromSTART) or fromCommand.goto. Workers write back to shared keys, so those keys need reducers. Cap parallelism with the top-level config keymax_concurrency. - 8
Command(update=..., goto=...)writes state and routes in one return value;gotoaccepts names, lists,ENDandSend. Annotate-> Command[Literal[...]](or passdestinations=toadd_node) for correct drawings.Commandadds dynamic edges, so static edges from the same node still run. - 9
Use conditional edges for pure routing over existing state and
Commandwhen a node must both update and route.Command(resume=...)is the onlyCommandmeant as graph input. - 10
Subgraphs: add a compiled subgraph directly with
add_nodewhen it shares state keys with the parent; call it inside a wrapper node that maps state in and out when schemas differ (for example private per-agent message histories).Command(graph=Command.PARENT)hands off to a node of the closest parent graph. - 11
Node granularity: checkpoints fall at node boundaries, so smaller nodes repeat less work after failures and allow per-node retry policies and visible intermediate results. A node can instead wrap several operations in
@taskcalls, whose results are checkpointed. - 12
Graph API vs Functional API: both compile to
Pregel.@entrypointplus@taskkeep plain Python control flow, save task results into the entrypoint's checkpoint and exposeprevious/entrypoint.final; the Graph API gives explicit shared state, a drawable structure and a checkpoint after each super-step.
Common traps
Returning
Command(goto=...)from a node that also hasadd_edgeto another node runs both destinations; the same holds forCommand.PARENThandoffs from a subgraph node.A list-form join silently never runs when a conditional fan-out skips one of its sources; use separate edges plus
defer=Truethere.An empty
Sendlist schedules nothing, so an aggregator reachable only through the workers never runs.defer=Truewaits for unrelated branches too, adding their latency to the aggregator.A compiled subgraph with no shared keys added directly as a node receives none of its inputs; wrap it in a node function instead.
Assigning
state["x"] = ...inside a node is lost, while mutating a nested list in place leaks through a shared reference; always return the changes.max_concurrency(likerecursion_limit) is a top-level config key; insideconfigurableit does nothing.
Read the source
Further reading
Suggest a resourceNo extra reading for Nodes, Edges, Send, Command and Subgraphs yet. Found a guide, video or cheat sheet that made it click? Share it and help the next learner.
Test yourself on Nodes, Edges, Send, Command and Subgraphs
Ten questions, with the answer and explanation after each one.