Preview — full styling will appear after the next deploy completes.

agentic-ai-patterns

Map-Reduce

Parallel fan-out and aggregation

Work is dynamically split into independent chunks (map), processed in parallel via Send primitives, then all results are merged by a reducer node.

flowchart TD
    S([__start__]) -->|Send| W1[worker genre_1]
    S -->|Send| W2[worker genre_2]
    S -->|Send| W3[worker genre_N]
    W1 --> R[reducer]
    W2 --> R
    W3 --> R
    R --> E([__end__])

Map-Reduce is the parallel workhorse of LangGraph. A `fan_out` node inspects the task and emits a `Send` object for each work item — in this case, one per book genre in the database. LangGraph schedules all `Send` targets to run concurrently, and each worker processes its own slice independently.

The key insight is the `Annotated[list, operator.add]` type on the results field in state. This reducer annotation tells LangGraph to *append* each worker's output to the list rather than overwriting it, which is essential for safely merging concurrent writes from many workers.

After all workers complete, a single `reducer` node receives the merged list and synthesizes the final answer. Map-Reduce is ideal for any task that can be decomposed into independent parallel units: per-document analysis, per-region statistics, or multi-source data fetching.