Skip to main content
When working with non-deterministic systems that make model-based decisions (e.g., agents powered by LLMs), it can be useful to examine their decision-making process in detail:
  1. Understand reasoning: Analyze the steps that led to a successful result.
  2. Debug mistakes: Identify where and why errors occurred.
  3. Explore alternatives: Test different paths to uncover better solutions.
LangGraph provides time travel functionality to support these use cases. Specifically, you can resume execution from a prior checkpoint — either replaying the same state or modifying it to explore alternatives. In all cases, resuming past execution produces a new fork in the history. To use time-travel in LangGraph:
  1. Run the graph with initial inputs using invoke or stream methods.
  2. Identify a checkpoint in an existing thread: Use the get_state_history method to retrieve the execution history for a specific thread_id and locate the desired checkpoint_id. Alternatively, set an interrupt before the node(s) where you want execution to pause. You can then find the most recent checkpoint recorded up to that interrupt.
  3. Update the graph state (optional): Use the update_state method to modify the graph’s state at the checkpoint and resume execution from alternative state.
  4. Resume execution from the checkpoint: Use the invoke or stream methods with an input of None and a configuration containing the appropriate thread_id and checkpoint_id.
For a conceptual overview of time-travel, see Time travel.

In a workflow

This example builds a simple LangGraph workflow that generates a joke topic and writes a joke using an LLM. It demonstrates how to run the graph, retrieve past execution checkpoints, optionally modify the state, and resume execution from a chosen checkpoint to explore alternate outcomes.

Setup

First we need to install the packages required
Next, we need to set API keys for Anthropic (the LLM we will use)
Sign up for LangSmith to quickly spot issues and improve the performance of your LangGraph projects. LangSmith lets you use trace data to debug, test, and monitor your LLM apps built with LangGraph.

1. Run the graph

Output:

2. Identify a checkpoint

Output:
Output:

3. Update the state

update_state will create a new checkpoint. The new checkpoint will be associated with the same thread, but a new checkpoint ID.
Output:

4. Resume execution from the checkpoint

Output:

Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.