Parallel work with Send
Some work splits into many independent pieces whose number you only know at run time. Send runs one branch per piece, in parallel, then gathers the results.
Map, then reduce
In map-reduce, a list of items is processed item by item (map) and the results are combined (reduce). LangGraph’s Send does the map: a routing function returns one Send(node, input) per item, and LangGraph runs that node once for each, in the same step, each with its own input. The results land in a state key whose reducer concatenates them; a final node does the reduce.
import operator
from typing import Annotated, TypedDict
from langgraph.types import Send
class State(TypedDict):
docs: list[str]
summaries: Annotated[list[str], operator.add] # parallel writes are concatenated
def fan_out(state: State):
return [Send("summarise", {"doc": d}) for d in state["docs"]]
def summarise(item: dict) -> dict:
return {"summaries": [llm_summary(item["doc"])]}
builder.add_conditional_edges(START, fan_out, ["summarise"])
builder.add_edge("summarise", "combine")
builder.add_edge("combine", END)A worked example
Eight retrieved documents each take about 2 seconds to summarise. One by one that is 16 seconds; with Send all eight run in one step, so the map takes about as long as the slowest call, around 2 seconds, and the combine node then writes one answer from eight summaries. The same structure serves orchestrator-workers: a planner node emits one Send per subtask it invented.
In practice
Parallel branches multiply load: API rate limits and cost grow with the number of branches, so cap the fan-out. Keep each branch’s input small and self-contained, and make the reduce step robust to a branch that failed or returned nothing.
Easy to confuse
- Several fixed edges out of one node also run in parallel, but their number is fixed in the graph; Send decides it at run time.
- A branch receives only the input you send it, not the whole state.
What does returning [Send("summarise", {"doc": d}) for d in docs] from a conditional edge do?
Send schedules the same node many times with different inputs. The number of branches is decided at run time, from the state.
Why does the summaries key need a reducer such as operator.add?
Without a reducer, parallel writes to one key would conflict. operator.add concatenates each branch’s list into one.
Ten documents take 2 s each to summarise. Roughly how long does the fan-out step take with Send?
All branches run in the same step, so the step takes about as long as the slowest branch (limited by rate limits and resources in practice).
Read more in the books
- LangChain and LangGraph documentation, LangChain: LangGraph: Graph API (Send and map-reduce).