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.1.0.tar.gz (26.9 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.1.0-py3-none-any.whl (33.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: langchain_memorysync-1.1.0.tar.gz
  • Upload date:
  • Size: 26.9 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.1.0.tar.gz
Algorithm Hash digest
SHA256 a8ff0a7f1a56e69a2477a0951935852d88ac99458de8bf20970484fbbf327643
MD5 24f0d5f7f0e5d69deecd0c9a369a4e59
BLAKE2b-256 4565ceb4ad1f5e60667a0b42e47fbd12b6a35c7386c555923a9e92e6e96b2776

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for langchain_memorysync-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9ebe9d77956c283f30dc351758369eedff90f51851a84f25da1da002a919b418
MD5 709fc0c028dfa44e3f3214ccff477d41
BLAKE2b-256 ae57dfc205d57ba89ec3374b70320fbb7f49bf8bab6290d13fadf302f6153534

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 files

1.0.1

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