Compile and Invoke
Running a graph.
The builder is a blueprint. Compile turns it into a graph you can run. A compiled graph is a LangChain runnable, so it has invoke, batch, and stream, just like a model or a chain.

- Builder is a blueprint
- Compile makes it runnable
- invoke, batch, stream
Invoke and batch
We compile a small graph that writes a shelf label for a book. Invoke runs it once, and returns the final state. Batch runs it for a list of inputs. Run it. One label from invoke, then three from batch, in order.
from typing import TypedDict
from langgraph.graph import StateGraph, START, END
class State(TypedDict):
title: str
label: str
def make_label(state):
return {"label": f"[ {state['title'].upper()} ]"}
builder = StateGraph(State)
builder.add_node(make_label)
builder.add_edge(START, "make_label"); builder.add_edge("make_label", END)
graph = builder.compile()
print(graph.invoke({"title": "Dune"})["label"])
for result in graph.batch([{"title": t} for t in ["Emma", "Circe", "The Hobbit"]]):
print(result["label"])[ DUNE ] [ EMMA ] [ CIRCE ] [ THE HOBBIT ]
What invoke returns
Invoke returns the whole final state, as a dictionary. Pick out the keys you need. Input keys you don't set are simply missing, until a node writes them. And because the graph is a runnable, async versions like a invoke work too.
| key | value |
|---|---|
| Returns | the final state |
| Pick | the keys you need |
| batch | many inputs |
| Async | ainvoke, abatch |
Summary
Compile turns the builder into a runnable graph. Invoke runs it once, batch runs it many times. Next, drawing a graph to see its shape.
Key takeaways- builder.compile()
- graph.invoke
- graph.batch