This tutorial builds on Add Tools.
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.
If youβre deploying your graph to LangGraph Platform, you do not need to set up a checkpointer manually β checkpointing and memory are handled for you automatically.This tutorial focuses on local development, where you do need to configure a checkpointer. When youβre ready to deploy, remove this checkpointer configuration.
1. Create a MemorySaver
checkpointer
Create a MemorySaver
checkpointer:
SqliteSaver
or PostgresSaver
and connect a database.
2. Compile the graph
Compile the graph with the provided checkpointer, which will checkpoint theState
as the graph works through each node:
3. Interact with your chatbot
Now you can interact with your bot!- Pick a thread to use as the key for this conversation.
- Call your chatbot:
The config was provided as the second positional argument when calling our graph. It importantly is not nested within the graph inputs (
{'messages': []}
).4. Ask a follow up question
Ask a follow up question:thread_id
in the config. See this callβs LangSmith trace for comparison.
5. Inspect the state
By now, we have made a few checkpoints across two different threads. But what goes into a checkpoint? To inspect a graphβsstate
for a given config at any time, call get_state(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:
- OpenAI
- Anthropic
- Azure
- Google Gemini
- AWS Bedrock