StateGraph
StateGraph is the builder that holds a state schema, named nodes, and edges. It describes the workflow; compile() turns that description into something you can run.1
Tiny example
Section titled “Tiny example”from typing_extensions import TypedDictfrom langgraph.graph import StateGraph
class OrderState(TypedDict): order_id: str status: str
builder = StateGraph(OrderState)Think of builder as a whiteboard. You still need to add work and routes.
| Object | Job |
|---|---|
StateGraph(OrderState) |
Starts the definition |
builder.add_node(...) |
Registers work |
builder.add_edge(...) |
Registers routing |
builder.compile() |
Produces the runnable graph |
Failure note
Section titled “Failure note”Creating StateGraph does not call a model, save state, or run anything. Do not confuse the builder with the compiled graph.
Related
Section titled “Related”Footnotes
Section titled “Footnotes”-
LangChain, Graph API overview. ↩