- 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.
Overview
We’ll build a minimal example in Python that demonstrates:- Creating and storing checkpoints as deep copies of workflow state.
- Rewinding to a specific checkpoint.
- Injecting a modified value into that checkpointed state.
- Resuming execution from the rewound checkpoint to observe a different outcome.
TypedDict to represent the workflow state used in the demo:
- Evaluate (marks the state as evaluated)
- Route (chooses a path based on confidence)
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.
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
- Python
TypedDictand typing: https://docs.python.org/3/library/typing.html#typing.TypedDict - Checkpointing concepts (computing): https://en.wikipedia.org/wiki/Checkpoint_(computing)
- LangGraph concepts and docs (search for LangGraph checkpoints and debugging in your project docs)