Menu

Give Your LangGraph Agent a Memory That Survives Restarts
📰

Give Your LangGraph Agent a Memory That Survives Restarts

DEV Community: mongodb·Satyam Yadav·about 12 hours ago
#lRn4O9kA
#devtomongodb#devto#dev#mongodb#store
Reading 0:00
15s threshold

Short-term memory with MongoDBSaver, long-term memory with MongoDBStore and Atlas Vector Search, in one small Python script.

Most agent demos have the memory of a goldfish. Restart the process and the conversation is gone. Open a new chat and the agent has no idea you told it your preferences yesterday.

In LangGraph this is not a model problem, it is a storage problem. The framework already has two clean slots for memory: a checkpointer and a store. You just have to plug something durable into them. In this post I wire both to MongoDB Atlas, so one database holds the conversation state and the facts the agent learns about each user.

Two kinds of memory, one database

LangGraph splits memory into two jobs:

Short-term memory lives inside a thread (one conversation). The checkpointer saves the full graph state after every step, so a thread can resume after a crash or a redeploy. MongoDBSaver from langgraph-checkpoint-mongodb does this.

Long-term memory lives across threads.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.