LangMem overview
LangMem is a Python library from LangChain that gives AI agents long-term memory: a model reads a conversation, decides what is worth keeping, and LangMem stores it so a later conversation can find it.
Last updated: 30 Sep, 2026 · LangMem 0.0.30
LangMem is open source under the MIT licence and published on PyPI as langmem. This course uses version 0.0.30, an early release whose API can still change, so every install below pins it. Its README describes three jobs: extract important information from conversations, optimize an agent's behaviour by refining its prompt, and maintain long-term memory. Its functions work with any storage system, and it also integrates natively with LangGraph's store.
A chat model forgets everything when a conversation ends. The next conversation starts from zero, so a support assistant asks a returning customer for their name, their order and their contact preference all over again. LangMem is the layer that carries those facts across conversations.
The three memory types LangMem manages
LangMem's conceptual guide sorts agent memory into three types, borrowed from how human memory is described:
| Memory type | What it holds | Support assistant example | LangMem feature |
|---|---|---|---|
| Semantic | Facts and preferences | Asha prefers email; order A-1001 arrived broken | Memory managers with collections or profiles |
| Episodic | Past experiences, with what worked | Offering a voucher calmed a customer about a late parcel | A memory manager with an episode schema |
| Procedural | How the agent behaves | "Always reply on the channel the customer asked for" | Prompt optimizers that rewrite the system prompt |
Core API and stateful integration
LangMem is built in two layers. The core API is a set of functions with no storage: a memory manager takes a conversation and the memories you already have, and returns the new state; a prompt optimizer takes a prompt and feedback, and returns a better prompt. The stateful layer uses LangGraph's store: a store manager searches, saves and deletes memories for you, and two memory tools let an agent save and search on its own.
Pick one to watch it run, step by step.
Hot path and background memory
Memories can be formed at two moments. In the hot path, the agent calls a memory tool during the conversation, so a memory exists straight away, at the cost of a slower reply. In the background, a separate call reads the conversation after it ends or goes quiet, so the user never waits. The course builds both, then combines them in the final project.
The support assistant this course builds
One example grows through every lesson: a support assistant for an online shop. Asha writes in about order A-1001, which arrived broken, and asks to be emailed. The assistant extracts that, keeps it current when she changes her mind, stores it under her user id, and finds it again in a new conversation days later. The last lesson assembles the whole assistant and shows what it remembers, and what it cannot remember for a customer it has never met.
Models and keys used for every run
Chat calls go to openai/gpt-oss-120b on Groq, and the store's semantic search uses Google's gemini-embedding-2; both have free keys, set up in Installation and setup. Model output changes from run to run, so your replies will be worded differently from the ones shown.
Five lessons play clips from the Agentic Memory module of the AI Security Course video, where semantic, episodic and procedural memory, vector store memory and summary memory are explained. The video builds each one by hand in plain Python; each lesson then shows the LangMem feature that does the same job.
Before you start
- Python 3.10 or later.
- Lists, dictionaries and Pydantic models in Python.
- What a chat model and a tool call are. The LangChain course covers both; the agent lessons use LangChain's
create_agent.
Related
- Next: Installation and setup
- Reference: LangMem documentation
Every expert started right here.