Async Graphs
Ainvoke.
Web servers handle many requests at once, using async code. LangGraph supports async nodes, and async methods, like a invoke and a stream. While one node waits for a network reply, other work can carry on.

- Servers use async
- Async nodes and methods
- Others work while one waits
Async nodes in parallel
Both nodes are async functions, which await a one second delay, standing in for network calls. They run in parallel from start. We run the graph with await a invoke. Run it. Two one second calls finish in about one second in total, not two.
import asyncio, operator, time
from typing import Annotated, TypedDict
from langgraph.graph import StateGraph, START
class State(TypedDict):
found: Annotated[list[str], operator.add]
async def bath(s):
await asyncio.sleep(1) # e.g. a network call
return {"found": ["Bath: 2"]}
async def bristol(s):
await asyncio.sleep(1)
return {"found": ["Bristol: 1"]}
b = StateGraph(State); b.add_node(bath); b.add_node(bristol)
b.add_edge(START, "bath"); b.add_edge(START, "bristol")
start = time.perf_counter(); out = asyncio.run(b.compile().ainvoke({"found": []}))
print(out["found"], f"in {time.perf_counter() - start:.1f}s")['Bath: 2', 'Bristol: 1'] in 1.0s
Async tips
Use async nodes when they call async libraries, like model a invoke. Use a invoke and a stream in async web servers. Don't mix in slow blocking calls, which hold everything up. And remember, parallel branches help even without async.
| key | value |
|---|---|
| Async nodes | await network calls |
| Methods | ainvoke, astream |
| Avoid | blocking calls |
| Servers | FastAPI and others |
Summary
Async nodes and a invoke let a graph wait for many things at once. Use them in async servers. Next, a quiz on reliability.
Key takeaways- async def node
- await graph.ainvoke
- Don't block