langchain-memorysync
MemorySync integration for LangChain: persistent chat message history, structured memory tools for agents, and prompt-ready recall context. Works with langchain-core 0.3.x and 1.x.
pip install langchain-memorysync
Set MEMORYSYNC_API_KEY (create a key at memorysync.io,
or run npx memorysync-cli init).
Chat message history
MemorySyncChatMessageHistory implements BaseChatMessageHistory, so it plugs
straight into RunnableWithMessageHistory:
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",
)
chain_with_history.invoke(
{"input": "My name is Ada."},
config={"configurable": {"session_id": "thread-42"}},
)
Turns are stored verbatim through MemorySync's episodic ingestion — no extraction gates, so short turns like "yes" survive — and the full LangChain message (tool calls, additional kwargs) is serialised into metadata for exact reconstruction. Writes are idempotent: a retried write is recognised, never duplicated.
history = MemorySyncChatMessageHistory(
session_id="thread-42",
user_id="customer-7", # share memory across a user's sessions
max_messages=30, # cap the transcript tail handed to the LLM
)
Agent tools
from langchain.agents import create_agent
from langchain_memorysync import create_memorysync_tools
tools = create_memorysync_tools(end_user_id="customer-7")
agent = create_agent(model, tools=tools)
Returns add_memory, search_memory, list_memories, update_memory, and
delete_memory. Tools return readable strings and never raise, so a memory
failure cannot abort an agent run. Pass read_only=True to hand an agent only
search_memory and list_memories.
add_memory derives an idempotency key from the content — an agent that
repeats itself gets "already stored", not a duplicate.
Recall context
from langchain_memorysync import MemorySyncContextProvider
provider = MemorySyncContextProvider(user_id="customer-7")
context = provider.get_context("What should I cook tonight?")
Returns a grouped, type-labelled context block built by MemorySync's hierarchical retrieval, ready to inject into a system prompt. Empty string — not an exception — when the user has no relevant memories yet.
Documentation
Full guide: docs.memorysync.io/integrations/langchain
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_memorysync-1.0.1.tar.gz.
File metadata
- Download URL: langchain_memorysync-1.0.1.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2362dbd66e92233c239718f18e388b62332021e2ce05531530a98b264f00539c
|
|
| MD5 |
4d7e0bcc177725f5c878dd0addf6821f
|
|
| BLAKE2b-256 |
49d3c914eee903eacca5ea06cc2db77bbfbab49a0617fb16ea1271f013eaacc9
|
File details
Details for the file langchain_memorysync-1.0.1-py3-none-any.whl.
File metadata
- Download URL: langchain_memorysync-1.0.1-py3-none-any.whl
- Upload date:
- Size: 18.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6021fa9d453c9f04e98ded1c6bef1e0ca4f698c2fd7b4b428c22014012b7270
|
|
| MD5 |
0cbb02cbbebbc82c100bbc38eb89362c
|
|
| BLAKE2b-256 |
a1a769700e767f89a7beb49331d622ae6d86f70736b18166b843a50d8e6ad326
|