Skip to main content
In this lesson we show a practical debugging pattern for LangGraph-style workflows: time travel via state injection. Using simple checkpointing, you can rewind a workflow to an earlier step, modify the saved state, and resume execution from that point. This enables fast experimentation, targeted debugging, and verification of alternate decision paths without re-running the entire pipeline. Why this is useful
  • Debug agent reasoning and decision logic by exploring alternate histories.
  • Reproduce and test edge cases by changing specific values at a chosen checkpoint.
  • Save time when only a later-stage decision needs to be inspected or changed.
Keywords: time travel, state injection, checkpointing, LangGraph, workflow state, debugging

Overview

We’ll build a minimal example in Python that demonstrates:
  1. Creating and storing checkpoints as deep copies of workflow state.
  2. Rewinding to a specific checkpoint.
  3. Injecting a modified value into that checkpointed state.
  4. Resuming execution from the rewound checkpoint to observe a different outcome.
Code for the demo is organized into discrete blocks so you can run each section independently.
Define a compact TypedDict to represent the workflow state used in the demo:
Next, define the workflow nodes. This tiny workflow has two phases:
  1. Evaluate (marks the state as evaluated)
  2. Route (chooses a path based on confidence)
Build a tiny checkpoint engine to simulate LangGraph’s checkpointing. Each checkpoint stores a deep copy of the state in a history list so it can be inspected or restored later.
Run the workflow once with a low-confidence input so the route chooses the fallback path. We print both the final state and the saved checkpoints for inspection.
Each saved checkpoint represents a snapshot of execution at a particular step. Time travel means selecting one of those snapshots, changing the state, and continuing from there to observe how the workflow would behave under the modified conditions.
Time travel is useful for debugging and experimentation: instead of rerunning the entire pipeline, you can jump to the step you care about, change a variable, and see what would have happened.

Inspecting checkpoints

Here’s a concise table that summarizes the checkpoints created in the example:

Rewind, inject, and resume

Now rewind to the checkpoint saved immediately after evaluation (after_evaluate), inject a higher confidence value, and resume routing from that checkpoint so the workflow follows the alternate path.
Compare the original run outcome with the time-travel outcome:
Because we injected a higher confidence before routing, the resumed execution followed the main_path instead of the fallback_path. This demonstrates how state injection lets you explore alternate outcomes without re-running the entire workflow.
When modifying checkpoints, always work on deep copies (as shown) to avoid mutating historical records. Preserving immutable checkpoints ensures reproducibility and accurate auditing of prior runs.

When to use time travel with state injection

  • Reproduce a bug that occurs only with a specific intermediate value.
  • Test how downstream logic responds to different upstream outputs.
  • Perform A/B style experiments by changing one variable at a checkpoint and comparing outcomes.

References and further reading

Key takeaway: State injection (time travel) lets you rewind a workflow to a chosen checkpoint, modify the saved state, and continue execution from there—making debugging, testing, and scenario exploration faster and more targeted.

Watch Video

Practice Lab