Deferred Nodes
Nodes that wait for all upstream paths to complete before executing. Essential for map-reduce and consensus patterns. @defer decorator.
Quick Reference
- →@defer decorator: marks a node to wait until all upstream branches have completed before running
- →Join semantics: deferred nodes act as synchronization barriers in parallel execution flows
- →Map-reduce collection: use @defer on the reduce node to guarantee all map branches finish first
- →Consensus patterns: gather results from multiple parallel evaluators before making a final decision
- →Works with Send() fan-out: the deferred node waits for all dynamically spawned branches to complete
What Are Deferred Nodes?
A deferred node waits until ALL upstream branches have completed before executing. It acts as a synchronization barrier — a join point in parallel flows.
In a graph with parallel branches (via Send() or multiple edges), LangGraph normally executes nodes as soon as their immediate predecessor completes. This means a reduce node might run after only one of five parallel branches finishes, seeing incomplete results. The @defer decorator changes this behavior: it tells LangGraph to hold the node until every upstream branch has completed and written its results to state. Only then does the deferred node execute, with the full aggregated state available.