Official SDK

LangChain long-term memory

LangChain long-term memory: persistent chat history and a memory store with prompt-ready recall, in Python and Node.js.

Overview

Install langchain-memorysync (Python) or memorysync-langchain (Node.js) to give any LangChain chain or agent durable memory. The chat history class plugs into RunnableWithMessageHistory and keeps each session’s transcript in MemorySync conversation history, apart from the user’s memories; the durable facts in user messages are extracted into memories, and clear() deletes the transcript while those facts stay. A context provider returns prompt-ready recall blocks, and both packages run on langchain-core 0.3.x and 1.x.

Setup status and requirements

Supported version
langchain-memorysync 1.2.0 (PyPI) / memorysync-langchain 1.2.0 (npm)
Last setup review
2026-10-01
Permissions
A MemorySync API key with read and write scopes.
Limits
Requires langchain-core 0.3 or newer (Python 3.10+, Node 18+). History clear() needs a key with delete permission; anonymous evaluation keys can write and read history but cannot clear it.
Open setup documentation →

Capabilities

Quick Start

from langchain_core.runnables.history import RunnableWithMessageHistory
from langchain_memorysync import MemorySyncChatMessageHistory
chain_with_history = RunnableWithMessageHistory(
chain,
lambda session_id: MemorySyncChatMessageHistory(session_id=session_id),
input_messages_key="input",
history_messages_key="history",
)

Use Cases

LangChain chatbots with persistent memory

Assistants that remember users across sessions

Personalised prompts from long-term recall

Guides and related pages

Explore More

Add long-term memory to LangChain

Start free with 10,000 add requests a month and no credit card. Memory is stored per end user and comes back in every later session.