Skip to main content

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

langchain_memorysync-1.0.1.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_memorysync-1.0.1-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

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

Hashes for langchain_memorysync-1.0.1.tar.gz
Algorithm Hash digest
SHA256 2362dbd66e92233c239718f18e388b62332021e2ce05531530a98b264f00539c
MD5 4d7e0bcc177725f5c878dd0addf6821f
BLAKE2b-256 49d3c914eee903eacca5ea06cc2db77bbfbab49a0617fb16ea1271f013eaacc9

See more details on using hashes here.

File details

Details for the file langchain_memorysync-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_memorysync-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c6021fa9d453c9f04e98ded1c6bef1e0ca4f698c2fd7b4b428c22014012b7270
MD5 0cbb02cbbebbc82c100bbc38eb89362c
BLAKE2b-256 a1a769700e767f89a7beb49331d622ae6d86f70736b18166b843a50d8e6ad326

See more details on using hashes here.

Release history Release notifications | RSS feed

1.1.0

2 files

This release

1.0.1 This release

2 files

1.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page