By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
A static edge list assumes you know the branches when you compile the graph. Real work often does not: summarise one document per topic in the customer's request, evaluate every candidate answer, or process the rows an upstream lookup returned. `Send` covers that case. A conditional edge can return a list of Send objects instead of a label; the runtime starts the target node once per object with that object's payload as its input.
That is the map half of map-reduce: the number of map tasks is decided at runtime. The reduce half is an ordinary node with an incoming edge from the map node — it runs once after every sent branch finishes and reads the reduced state, exactly like the fan-in from Lesson 5.
from operator import add
from typing import Annotated, TypedDict
from langgraph.graph import END, START, StateGraph
from langgraph.types import Send
class ReportState(TypedDict):
topics: list[str]
summaries: Annotated[list[str], add]
class TopicState(TypedDict):
topic: str
def fan_out_topics(state: ReportState) -> list[Send]:
return [
Send("summarize_topic", {"topic": topic}) for topic in state["topics"]
]
def summarize_topic(state: TopicState) -> dict:
return {"summaries": [f"{state['topic']}: checked"]}
def collect(state: ReportState) -> dict:
return {"summaries": [f"collected {len(state['summaries'])} summaries"]}
builder = StateGraph(ReportState)
builder.add_node("summarize_topic", summarize_topic)
builder.add_node("collect", collect)
builder.add_conditional_edges(START, fan_out_topics)
builder.add_edge("summarize_topic", "collect")
builder.add_edge("collect", END)
graph = builder.compile()
result = graph.invoke({"topics": ["refunds", "shipping"], "summaries": []})
print(sorted(result["summaries"][:2]))
print(result["summaries"][-1])A compiled graph has the same callable contract as a node: it takes state and returns updates. So it can be added as a node in a larger graph. That is how you keep a big workflow readable: define a self-contained pipeline once, test it on its own, then compose it. The outer graph does not need to know the inner graph's nodes or edges — only the state keys they share.
from typing import TypedDict
from langgraph.graph import END, START, StateGraph
class InnerState(TypedDict):
text: str
def uppercase(state: InnerState) -> dict:
return {"text": state["text"].upper()}
inner_builder = StateGraph(InnerState)
inner_builder.add_node("uppercase", uppercase)
inner_builder.add_edge(START, "uppercase")
inner_builder.add_edge("uppercase", END)
inner_graph = inner_builder.compile()
class OuterState(TypedDict):
text: str
outer_builder = StateGraph(OuterState)
# A compiled graph is a valid node: same callable contract, same state keys.
outer_builder.add_node("normalize", inner_graph)
outer_builder.add_edge(START, "normalize")
outer_builder.add_edge("normalize", END)
outer_graph = outer_builder.compile()
print(outer_graph.invoke({"text": "harbor supply"})["text"])| Mechanism | When to use it | What decides the next step |
|---|---|---|
| Plain edge | The next step is always the same | The edge you added at build time |
| Conditional edge | One next node chosen from a fixed set | A router function reading state |
Send | The same node runs many times with different inputs | A router returning a list of Send payloads |
| Subgraph node | A reusable multi-node pipeline with its own internals | The outer graph's edges; the subgraph owns what is inside |
Command(goto=...) | A node wants to both update state and choose the next node | The node's return value (see Lesson 8 for the resume form) |
add_node("research", research_graph), not reach into the inner graph's nodes.research, retrieve, summarise; the trace then reads as a pipeline of capabilities.Key takeaways
Send(node, payload) starts that node once per payload — the width of a fan-out can be decided at runtime.
A conditional edge from START returning a list of Send objects is the map step; an incoming edge on a reduce node is the barrier.
A compiled graph is a valid node, so subgraphs let you build, test and reuse pipelines.
Pick the simplest control mechanism: plain edge, conditional edge, Send, subgraph or Command.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.