█

AI/TLDR

Buy me a coffee
Buy me a coffee

LangMem

Long-term memory tools for LangGraph agents that learn from every conversation

Agent MemoryOpen source
Language
Python
$pip install -U langmem
IN SHORT

What is LangMem?

LangMem is a memory SDK from the LangChain team that helps agents remember information across conversations. It gives you tools to pull important details out of a chat, store them, and search them later, so an agent can personalize its replies and stay consistent between sessions. It sits in the Agent Memory category of the Agents & Automation tools and is open-source, written in Python.

Overview

LangMem is a memory SDK from the LangChain team that helps agents remember information across conversations. It gives you tools to pull important details out of a chat, store them, and search them later, so an agent can personalize its replies and stay consistent between sessions.

It is aimed at developers building agents who need long-term memory rather than a fresh start on every request. You can use its core memory API with any storage system, or rely on its built-in integration with LangGraph's long-term memory store.

Within the agent-memory space, LangMem sits as a memory framework. It supports both "hot path" memory (tools the agent calls during a conversation) and background memory management that extracts and consolidates knowledge automatically.

What it does

  • Core memory API that works with any storage backend, not just LangGraph
  • Memory management tools (create_manage_memory_tool, create_search_memory_tool) agents call during a conversation
  • Background memory manager that extracts, consolidates, and updates knowledge automatically
  • Native integration with LangGraph's long-term memory store, available in LangGraph Platform deployments
  • Prompt-refinement tooling to optimize agent behavior over time

Getting started

Install LangMem with pip, set an LLM provider API key, then wire its memory tools into a LangGraph agent.

Install LangMem

Install the package from PyPI.

bashbash
pip install -U langmem

Set your LLM API key

Configure an API key for a supported LLM provider in your environment.

bashbash
export ANTHROPIC_API_KEY="sk-..."  # Or another supported LLM provider

Create an agent with memory

Add the manage- and search-memory tools to a LangGraph react agent backed by a store.

pythonpython
from langgraph.prebuilt import create_react_agent
from langgraph.store.memory import InMemoryStore
from langmem import create_manage_memory_tool, create_search_memory_tool

store = InMemoryStore(
    index={
        "dims": 1536,
        "embed": "openai:text-embedding-3-small",
    }
)

agent = create_react_agent(
    "anthropic:claude-3-5-sonnet-latest",
    tools=[
        create_manage_memory_tool(namespace=("memories",)),
        create_search_memory_tool(namespace=("memories",)),
    ],
    store=store,
)

Store and recall a memory

Chat normally; the agent decides what to store and searches its memory when asked.

pythonpython
agent.invoke(
    {"messages": [{"role": "user", "content": "Remember that I prefer dark mode."}]}
)

response = agent.invoke(
    {"messages": [{"role": "user", "content": "What are my lighting preferences?"}]}
)
print(response["messages"][-1].content)

Commands and code are distilled from the project's own documentation — always check the official repo for the latest.

When to use it

  • Give a chat agent persistent memory of a user's preferences across separate sessions
  • Let an agent record and search facts in the hot path during an ongoing conversation
  • Run a background process that consolidates and updates an agent's knowledge over time
  • Add long-term memory to an existing LangGraph application using its storage layer

How LangMem compares

LangMem alongside other open-source agent memory tools AI/TLDR tracks, ranked by GitHub stars.

ToolStarsWhat it does
Claude-Mem★ 121kPersistent memory layer for coding agents: it captures what an agent does during a session, compresses it into semantic summaries, and injects the relevant parts back into later sessions.
Mem0★ 69.7kA memory layer that you add to existing LLM agents to extract, store, and recall user facts and preferences across sessions using vector, graph, and key-value backends.
Hindsight★ 64.3kAn agent memory server that stores facts and experiences, consolidates them into observations and mental models, and serves them back through retain, recall, and reflect operations.
MemPalace★ 60.8kLocal-first agent memory that stores conversations verbatim instead of summarising them, with a structured palace index, pluggable vector backends and an MCP server.
OpenViking★ 43.1kA context database that stores an agent's memories, resources, and skills as one browsable viking:// filesystem with three-tier (abstract/overview/details) on-demand loading.
Cognee★ 33.7kA graph-native memory engine that turns raw documents and conversations into a queryable knowledge graph for agents that need to build lasting knowledge.
Graphiti★ 33.2kA library that builds a temporal knowledge graph from an agent's conversations and data so facts can be tracked and queried as they change over time.
LangMem★ 1.8kLong-term memory tools for LangGraph agents that learn from every conversation