LangMem
LangChain's long-term-memory SDK that lets agents store, search, and update semantic, episodic, and procedural memories outside the prompt window.
Description
LangMem is a Python library from the LangChain team that adds long-term memory primitives to agent applications. Its conceptual guide names three memory types — semantic (facts that ground responses), episodic (successful past interactions used as learning examples), and procedural (how the agent should behave and respond) — and exposes typed extraction, storage, and prompt-optimization APIs over each. LangMem integrates with LangGraph's BaseStore so writes can be managed automatically and surfaced as tools the agent calls directly, rather than only as a sidecar service.
Solution
Library invoked from inside an agent's tool-calling loop, optionally backed by LangGraph's BaseStore. The agent (or a background manager) calls LangMem extractors that classify writes into semantic, episodic, and procedural buckets; semantic and episodic memories are persisted as searchable items, while procedural memory is materialised as updated system-prompt instructions via a prompt-optimizer (metaprompt / gradient / prompt_memory). Retrieved memories are injected back into the next prompt.
Primary use cases
- persistent agent memory across LangGraph runs
- episodic recall of prior successful interactions
- semantic fact stores that agents update over time
- procedural memory for evolving agent system prompts
Open the full interactive page →
Diagram, neighbourhood map, code examples, related patterns and full provenance.