LangGraph state, checkpoints, interrupts and time travel
What makes LangGraph different from a plain loop is persistence. Every super-step saves the whole state, so runs can pause for a person, resume after a crash, or be rewound and forked.
Interactive simulation. It needs JavaScript; the text below explains what it shows.
What you are looking at
The flow shows the nodes, the state panel shows exactly what they read and write, and the checkpoint list records the state after every step. The run pauses before sending until you approve, edit or reject; clicking a checkpoint restores it and starts a branch.
Things to try
- Step to the review node and edit the draft before approving.
- Reject, then click an earlier checkpoint to time-travel and try again.
- Watch the branch number when you resume from the past.
How it works in real systems
In LangGraph, compile the graph with a checkpointer (MemorySaver, SqliteSaver or PostgresSaver) and interrupt_before=['send']; resume with the same thread_id. get_state_history lists the checkpoints, and invoking with a past checkpoint_id forks from it.
This simulation replays a scripted run so that every step is the same each time; the structure is real, the timings and scores are typical values.
Code lab
The same idea in real code, step by step. Copy each block into a notebook or a file and run it in order.
Step 1 · A graph with a checkpointer and an interrupt
# pip install langgraph
from typing import TypedDict, Optional
from langgraph.graph import StateGraph, START, END
from langgraph.checkpoint.memory import MemorySaver
class State(TypedDict):
question: str; documents: list; draft: Optional[str]; sent: bool
def retrieve(s): return {"documents": ["Returns policy §2", "Shipping §3"]}
def generate(s): return {"draft": "Yes: send a photo of the damage and we will refund or replace the tent."}
def send(s): print("SENDING:", s["draft"]); return {"sent": True}
g = StateGraph(State)
for n, f in [("retrieve", retrieve), ("generate", generate), ("send", send)]: g.add_node(n, f)
g.add_edge(START, "retrieve"); g.add_edge("retrieve", "generate"); g.add_edge("generate", "send"); g.add_edge("send", END)
app = g.compile(checkpointer=MemorySaver(), interrupt_before=["send"]) # pause for a human before sending
Step 2 · Run, pause, edit, resume
cfg = {"configurable": {"thread_id": "customer-42"}}
app.invoke({"question": "Refund for a torn tent?", "documents": [], "draft": None, "sent": False}, cfg)
print(app.get_state(cfg).next) # ('send',): paused before send
app.update_state(cfg, {"draft": "Yes: send a photo of the damage; we will refund the full price or send a new tent."})
app.invoke(None, cfg) # resume from the checkpoint
Step 3 · Time travel
history = list(app.get_state_history(cfg)) # newest first
for snap in history: print(snap.config["configurable"]["checkpoint_id"], snap.next, snap.values.get("draft"))
past = next(s for s in history if s.next == ("generate",))
app.invoke(None, past.config) # re-run from that checkpoint: a new branch of the thread
In production use SqliteSaver or PostgresSaver so threads survive restarts.