Full-Code · Memory Storesactive

LangMem

Type: full-code  ·  Vendor: LangChain  ·  Language: Python  ·  License: MIT  ·  Status: active  ·  Status in practice: emerging

Links: homepage docs repo

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.

Agent loop shape. 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

Key concepts

  • Semantic memory semantic-memory (docs)Facts and relationships that ground the agent's responses; extracted from conversations.
  • Episodic memory episodic-memory (docs)Successful past interactions kept as learning examples that guide future behavior.
  • Procedural memory procedural-memory (docs)How the agent should behave and respond; materialised by updating the system prompt via an optimizer.
  • Prompt optimizer (metaprompt / gradient / prompt_memory) (docs)Three optimizer strategies that update system prompts from past conversations and feedback.
  • LangGraph BaseStore integration (docs)Backing store used to persist extracted memories automatically across agent runs.

Patterns this full-code implements