[GH-ISSUE #1120] [langgraph]: Run graph nodes in parallel #151

Closed
opened 2026-02-17 17:19:17 -05:00 by yindo · 0 comments
Owner

Originally created by @jsxzhub on GitHub (Oct 24, 2025).
Original GitHub issue: https://github.com/langchain-ai/docs/issues/1120

Type of issue

issue / bug

Language

Python

Description

import operator
from typing import Annotated, Any
from typing_extensions import TypedDict
from langgraph.graph import StateGraph, START, END

class State(TypedDict):
# The operator.add reducer fn makes this append-only
aggregate: Annotated[list, operator.add]

def a(state: State):
print(f'Adding "A" to {state["aggregate"]}')
return {"aggregate": ["A"]}

def b(state: State):
print(f'Adding "B" to {state["aggregate"]}')
return {"aggregate": ["B"]}

def b_2(state: State):
print(f'Adding "B_2" to {state["aggregate"]}')
return {"aggregate": ["B_2"]}

def c(state: State):
print(f'Adding "C" to {state["aggregate"]}')
return {"aggregate": ["C"]}

def c_2(state: State):
print(f'Adding "C_2" to {state["aggregate"]}')
return {"aggregate": ["C_2"]}

def d(state: State):
print(f'Adding "D" to {state["aggregate"]}')
return {"aggregate": ["D"]}

builder = StateGraph(State)
builder.add_node(a)
builder.add_node(b)
builder.add_node(b_2)
builder.add_node(c)
builder.add_node(d)
builder.add_edge(START, "a")
builder.add_edge("a", "b")
builder.add_edge("a", "c")
builder.add_edge("b", "b_2")
builder.add_edge("b_2", "d")
builder.add_edge("c", "d")
builder.add_edge("d", END)
graph = builder.compile()

from IPython.display import Image, display

display(Image(graph.get_graph().draw_mermaid_png()))

print(graph.invoke({"aggregate": []}))

result:

Adding "A" to []
Adding "B" to ['A']
Adding "C" to ['A']
Adding "B_2" to ['A', 'B', 'C']
Adding "D" to ['A', 'B', 'C']
Adding "D" to ['A', 'B', 'C', 'B_2', 'D']
{'aggregate': ['A', 'B', 'C', 'B_2', 'D', 'D']}

Why did "D" execute twice?

Originally created by @jsxzhub on GitHub (Oct 24, 2025). Original GitHub issue: https://github.com/langchain-ai/docs/issues/1120 ### Type of issue issue / bug ### Language Python ### Description import operator from typing import Annotated, Any from typing_extensions import TypedDict from langgraph.graph import StateGraph, START, END class State(TypedDict): # The operator.add reducer fn makes this append-only aggregate: Annotated[list, operator.add] def a(state: State): print(f'Adding "A" to {state["aggregate"]}') return {"aggregate": ["A"]} def b(state: State): print(f'Adding "B" to {state["aggregate"]}') return {"aggregate": ["B"]} def b_2(state: State): print(f'Adding "B_2" to {state["aggregate"]}') return {"aggregate": ["B_2"]} def c(state: State): print(f'Adding "C" to {state["aggregate"]}') return {"aggregate": ["C"]} def c_2(state: State): print(f'Adding "C_2" to {state["aggregate"]}') return {"aggregate": ["C_2"]} def d(state: State): print(f'Adding "D" to {state["aggregate"]}') return {"aggregate": ["D"]} builder = StateGraph(State) builder.add_node(a) builder.add_node(b) builder.add_node(b_2) builder.add_node(c) builder.add_node(d) builder.add_edge(START, "a") builder.add_edge("a", "b") builder.add_edge("a", "c") builder.add_edge("b", "b_2") builder.add_edge("b_2", "d") builder.add_edge("c", "d") builder.add_edge("d", END) graph = builder.compile() from IPython.display import Image, display display(Image(graph.get_graph().draw_mermaid_png())) print(graph.invoke({"aggregate": []})) result: Adding "A" to [] Adding "B" to ['A'] Adding "C" to ['A'] Adding "B_2" to ['A', 'B', 'C'] Adding "D" to ['A', 'B', 'C'] Adding "D" to ['A', 'B', 'C', 'B_2', 'D'] {'aggregate': ['A', 'B', 'C', 'B_2', 'D', 'D']} Why did "D" execute twice?
yindo added the langchain label 2026-02-17 17:19:17 -05:00
yindo closed this issue 2026-02-17 17:19:17 -05:00
yindo changed title from [langgraph]: Run graph nodes in parallel to [GH-ISSUE #1120] [langgraph]: Run graph nodes in parallel 2026-06-05 17:25:20 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/docs#151