LangMem
A Python library from LangChain that has an AI pull memories out of conversations and keep them up to date in LangGraph's store.
by LangChain · Built this? Edit this page on GitHub
In short
LangMem is a set of building blocks for adding long-term memory to an AI agent. After a conversation, a memory manager has an AI read it next to the few saved memories that look closest, and decide what to add, rewrite or remove. You choose what a memory looks like: free text, a typed record, or a single profile per user that gets patched in place. The memories are kept in LangGraph's store, which also does the searching. You can run the manager in the conversation, give the agent tools to save and search memories itself, or have it wait until a conversation goes quiet. A separate prompt optimizer rewrites an agent's instructions from past conversations and feedback.
Who it’s for
Python developers building agents with LangGraph or LangChain who want memory without writing the extraction prompts themselves. The core manager works without a store, so it can sit in other frameworks too.
What it remembers
Whatever you set it up to keep: facts and preferences about users, a profile per user, examples of interactions that went well, and the agent's own instructions (rewritten by the optimizer).
- Memory lives
- LangGraph's store (in memory, Postgres, or LangGraph Platform)
- API keys
- An AI model key, plus an embedding model for search
- Works with
- LangGraph, LangChain, LangGraph Platform, Any LangGraph app (through its memory tools)
- License
- Open sourceMIT
- Price
- Free
Under the hood
- Who writes memories
- An AI call reads the conversation with the closest saved memories and adds, rewrites or removes them. Or the agent saves memories itself through a tool, as it talks.
- Where they're kept
- LangGraph's store, as small JSON records grouped by namespaces such as a user ID. LangMem keeps nothing of its own.
- How they're found
- The store's vector search, with embeddings you configure. The manager can also have an AI write the search queries.
- Extra AI calls
- Yes: each manager run is an AI call of one or more steps, plus embeddings; an optional query writer and extra passes add more. The prompt optimizer takes 1 to 10 calls a run.
How it works
- 1A conversationYour agent talks; it can also save memories through a tool.
- 2Wait for quietOptionally, the run waits a set time and restarts if new messages arrive.
- 3Find the nearestLangGraph's store finds the saved memories closest to the conversation.
- 4UpdateAn AI adds, rewrites or removes memories, and the store saves them.
- 5SearchNext time, the agent or your code searches the store.
What stands out
- One manager handles the whole update: in a single pass an AI adds new memories, rewrites old ones and, if you allow it, removes the wrong ones.
- Memories can be shaped with your own Pydantic types, including one profile per user that is updated rather than added to.
- A debounced background run: memory work waits until a conversation goes quiet, and restarts if new messages arrive.
- A prompt optimizer that treats an agent's instructions as memory, and rewrites them from past conversations and feedback.
What it doesn’t do
- The latest version on PyPI is 0.0.30, from October 2025, so it has had no new release in a year.
- It doesn't store or search anything itself. That's LangGraph's store, which you set up, with an embedding model for search.
- A rewritten memory replaces the old one under the same key, and a removed one is deleted. No history of what a memory used to say is kept.
- Nothing fades and using a memory doesn't strengthen it. The concept guide says recall should weigh importance and recent use, but the code ranks by similarity only.
- No links between memories, no reminders that come back on their own, and no emotional weighting.
- Nothing runs on a schedule over the whole store. Each run touches only the handful of memories that match the latest conversation.
Measured against human memory
0 built, 6 partly, 5 not of the Field Guide’s 11 mechanisms
Encoding
Salience
Decides what's worth keeping, and how much, as a memory is written.
An AI decides what to keep, told to favour surprising and often repeated information and to mark uncertain things with a confidence. You can replace the instructions. There's no importance score. source
Emotion
Gives memories written with feeling more weight.
No emotional weighting. Nothing in the code reads or records feeling.
Storage
Forgetting
Lets unused memories fade over time on its own.
Nothing fades. Memories stay until an AI or your code removes them; an expiry time is a feature of LangGraph's store that LangMem's managers don't use.
Interference
When a new memory closely matches an old one, notices and lets the newer one win.
Before writing, the manager fetches the memories closest to the conversation, and an AI may rewrite or remove ones the conversation contradicts. That's the AI's judgement as it edits; no rule says the newer wins. source
Retrieval
Retrieval
Remembering something makes that memory stronger.
Being found doesn't strengthen a memory. Search ranks by similarity only, though the concept guide says recall should weigh use.
Association
Links memories, so recalling one brings its neighbours.
Memories aren't linked to each other. Namespaces group them, but nothing connects one memory to another.
Prospective
Brings a memory back at the right time without being asked.
Nothing comes back on its own. Your agent searches when it chooses to, or your code fetches memories each turn.
Transformation
Consolidation
Reworks memories between sessions: strengthening, merging, reorganising.
After a conversation, or once it has been quiet for a delay you set, an AI merges, rewrites and, if you allow it, removes the few memories that match it. It never reworks the whole store, and nothing runs without a new conversation. source
Reconsolidation
Corrects a memory when it's contradicted, and keeps what it used to say.
An AI or the agent can correct a memory, but the new text overwrites the old under the same key, and a removal deletes it. What it used to say isn't kept. source
Gist
Turns many specific moments into general knowledge.
The prompt optimizer turns batches of past conversations and feedback into general rules in the agent's instructions. You run it and keep the result, and nothing checks the rules later. source
Schemas
Forms beliefs about people and projects, and weighs new facts against them.
You can keep one profile per user (name, preferences, and whatever fields you define) that an AI updates in place as conversations arrive. New facts aren't weighed against it. source
Not every system is trying to be a human memory, so a hollow dot isn’t a flaw. It just says what the system doesn’t do. What the mechanisms are.
LangMem’s makers haven’t shared what they’re building next, so only today shows here. Makers can add their roadmap the same way they correct an entry.
Compare LangMem with the others, side by sideQuestions
- Who is LangMem for?
Python developers building agents with LangGraph or LangChain who want memory without writing the extraction prompts themselves. The core manager works without a store, so it can sit in other frameworks too.
- Where does LangMem keep its memories?
LangGraph's store (in memory, Postgres, or LangGraph Platform). LangGraph's store, as small JSON records grouped by namespaces such as a user ID. LangMem keeps nothing of its own.
- Does LangMem forget?
Forgetting: not built. Nothing fades. Memories stay until an AI or your code removes them; an expiry time is a feature of LangGraph's store that LangMem's managers don't use.
- Does LangMem correct a memory when it turns out to be wrong?
Reconsolidation: a little. An AI or the agent can correct a memory, but the new text overwrites the old under the same key, and a removal deletes it. What it used to say isn't kept. source
- Is LangMem open source?
Yes, it's open source. License: MIT. Code: github.com/langchain-ai/langmem.
- Does LangMem need an API key?
API keys: An AI model key, plus an embedding model for search.
- How much does LangMem cost?
Price: Free.