Compiles the `StateGraph` into a `CompiledStateGraph` object. The compiled graph implements the `Runnable` interface and can be invoked, streamed, batched, and run asynchronously. Args: checkpointer: A checkpoint saver object or flag. If provide
(
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,
transformers: Sequence[Callable[[tuple[str, ...]], Any]] | None = None,
)
| 1162 | return self |
| 1163 | |
| 1164 | def compile( |
| 1165 | self, |
| 1166 | checkpointer: Checkpointer = None, |
| 1167 | *, |
| 1168 | cache: BaseCache | None = None, |
| 1169 | store: BaseStore | None = None, |
| 1170 | interrupt_before: All | list[str] | None = None, |
| 1171 | interrupt_after: All | list[str] | None = None, |
| 1172 | debug: bool = False, |
| 1173 | name: str | None = None, |
| 1174 | transformers: Sequence[Callable[[tuple[str, ...]], Any]] | None = None, |
| 1175 | ) -> CompiledStateGraph[StateT, ContextT, InputT, OutputT]: |
| 1176 | """Compiles the `StateGraph` into a `CompiledStateGraph` object. |
| 1177 | |
| 1178 | The compiled graph implements the `Runnable` interface and can be invoked, |
| 1179 | streamed, batched, and run asynchronously. |
| 1180 | |
| 1181 | Args: |
| 1182 | checkpointer: A checkpoint saver object or flag. |
| 1183 | |
| 1184 | If provided, this `Checkpointer` serves as a fully versioned "short-term memory" for the graph, |
| 1185 | allowing it to be paused, resumed, and replayed from any point. |
| 1186 | |
| 1187 | If `None`, it may inherit the parent graph's checkpointer when used as a subgraph. |
| 1188 | |
| 1189 | If `False`, it will not use or inherit any checkpointer. |
| 1190 | |
| 1191 | **Important**: When a checkpointer is enabled, you should pass a `thread_id` |
| 1192 | in the config when invoking the graph: |
| 1193 | |
| 1194 | ```python |
| 1195 | config = {"configurable": {"thread_id": "my-thread"}} |
| 1196 | graph.invoke(inputs, config) |
| 1197 | ``` |
| 1198 | |
| 1199 | The `thread_id` is the key used to store and retrieve checkpoints. Use a |
| 1200 | unique ID for independent runs, or reuse the same ID to accumulate state |
| 1201 | across invocations (e.g., for conversation memory). |
| 1202 | |
| 1203 | interrupt_before: An optional list of node names to interrupt before. |
| 1204 | interrupt_after: An optional list of node names to interrupt after. |
| 1205 | debug: A flag indicating whether to enable debug mode. |
| 1206 | name: The name to use for the compiled graph. |
| 1207 | transformers: Optional sequence of `StreamTransformer` classes or |
| 1208 | configured factories. Classes and factories are instantiated |
| 1209 | per run whenever `stream_events(version="v3")` / `astream_events(version="v3")` is called and are |
| 1210 | propagated to subgraph scopes. Custom factories should follow |
| 1211 | the standard `StreamTransformer` constructor shape by |
| 1212 | accepting `scope` as their first argument. Appended after the |
| 1213 | built-in stream transformers. |
| 1214 | |
| 1215 | Returns: |
| 1216 | CompiledStateGraph: The compiled `StateGraph`. |
| 1217 | """ |
| 1218 | checkpointer = ensure_valid_checkpointer(checkpointer) |
| 1219 | |
| 1220 | serde_allowlist: set[tuple[str, ...]] | None = None |
| 1221 | if _serde.STRICT_MSGPACK_ENABLED: |