Master LangMem with our step-by-step tutorial, detailed feature walkthrough, and expert tips.
Install the library with `pip install langmem` and configure your LLM provider credentials (e.g., OpenAI API key). Set up a LangGraph BaseStore backend — use InMemoryStore for development or PostgresStore for production persistence. Add a memory manager to your LangGraph agent graph to extract semantic or episodic memories from conversations. Configure memory namespaces (e.g., user/preferences, user/facts) and wire memory retrieval into your agent's prompt assembly. Optionally enable background memory formation and the prompt optimizer for procedural memory that improves your agent over time.
💡 Quick Start: Follow these 1 steps in order to get up and running with LangMem quickly.
Explore the key features that make LangMem powerful for ai memory & search workflows.
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.
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.
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.
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.
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).
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.
Retrieving only project-related memories when the user asks about a specific project, without loading unrelated personal preferences.
LangMem is a library of memory primitives for long-term, cross-session agent memory. LangChain's classic memory modules track state within a single conversation, while LangMem focuses on persistent semantic, episodic, and procedural memory that survives across sessions and lets agents learn from past interactions.
No. LangMem provides stateless functional primitives (memory managers, prompt optimizers) that can be used with any LangChain agent or even standalone. However, its stateful storage-backed API is built on LangGraph's BaseStore, so deeper integration is easiest inside a LangGraph application.
LangMem works with any backend that implements LangGraph's BaseStore interface. This includes the in-memory store for development and Postgres for production, with the option to plug in custom stores for other databases or vector stores.
The prompt optimizer is a procedural-memory primitive that takes an agent's existing system prompt plus signals from past runs (such as user feedback or evaluation traces) and rewrites the prompt to improve future performance. This lets agents adapt their behavior over time without retraining or fine-tuning the underlying model.
Yes. LangMem is open-source under the MIT license, so it can be used commercially at no cost. Operational costs come from the underlying LLM calls used to extract and manage memories and from whatever storage backend you choose to run.
Now that you know how to use LangMem, it's time to put this knowledge into practice.
Sign up and follow the tutorial steps
Check pros, cons, and user feedback
See how it stacks against alternatives
Follow our tutorial and master this powerful ai memory & search tool in minutes.
Tutorial updated March 2026