LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • Graphs
  • Functional API
  • Pregel
  • Checkpointing
  • Storage
  • Caching
  • Types
  • Runtime
  • Config
  • Errors
  • Constants
  • Channels
  • Agents
LangGraph CLI
LangGraph SDK
LangGraph Supervisor
LangGraph Swarm
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

OverviewGraphsFunctional APIPregelCheckpointingStorageCachingTypesRuntimeConfigErrorsConstantsChannelsAgents
LangGraph CLI
LangGraph SDK
LangGraph Supervisor
LangGraph Swarm
Language
Theme
PythonlanggraphgraphstateStateGraphcompile
Method●Since v0.1

compile

Compiles the StateGraph into a CompiledStateGraph object.

The compiled graph implements the Runnable interface and can be invoked, streamed, batched, and run asynchronously.

Copy
compile(
  self,
  checkpointer: Checkpointer = None,
  *,
  cache: BaseCache | None = None,
  store: BaseStore | None = None,
  interrupt_before: All | list[str] | None = None,
  interrupt_after: All | list[str] | None = None,
  debug: bool = False,
  name: str | None = None
) -> CompiledStateGraph[StateT, ContextT, InputT, OutputT]

Parameters

NameTypeDescription
checkpointerCheckpointer
Default:None

A checkpoint saver object or flag.

If provided, this Checkpointer serves as a fully versioned "short-term memory" for the graph, allowing it to be paused, resumed, and replayed from any point.

If None, it may inherit the parent graph's checkpointer when used as a subgraph.

If False, it will not use or inherit any checkpointer.

Important: When a checkpointer is enabled, you should pass a thread_id in the config when invoking the graph:

config = {"configurable": {"thread_id": "my-thread"}}
graph.invoke(inputs, config)

The thread_id is the key used to store and retrieve checkpoints. Use a unique ID for independent runs, or reuse the same ID to accumulate state across invocations (e.g., for conversation memory).

interrupt_beforeAll | list[str] | None
Default:None

An optional list of node names to interrupt before.

interrupt_afterAll | list[str] | None
Default:None

An optional list of node names to interrupt after.

debugbool
Default:False

A flag indicating whether to enable debug mode.

namestr | None
Default:None

The name to use for the compiled graph.

View source on GitHub