Get startedGet started for free

Memory and checkpointing in LangGraph

1. Memory and checkpointing in LangGraph

Time to put the finishing touches on your agent: let's talk about memory!

2. Never forget memory!

For AI agents to have effective, coherent conversations with their users , they need memory. Without it, every conversation or task starts from scratch — like talking to someone with no recall of your last meeting.

3. Long-term vs. short-term memory

In AI agents, memory generally falls into two categories: short-term and long-term. Short-term memory is like a scratchpad—it holds context only while a task or conversation is happening. Long-term memory is stored knowledge, such as user preferences or specific insights, that can be recalled later—even across different sessions. Here's the challenge: short-term memory disappears after every agent invocation. That means agents can't resume their conversations where they left off unless we deliberately save that state.

4. Memory in LangChain

LangChain solves this with checkpoints and threads. A checkpoint is like a save state in a video game—it captures the agent's state at a single moment in time. A thread is like the storyline in the video game—each thread can have many checkpoints, so we can pause, resume, or even branch off into new directions. By default, checkpoints live only in-memory, like in your previous implementation, but we can store them for later use.

5. Remembering memory

We'll be persisting this short-term memory across runs by saving the checkpoints in a MongoDB database with the MongoDBSaver class. This means short-term memory won't vanish when the process ends — it survives and can be resumed anytime. It's important to note that MongoDBSaver isn't a long-term memory strategy. It doesn't extract specific insights from conversations for long-term use — it only makes the short-term state durable across runs.

6. Remembering memory

While we won't be implementing this in the course, you can check out the MongoDBStore class in LangGraph instead, to persist long-term memory for the agent in MongoDB.

7. Summary

To wrap up: short-term memory keeps agents coherent in the moment, but usually disappears. LangGraph saves it with checkpoints and threads, and MongoDB makes those saves durable. That way, your agent can pick up right where it left off.

8. Let's practice!

Time to give this a go!

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.