LangChain memory primitives for long-horizon agent workflows.
Memory building blocks for AI agents — lets your AI remember important facts and context across long conversations.
LangMem is an open-source Python library from the LangChain team that provides memory primitives specifically engineered for long-horizon AI agent workflows. While LangChain and LangGraph already handle conversational state within a single session, LangMem extends that with persistent, cross-session memory that allows agents to remember facts, user preferences, prior conversations, and learned procedures across time. It addresses one of the most persistent gaps in production LLM systems: agents that lose context the moment a session ends, forcing users to re-explain themselves on every interaction.
The library offers two main usage patterns. The first is a set of functional, stateless primitives — including memory managers and prompt optimizers — that developers can integrate directly into any LangChain or LangGraph agent. These let an agent extract structured information from a conversation, decide what to write, update, or delete from long-term storage, and reflect on past interactions to improve future ones. The second pattern is a stateful storage-backed API that plugs into LangGraph's BaseStore interface, supporting in-memory, Postgres, or other persistent backends out of the box. This gives developers a clean separation between memory logic (what to remember) and storage (where to keep it).
LangMem distinguishes between several memory types modeled after cognitive science: semantic memory (facts and knowledge about the user or domain), episodic memory (specific past events and conversations), and procedural memory (learned rules, prompts, or behaviors that improve over time). The procedural-memory side is particularly novel — it includes a prompt optimizer that uses agent feedback or evaluation traces to iteratively rewrite an agent's system prompt, effectively letting the agent learn from experience without fine-tuning. Memory operations can be triggered either in the 'hot path' (synchronously during a turn) or in the 'background' (asynchronously after a turn ends), giving developers control over the latency-vs-completeness tradeoff.
LangMem is MIT-licensed and integrates tightly with the broader LangChain ecosystem, including LangGraph for orchestration and LangSmith for observability. It is best suited for teams already building on LangChain who need durable agent memory, chatbots with persistent user profiles, or copilots that improve through use. Because it is a library rather than a managed service, teams are responsible for choosing and operating their own storage backend, designing schemas, and tuning when memories are written and retrieved.
Was this helpful?
LangMem brings memory management directly into the LangGraph ecosystem as a library rather than a separate service. For LangGraph users, this tight integration is valuable — memory operations become graph nodes rather than external API calls. The semantic and episodic memory abstractions are well-designed. However, it's tightly coupled to LangGraph, limiting its usefulness for teams using other frameworks. Being newer, the community and documentation are still developing.
Extracts factual information and user preferences from conversations. Facts are stored as discrete memories with metadata and can be updated or superseded by newer information.
Use Case:
An agent that remembers a user's tech stack, communication preferences, and project context across multiple sessions.
Captures event-based memories from conversations — what happened, when, and the user's reaction. Episodic memories include temporal context and emotional valence.
Use Case:
Remembering that a customer had a frustrating deployment failure last week and bringing up that context when they ask about deployment again.
Extracts behavioral patterns from interactions and creates system prompt modifications. The agent literally learns how to behave better over time by updating its own instructions.
Use Case:
An agent that learns to always ask about the user's Python version when they report library errors, after discovering this is frequently the root cause.
Memories are stored in LangGraph's persistent key-value store with namespace-based organization. Memory operations are LangGraph nodes that participate in graph state management and checkpointing.
Use Case:
Building a customer support graph where memory retrieval and update are explicit nodes that can be modified, monitored, and replayed.
Choose between different memory formation strategies: background processing (asynchronous extraction after conversations), inline processing (real-time extraction during conversations), or batch processing (periodic extraction from accumulated transcripts).
Use Case:
Using background processing for a high-throughput chatbot where memory extraction latency would hurt user experience.
Memories are organized in hierarchical namespaces (e.g., user/preferences, user/projects, global/procedures). Retrieval can scope to specific namespaces for precise context loading.
Use Case:
Retrieving only project-related memories when the user asks about a specific project, without loading unrelated personal preferences.
Free
Variable
Separate LangChain pricing
Ready to get started with LangMem?
View Pricing Options →LangMem works with these platforms and services:
We believe in transparent reviews. Here's what LangMem doesn't handle well:
Weekly insights on the latest AI tools, features, and trends delivered to your inbox.
Through 2025 and into 2026, LangMem matured alongside LangGraph's broader push toward production agent infrastructure. Notable directions include tighter coupling with LangGraph's BaseStore for persistent multi-agent memory, refinements to the prompt optimizer for procedural memory, and improved patterns for background memory formation that decouple memory writes from user-facing latency. The library continues to evolve quickly, so teams adopting it should pin versions and track release notes on the langchain-ai/langmem GitHub repository.
AI Agents
Open-source Python framework for orchestrating role-playing, autonomous AI agents that collaborate as a 'crew' to complete complex tasks.
Multi-Agent Builders
Microsoft's open-source framework for building multi-agent AI systems with asynchronous, event-driven architecture.
AI agent framework
LangGraph is LangChain's open-source framework for building stateful, durable, multi-agent workflows in Python and JavaScript with graph-based control flow.
AI Agent Builders
SDK for building AI agents with planners, memory, and connectors. - Enhanced AI-powered platform providing advanced capabilities for modern development and business workflows. Features comprehensive tooling, integrations, and scalable architecture designed for professional teams and enterprise environments.
No reviews yet. Be the first to share your experience!
Get started with LangMem and see if it's the right fit for your needs.
Get Started →Take our 60-second quiz to get personalized tool recommendations
Find Your Perfect AI Stack →Explore 20 ready-to-deploy AI agent templates for sales, support, dev, research, and operations.
Browse Agent Templates →