LangMem

RAG & Memory 💻 Python ⚖️ MIT 🟢 Actively maintained
1.6k stars

LangMem is a Python library that helps AI agents learn and adapt from interactions over time by extracting information, refining prompts, and maintaining long-term memory. It provides tools for memory management that work with any storage system and integrates natively with LangGraph's storage layer. It is for developers building agents that need persistent, evolving memory across sessions.

✨ Key features

  • Core memory API compatible with any storage system
  • Memory management tools for agents to record and search information
  • Background memory manager for automatic extraction and consolidation
  • Native integration with LangGraph's Long-term Memory Store
  • Works with LangGraph's create_react_agent for quick setup

🎯 Use cases

  • Build agents that remember user preferences across conversations
  • Create chatbots that personalize responses based on past interactions
  • Implement memory management in existing LangGraph agents
  • Automatically extract and consolidate knowledge from conversations in the background

📦 Installation

🧰 Requirements: Python environment with pip; API key for a supported LLM provider (e.g., Anthropic, OpenAI).

pip install -U langmem

Configure your environment with an API key for your favorite LLM provider:

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

🚀 Usage

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,
)

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)

⚠️ Good to know

InMemoryStore keeps memories in process memory and will be lost on restart; for production, use a DB-backed store like AsyncPostgresStore.

❓ FAQ

What storage systems does LangMem support?

LangMem's core memory API works with any storage system, and it has native integration with LangGraph's Long-term Memory Store, including InMemoryStore and AsyncPostgresStore.

How do I persist memories across server restarts?

Use a DB-backed store like AsyncPostgresStore instead of InMemoryStore, which is only in-memory and loses data on restart.

Can I use LangMem without LangGraph?

Yes, the memory tools work in any LangGraph app, but you can also build custom memory systems without agents using the functional primitives.

How does the agent decide what to remember?

The agent uses the memory tools (create_manage_memory_tool and create_search_memory_tool) to decide what and when to store, and it can search past interactions when needed.

📊 Repository

Stars★ 1,646
Forks🍴 186
Open issues🐛 65
Last commit🕒 Sep 4, 2026
Created📅 Jan 2025
Language💻 Python
License⚖️ MIT

🤖 Overview, features, install steps and FAQ were generated from the project's README on Sep 4, 2026. Always check the original source before running commands.