AI Hints
Home›LangGraph Tutorial›Checkpointers and Threads
LangGraph · Lesson 40 of 120

Checkpointers

Saving state.

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

So far, every run starts from scratch. A checkpointer changes that. After every step, it saves the state. The next run on the same conversation continues from the saved state.

Checkpointers
From the video: Checkpointers
  • Runs start from scratch
  • Save after every step
  • Continue next time

A graph that remembers

Visits uses operator add, and the node adds one each time. We compile with an in memory saver. The config holds a thread ID, which names the conversation. We invoke twice on the same thread. Run it. The second run continues from the first, so visits reaches two.

checkpointer.pypython
import operator
from typing import Annotated, TypedDict
from langgraph.checkpoint.memory import InMemorySaver
from langgraph.graph import StateGraph, START

class State(TypedDict):
    visits: Annotated[int, operator.add]

def visit(s):
    return {"visits": 1}

b = StateGraph(State); b.add_node(visit); b.add_edge(START, "visit")
graph = b.compile(checkpointer=InMemorySaver())

config = {"configurable": {"thread_id": "sam"}}
for run in [1, 2]:
    print(f"run {run}: visits =", graph.invoke({}, config)["visits"])
Output
run 1: visits = 1
run 2: visits = 2

What checkpointers give you

Checkpointers unlock most of LangGraph's power. Memory across turns. Pausing for a human, and resuming later. Looking back at every past step. And recovering after a crash, from the last saved step.

keyvalue
Memoryacross turns
Pauseresume later
Historyevery step saved
Recoveryafter a crash

Summary

A checkpointer saves the state after every step, and a thread ID names the conversation. Next, keeping conversations apart with threads.

Key takeaways
  • compile(checkpointer=...)
  • thread_id in config
  • Saved every step
Next up: Threads — separate conversations