LangGraphLangGraph 1.2 · Python 3.10+
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
37 small wins to finish your pathNext lesson

Two paths at once

Two edges out of one point, and both nodes run. Not one after the other, but in the same step.

Support work is full of this. Before answering a billing complaint you want the account status and the payment history, and neither lookup needs the other's answer. Doing them one after the other is only slower.

One in, two across, one out
START. Two edges leave here instead of one.Step 1 of 4

A key for each result

Three keys. One for each check, and one for the summary. They write to different keys on purpose, and the next lesson is about what happens when they do not.

python
from typing_extensions import TypedDict

class State(TypedDict):
    account: str
    payments: str
    summary: str

Two checks and something to join them

python
def check_account(state):
    return {"account": "active"}

def check_payments(state):
    return {"payments": "two charges on 3 March"}
python
def summarise(state):
    return {"summary": f"account {state['account']}, payments: {state['payments']}"}

This one reads both keys, which only works because both checks have finished by the time it runs.

Two edges out, two edges in

python
from langgraph.graph import StateGraph, START

builder = StateGraph(State)
builder.add_node("check_account", check_account)
builder.add_node("check_payments", check_payments)
builder.add_node("summarise", summarise)
python
builder.add_edge(START, "check_account")
builder.add_edge(START, "check_payments")
builder.add_edge("check_account", "summarise")
builder.add_edge("check_payments", "summarise")

The first two edges are the fan out. Both nodes are ready at once, so both run in the same step. The last two are the fan in, and a node waits for every incoming edge before it runs.

Example
print(builder.compile().invoke({"account": "", "payments": "", "summary": ""})["summary"])

Two things worth noticing

Both results were there when summarise ran. That is the point of fanning out and coming back together. The work happened side by side and the results met in one dictionary.

summarise ran once, not twice. Two edges point at it, so you might expect two runs. A node waits for every incoming edge to finish, then runs a single time.

What in the same step really means
Running in the same step is not the same as running in threads. LangGraph gathers the nodes that are ready and runs that group together. For work that waits on a network, make the node async def and it genuinely overlaps. For plain Python like this, the benefit is the shape of the program, not the speed.
Try it yourself
  • Print the graph's edges and find the two leaving __start__.
  • Add a third check that runs alongside the other two.
  • Have check_payments try to read state["account"] and see what it gets.

This is what real progress feels like.