# State History, Replay and Time Travel — LangGraph Agents & Multi-Agent Systems

Source: https://www.geekswithgeeks.com/en/langgraph-agents/m-timetravel

> Inspect, rewind and fork past states for debugging.

## Every step is a snapshot

Because a checkpoint is saved after each step, you can list a thread's **state history** (`get_state_history`), inspect what the state looked like before any node ran, see which node is **next**, and even **resume from an earlier checkpoint** (optionally after editing the state) to explore a different outcome. This "time travel" helps debug agents (why did it take that branch?), recover from a bad step, and test "what if" changes without re-running everything from the start. It also supports **audit trails**: you can show exactly what the agent knew at each step.

## Listing a thread's history, run

I ran this offline with langgraph 1.2.12 and langchain-core 1.6.6 in a Python virtual environment. No API key or model is needed because plain Python functions stand in for the model, so the output is repeatable. Oldest first: the empty start (next node is the `__start__` marker), then n=0 before `a`, n=1 before `b`, and the final n=2 with nothing left to run.

```python
from typing import TypedDict
from langgraph.graph import StateGraph, START, END
from langgraph.checkpoint.memory import InMemorySaver

class State(TypedDict):
    n: int

def inc(s): return {"n": s["n"] + 1}

g = StateGraph(State)
g.add_node("a", inc); g.add_node("b", inc)
g.add_edge(START, "a"); g.add_edge("a", "b"); g.add_edge("b", END)
app = g.compile(checkpointer=InMemorySaver())
cfg = {"configurable": {"thread_id": "t"}}
app.invoke({"n": 0}, cfg)

snaps = list(app.get_state_history(cfg))          # newest first
for s in reversed(snaps):
    print("n =", s.values.get("n"), "| next:", s.next)

```

Output:

```
n = None | next: ('__start__',)
n = 0 | next: ('a',)
n = 1 | next: ('b',)
n = 2 | next: ()
```

**Quiz:** What does time travel let you do?

- [x] Inspect and resume from earlier checkpoints of a thread
- [ ] Change the past of the real world
- [ ] Skip all nodes
- [ ] Disable checkpoints

*Answer:* Inspect and resume from earlier checkpoints of a thread. Each checkpoint is a restorable snapshot of the run.
