Time Travel
Replay from the past.
Every checkpoint has its own config. If you invoke the graph with a past checkpoint's config, and no new input, LangGraph replays from that point. Steps before it are reused, and steps after it run again.

- Each checkpoint has a config
- Invoke from the past
- Replay from there
Replaying from a checkpoint
Each node in the order graph prints its name when it runs. After a full run, we search the history for the checkpoint where price was next. Invoking with none as the input, and that checkpoint's config, replays from there. Run it. The first run prints all three steps. The replay prints only price, and receipt.
from order_graph import graph
config = {"configurable": {"thread_id": "order-4"}}
print("first run:")
graph.invoke({"title": "dune", "quantity": 2}, config)
before_price = next(s for s in graph.get_state_history(config) if s.next == ("price",))
print("replay:")
graph.invoke(None, before_price.config)first run: running clean running price running receipt replay: running price running receipt
Also uses order_graph.py
from typing import TypedDict
from langgraph.checkpoint.memory import InMemorySaver
from langgraph.graph import StateGraph, START, END
PRICES = {"Dune": 9.99, "Circe": 10.99}
class Order(TypedDict):
title: str
quantity: int
total: float
receipt: str
def clean(s):
print(" running clean")
return {"title": s["title"].strip().title()}
def price(s):
print(" running price")
return {"total": round(PRICES[s["title"]] * s["quantity"], 2)}
def receipt(s):
print(" running receipt")
return {"receipt": f"{s['quantity']} x {s['title']} = £{s['total']}"}
b = StateGraph(Order)
b.add_sequence([clean, price, receipt])
b.add_edge(START, "clean"); b.add_edge("receipt", END)
graph = b.compile(checkpointer=InMemorySaver())When to replay
Replay is great for debugging. Rerun a step after fixing a bug, without repeating the steps before it. For model steps, a replay calls the model again, so the answer may differ. That's useful for comparing outputs.
| key | value |
|---|---|
| Debug | rerun one step |
| Reuse | earlier steps |
| Model steps | called again |
| Input | None + old config |
Summary
Invoke with none and a past checkpoint's config to replay from that point. Earlier steps are reused. Next, forking, to take a different path.
Key takeaways- Find the checkpoint
- invoke(None, snap.config)
- Later steps rerun