checkpointer
when compiling the graph and a thread_id
when calling your graph, LangGraph automatically saves the state after each step. When you invoke the graph again using the same thread_id
, the graph loads its saved state, allowing the chatbot to pick up where it left off.
We will see later that checkpointing is much more powerful than simple chat memory - it lets you save and resume complex state at any time for error recovery, human-in-the-loop workflows, time travel interactions, and more. But first, let’s add checkpointing to enable multi-turn conversations.
MemorySaver
checkpointerMemorySaver
checkpointer:
SqliteSaver
or PostgresSaver
and connect a database.
State
as the graph works through each node:
{"messages": []}
).thread_id
in the config. See this call’s LangSmith trace for comparison.
state
for a given config at any time, call getState(config)
.
next
node to process. In our case, the graph has reached an END
state, so next
is empty.
Congratulations! Your chatbot can now maintain conversation state across sessions thanks to LangGraph’s checkpointing system. This opens up exciting possibilities for more natural, contextual interactions. LangGraph’s checkpointing even handles arbitrarily complex graph states, which is much more expressive and powerful than simple chat memory.
Check out the code snippet below to review the graph from this tutorial: