AI Hints
Home›LangGraph Tutorial›Inspecting and Editing State
LangGraph · Lesson 45 of 120

State History

Every checkpoint.

⏱ 2 min read▶ Video at 47:20🎓 Free
Watch this lesson in the LangGraph courseWatch on YouTube ↗Full LangGraph course

A checkpointer doesn't just keep the latest state. It keeps a checkpoint after every step. Get state history lets you walk back through all of them, newest first.

State History
From the video: State History
  • Every step saved
  • Not just the latest
  • Walk back through them

Walking the history

We run the three step order pipeline. Get state history returns every checkpoint. For each one, we print the step number, what would run next, and the total at that moment. Run it. Reading from the bottom up, we see the input arrive, then clean, price, and receipt run, one by one.

history.pypython
from order_graph import graph

config = {"configurable": {"thread_id": "order-3"}}
graph.invoke({"title": "dune", "quantity": 2}, config)

for snap in graph.get_state_history(config):
    step = snap.metadata["step"]
    print(f"step {step:>2}  next={snap.next}  total={snap.values.get('total')}")
Output
step  3  next=()  total=19.98
step  2  next=('receipt',)  total=19.98
step  1  next=('price',)  total=None
step  0  next=('clean',)  total=None
step -1  next=('__start__',)  total=None
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):
    return {"title": s["title"].strip().title()}
def price(s):
    return {"total": round(PRICES[s["title"]] * s["quantity"], 2)}
def receipt(s):
    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())

Why history matters

History shows exactly how a result came about, step by step, which is gold for debugging. And every checkpoint has its own config, so you can go back to it, and run again from there. That's time travel, coming next.

keyvalue
Debugsee every step
Audithow a result came about
Configsone per checkpoint
Nexttime travel

Summary

Get state history lists every checkpoint of a thread, newest first. Each one can be revisited. Next, time travel.

Key takeaways
  • get_state_history
  • Newest first
  • A config per checkpoint
Next up: Time Travel — replay from the past