Powering Long-Term Memory for Agents With LangGraph and MongoDB

Prakul Agarwal and Thibaut Gourdel

We're excited to introduce the MongoDB Store for LangGraph—a powerful integration that brings flexible and scalable long-term memory to AI agents. This new integration between MongoDB and LangGraph, LangChain’s open-source agent orchestration framework, allows agents to remember and build on previous interactions across multiple sessions instead of only retaining memory for the current session. The result is more intelligent, context-aware agentic systems that learn and improve over time.

This new integration complements MongoDB’s existing checkpointer integration, which handles short-term memory and persistent conversation history. Together, the MongoDB Store for LangGraph and MongoDB’s support for checkpointers provide a complete solution for building production-ready, memory-enabled agents.

The need for agent memory

An AI agent is a system designed to take actions or make decisions based on input, often using tools and reasoning to complete tasks. By default, agents don’t retain memory between conversations, which severely constrains what they can accomplish.

Agent memory (and memory management) is a computational exocortex for AI agents. It is a dynamic, systematic process that integrates an agent’s large language model (LLM) memory (context window and parametric weights) with a persistent memory management system to encode, store, retrieve, and synthesize knowledge and experiences.

Agent memory is typically divided into two main types: short-term memory and long-term memory. In a memory context, LangGraph uses “threads” to represent individual conversations or sessions. Short-term memory, managed through thread-scoped checkpointers that MongoDB supports, maintains context within a given session. While this preserves conversation continuity and manages history, it doesn’t help agents learn continuously from the past across different conversations to adapt and optimize their behavior over time. This is why we introduced the MongoDB Store for LangGraph, enabling your agents to retain memories across conversations through a cross-thread memory store.

Figure 1. Short and long-term memory integration between LangGraph and MongoDB.
The top left of this diagram is the AI agent, which sends and receives data from MongoDB Atlas with two lines titled shared across threads and thread-level context. Atlas contains Stores Optimized Search, Checkpointers, and TTL Indexes. The bottom of the diagram has a line that shows langGraph + langgraph-checkpoint-mongodb + langgraph-store-mongodb.

MongoDB Store: Enabling cross-thread long-term memory

The new langgraph-store-mongodb package introduces a MongoDBStore class. Available now through PyPI, this production-ready integration provides:

  • Cross-thread persistence: Store and recall information across different conversation sessions and user interactions, allowing agents to build on previous knowledge.

  • Native JSON structure: LangGraph stores long-term memories as JSON documents, which map directly to MongoDB documents. Each memory is organized using namespaces and a key-value structure. This enables the usage of MongoDB’s native and optimized data formats and search capabilities for efficient retrieval.

  • Vector Search capabilities: Leverage MongoDB Atlas Vector Search for semantic memory retrieval based on meaning, not just keyword matching.

  • Asynchronous support: Support for both synchronous and asynchronous operations for high-performance applications.

  • Automatic connection management: Robust connection pooling and error handling to ensure reliability.

  • Optimized TTL indexes: MongoDB’s Time-to-Live (TTL) indexes are integrated with LangGraph’s TTL system, allowing automatic removal of stale or outdated data. This improves retrieval performance, reduces storage costs, and ensures the system "forgets" obsolete memories efficiently.

Ready to give your AI agents persistent long-term memory? The langgraph-store-mongodb package is available now:

pip install langgraph-store-mongodb

The MongoDB Store for LangGraph enables developers to build more powerful agents for different use cases, including:

  • Customer support agents: Build agents that remember customer preferences, past issues, and resolution patterns across multiple support channels.

  • Personal assistant applications: Build agents that learn user habits and preferences to provide increasingly personalized experiences.

  • Enterprise knowledge management: Create agents that accumulate organizational knowledge and can retrieve relevant information semantically.

  • Multi-agent systems: Enable agent teams to share learned experiences and coordinate through persistent memory.

Why MongoDB for agent memory?

Effective agentic memory requires comprehensive mechanisms for storing, retrieving, updating, and deleting memories. MongoDB Atlas provides a unified database that meets all these complex requirements:

  • Flexible document model: Store complex, nested memories as rich JSON, matching how agents naturally read, organize, and update evolving information.

  • Semantic search: Native vector search enables retrieval by meaning, not just exact matches.

  • State-of-the-art models: Voyage AI provides embedding models and rerankers for cutting-edge memory retrieval.

  • Scalable architecture: Distributed architecture, workload isolation, autoscaling, and automatic sharding capabilities for scaling AI agent memory.

  • Enterprise security: Fine-grained role-based access control (RBAC) allows precise management of both access scope (specific services or databases) and access type (read-only or read-write).

MongoDB Atlas and LangChain: A complete solution for AI agent memory

Short-term memory provides an agent with immediate context, current conversation state, prior exchanges within that session, or shared memory for coordination in multi-agent systems. The most common form of short-term memory is working memory—an active, temporary context accessible during a session. MongoDB's integration with LangGraph checkpointers supports this by persisting and restoring conversation states.

Other short-term memory implementations include semantic caches, such as using MongoDB's semantic cache integration with LangChain, which stores recent prompts and LLM responses for retrieval when similar queries occur. Shared memory is also used in multi-agent systems to provide a common space for coordination and information sharing.

Long-term memory serves as the agent’s knowledge base, storing diverse kinds of information for future use. It includes several functional types, each requiring specific storage and retrieval strategies:

  • Episodic memory: captures specific events and interactions, such as conversation history or summaries of key occurrences with metadata (e.g., timestamps, participants). For instance, a customer support agent can use this to recall a user’s past issues and offer personalized responses.

  • Procedural memory: records instructions or rules for recurring tasks. A typical implementation is a social content generator agent that remembers past feedback on writing style and formatting to improve its process.

  • Semantic memory: remembers general knowledge, facts, and concepts. This is often implemented through retrieval-augmented generation (RAG), where data is stored as vector embeddings and retrieved based on semantic similarity.

  • Associative memory: stores key entities and relationships between different pieces of information, enabling an agent to identify patterns and make inferences by navigating these connections. It's often implemented using graph structures that support efficient exploration of relationships. One practical approach is GraphRAG.

The MongoDB Store for LangGraph supports these memory types through flexible filtering and semantic search, making it a versatile approach for building reliable long-term memory in agents.

LangChain also provides LangMem, a toolkit featuring pre-built tools designed specifically for extracting and managing procedural, episodic, and semantic memories. LangMem integrates natively with LangGraph, streamlining the memory engineering process. For developers seeking a straightforward approach to using various memory types with MongoDB, explore this comprehensive tutorial for implementing MongoDB alongside LangGraph and LangMem.

The future of intelligent agents

With the new MongoDB Store for LangGraph, we're enabling developers to build AI agents that can learn and adapt. Agents that remember user preferences, learn from mistakes, and build knowledge over time will transform how we interact with AI systems.

The combination of LangGraph's sophisticated orchestration capabilities with MongoDB's flexible, scalable storage creates unprecedented opportunities for building intelligent, persistent AI agents that feel truly alive and responsive.

Ready to build memory-enabled agents with LangGraph and MongoDB Atlas? Get started with the documentation.