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.0.tar.gz (14.2 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.0-py3-none-any.whl (17.0 kB view details)

Uploaded Python 3

File details

Details for the file langchain_memorysync-1.0.0.tar.gz.

File metadata

  • Download URL: langchain_memorysync-1.0.0.tar.gz
  • Upload date:
  • Size: 14.2 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.0.tar.gz
Algorithm Hash digest
SHA256 6c054202b216dc684e5cc135063d560d3c794fac3f7ca4fc8f8f202607b97c94
MD5 f2d68cc065d1139ef785025155275880
BLAKE2b-256 fb3da91682f454ac867514703f12636693dc20745bca89f724542d5ab49d31d6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for langchain_memorysync-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c511bcf20c5caa5d7c330a7f0839081d6077bacc2dec3886765ef7f71c381afb
MD5 081420be37ac1f0249ff56d562b20af2
BLAKE2b-256 25657439108a5d38850ec7d7771231b9a0942f6282c89bb798a68c4cae12c594

See more details on using hashes here.

Release history Release notifications | RSS feed

1.1.0

2 files

1.0.1

2 files

This release

1.0.0 This release

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