## Summary Fix time travel (replay and fork) for graphs with interrupts and subgraphs. ## Problem Two issues with replaying/forking from earlier checkpoints: 1. **Stale interrupt values during replay** — Replays incorrectly reused cached `RESUME` values from prior `interrupt()` calls, so interrupts silently returned stale answers instead of re-firing. 2. **Wrong subgraph state during time travel** — Subgraphs always loaded their **latest** checkpoint instead of the one corresponding to the parent's historical state. This caused subgraphs to skip execution or produce incorrect results during replay/fork. ## Changes Code changes span `libs/langgraph/langgraph/pregel/_loop.py`, `libs/langgraph/langgraph/_internal/_constants.py`, and a new `libs/langgraph/langgraph/_internal/_replay.py` module: - **Strip stale `RESUME` writes on replay** — During replays, cached `RESUME` writes are filtered out so `interrupt()` re-fires instead of returning old values. Genuine resumes (`Command(resume=...)`) preserve these writes. - **Rename `skip_done_tasks` → `is_replaying`** — Clearer naming for the flag that tracks whether the current run is replaying from a specific checkpoint. - **New `ReplayState` class (`_replay.py`)** — Encapsulates subgraph checkpoint loading during time-travel. Tracks a parent checkpoint ID upper bound and which subgraph namespaces have already loaded their pre-replay checkpoint. On the first visit to a subgraph namespace, it loads the latest checkpoint created *before* the replay point (via `checkpointer.list(..., before=...)` with `limit=1`). On subsequent visits (e.g. the same subgraph in a later loop iteration), it falls back to normal latest-checkpoint loading. The task-id suffix is stripped from namespaces so the same logical subgraph is recognized across loop iterations. - **New `CONFIG_KEY_REPLAY_STATE` config key** — The parent graph creates a `ReplayState` instance and passes it to subgraphs via config. For forks (`source=update`), the replay state uses the fork's parent checkpoint ID since the fork was created after the subgraph's original checkpoints. The single `ReplayState` instance is shared by reference across all derived configs within one parent execution. - **Subgraph checkpoint loading in `__enter__`/`__aenter__`** — When a subgraph detects a `ReplayState` in its config, it delegates checkpoint loading to `ReplayState.get_checkpoint`/`aget_checkpoint` instead of using the default `get_tuple`. It also clears `CONFIG_KEY_RESUMING` so `_first` re-applies input and recreates ephemeral routing channels. ## Tests New test files `test_time_travel.py` (~2500 lines) and `test_time_travel_async.py` (~2200 lines) covering: - Replay and fork with interrupts (single and multiple) - Replay and fork for graphs with and without subgraphs - Correct subgraph checkpoint restoration during parent time travel - `get_state` with subgraph state during replay
Trusted by companies shaping the future of agents – including Klarna, Replit, Elastic, and more – LangGraph is a low-level orchestration framework for building, managing, and deploying long-running, stateful agents.
Get started
Install LangGraph:
pip install -U langgraph
Create a simple workflow:
from langgraph.graph import START, StateGraph
from typing_extensions import TypedDict
class State(TypedDict):
text: str
def node_a(state: State) -> dict:
return {"text": state["text"] + "a"}
def node_b(state: State) -> dict:
return {"text": state["text"] + "b"}
graph = StateGraph(State)
graph.add_node("node_a", node_a)
graph.add_node("node_b", node_b)
graph.add_edge(START, "node_a")
graph.add_edge("node_a", "node_b")
print(graph.compile().invoke({"text": ""}))
# {'text': 'ab'}
Get started with the LangGraph Quickstart.
To quickly build agents with LangChain's create_agent (built on LangGraph), see the LangChain Agents documentation.
Tip
For developing, debugging, and deploying AI agents and LLM applications, see LangSmith.
Core benefits
LangGraph provides low-level supporting infrastructure for any long-running, stateful workflow or agent. LangGraph does not abstract prompts or architecture, and provides the following central benefits:
- Durable execution: Build agents that persist through failures and can run for extended periods, automatically resuming from exactly where they left off.
- Human-in-the-loop: Seamlessly incorporate human oversight by inspecting and modifying agent state at any point during execution.
- Comprehensive memory: Create truly stateful agents with both short-term working memory for ongoing reasoning and long-term persistent memory across sessions.
- Debugging with LangSmith: Gain deep visibility into complex agent behavior with visualization tools that trace execution paths, capture state transitions, and provide detailed runtime metrics.
- Production-ready deployment: Deploy sophisticated agent systems confidently with scalable infrastructure designed to handle the unique challenges of stateful, long-running workflows.
LangGraph’s ecosystem
While LangGraph can be used standalone, it also integrates seamlessly with any LangChain product, giving developers a full suite of tools for building agents. To improve your LLM application development, pair LangGraph with:
- LangSmith — Helpful for agent evals and observability. Debug poor-performing LLM app runs, evaluate agent trajectories, gain visibility in production, and improve performance over time.
- LangSmith Deployment — Deploy and scale agents effortlessly with a purpose-built deployment platform for long running, stateful workflows. Discover, reuse, configure, and share agents across teams — and iterate quickly with visual prototyping in LangGraph Studio.
- LangChain – Provides integrations and composable components to streamline LLM application development.
Note
Looking for the JS version of LangGraph? See the JS repo and the JS docs.
Additional resources
- Guides: Quick, actionable code snippets for topics such as streaming, adding memory & persistence, and design patterns (e.g. branching, subgraphs, etc.).
- Reference: Detailed reference on core classes, methods, how to use the graph and checkpointing APIs, and higher-level prebuilt components.
- Examples: Guided examples on getting started with LangGraph.
- LangChain Forum: Connect with the community and share all of your technical questions, ideas, and feedback.
- LangChain Academy: Learn the basics of LangGraph in our free, structured course.
- Case studies: Hear how industry leaders use LangGraph to ship AI applications at scale.
Acknowledgements
LangGraph is inspired by Pregel and Apache Beam. The public interface draws inspiration from NetworkX. LangGraph is built by LangChain Inc, the creators of LangChain, but can be used without LangChain.