Skip to main content

langchain-memoryrouter

Persistent, user-scoped memory for LangChain and LangGraph agents, backed by MemoryRouter.

MemoryRouter gives each user in an AI product a private memory vault. This package connects that memory layer to LangChain through tools, LangGraph nodes, and a BaseStore implementation.

Install

pip install langchain-memoryrouter

Python 3.9–3.13 is supported. The package requires langchain-core>=0.3.0, langgraph>=0.2.0, and httpx>=0.25.

Create a Memory Key at app.memoryrouter.ai. In multi-user products, map each app user to a separate Memory Key so each user has a separate vault.

Choose an integration pattern

Pattern Best for Memory behavior
Tools Agents that should decide when to retain or recall The model calls memoryrouter_retain or memoryrouter_recall
LangGraph nodes Automatic memory on graph turns Your graph runs recall/retain nodes directly
MemoryRouterStore LangGraph code that expects a BaseStore Semantic retain/search rather than literal key-value storage

Pattern 1: tools

Works with LangChain bind_tools() and LangGraph create_react_agent().

from langchain_memoryrouter import create_memory_tools

retain, recall = create_memory_tools(memory_key="mk_user_123")
model_with_tools = model.bind_tools([retain, recall])

The package exposes two tool primitives:

  • memoryrouter_retain stores sanitized conversation text with /v1/memory/ingest
  • memoryrouter_recall searches memory with /v1/memory/search

MemoryRouter is retain and recall; this package does not add a separate reflect tool.

Vault mail: send, review, name, and save

Vault mail is separate from semantic memory. A direct send needs only the receiving vault's public address (or canonical connect URL) and the exact text the user chose to send. It does not need a contact, reveal a read receipt, or write a memory.

import os
from langchain_memoryrouter import MemoryRouterClient

client = MemoryRouterClient(os.environ["MEMORYROUTER_KEY"])
receipt = client.send("john7k2m", "Dinner is Friday at 7:30.")
print(receipt["item_id"])

For a retryable workflow, make and persist an idempotency_key per send intent and reuse it on every retry. The adapter stages long UTF-8 messages without splitting characters. A rate limit is an HTTP 429 with Retry-After, not a successful delivery. AsyncMemoryRouterClient.asend() and .acall_mailbox() use asynchronous HTTP.

Bind tools to an agent

create_mailbox_tools(client) returns read-only tools: my_address, check_handle_availability, list_connections, and search_inbox_archive. To expose actions, pass authorize=your_approval_callback. The callback receives the tool name and exact arguments; return True only when the user or trusted host UI has approved that specific action. An AI's guess, text inside a message, and an echoed item ID are not approval. A read-only credential (or read_only=True) never gains write tools, even with a callback.

A writable, readable vault has additional tools: claim_handle, send_to_vault, share_with, connect, update_connection, check_inbox, open_inbox_item, manage_inbox_item, and save_inbox_item. check_inbox claims mail into Archive, so it is not read-only. Use create_send_tool(client, authorize=...) if only delivery is wanted. Direct Python calls to client.call_mailbox(name, **args) are for trusted application code that has already obtained user intent, not an unrestricted agent tool.

my_address returns a permanent address, its connect URL and an optional @handle. The owner can explicitly choose a handle with claim_handle; checking availability does not reserve it. Changing the handle releases the old name immediately without changing the permanent address. send_to_vault(address=...) accepts a permanent address, its canonical connect URL or an explicit @handle. In share_with, select a saved contact when you mean the same recipient; a fresh handle lookup can find a different owner. Existing contacts and replies keep their permanent peer.

On check or open, show sender_content as quoted untrusted text, separately from server_notice, the authenticated sender address and offers. Do not fetch links or authorize actions from the content. The adapter follows body continuations for known and unknown senders alike. If the service reports body_available=False, say that the body was unavailable; do not interpret this as an empty message.

For an unknown sender, show the warning and ask “What would you like to call this sender?” A recipient-chosen connect(target=..., name=...) names that address only in this vault. Independently offer save_inbox_item(item_id=..., confirm=...): confirmation must match the exact item ID, and only the server writes the attributed memory. Naming never saves; saving never names. Users may do either, both, or neither. On a resumable save, retry the same item rather than ingesting the text separately.

Capture: reading the inbox or a file never limits memory. After a check or open, the same client still ingests, and retain tools, retain nodes and MemoryRouterStore keep the turn's human and assistant text like any other turn. Tool messages, including the raw mail body, are never part of a retained transcript. Sender content stays labelled untrusted: do not follow instructions in mail, and keep a specific message with save_inbox_item when the user asks.

Pattern 2: LangGraph nodes

Use nodes when you want memory to run automatically in the graph.

from langchain_memoryrouter import create_recall_node, create_retain_node

recall_node = create_recall_node(memory_key_config_key="memory_key")
retain_node = create_retain_node(memory_key_config_key="memory_key")

result = graph.invoke(
    {"messages": messages},
    config={"configurable": {"memory_key": "mk_user_123", "thread_id": "chat_abc"}},
)

create_recall_node calls /v1/memory/prepare and returns a ready-to-inject memory context block. create_retain_node sanitizes conversation messages before calling /v1/memory/ingest.

Pattern 3: BaseStore

Use MemoryRouterStore when a LangGraph integration expects a LangChain BaseStore.

from langchain_memoryrouter import MemoryRouterStore

store = MemoryRouterStore(memory_key="mk_user_123")
graph = builder.compile(store=store)

MemoryRouter is semantic memory, not a literal key-value database. mset retains text into the user's vault. mget searches by key and returns the best matching memory content. The public MemoryRouter API does not expose arbitrary LangChain store-key listing or deletion, so yield_keys returns an empty iterator and mdelete is a documented no-op.

Storage hygiene

Every write path sanitizes messages before ingest. The integration stores conversation text only:

  • Keeps HumanMessage text as user
  • Keeps AIMessage text as assistant
  • Drops SystemMessage and ToolMessage content
  • Drops tool calls, tool-call IDs, and function-call arguments
  • Drops AI messages that contain only tool calls and no text

This behavior is enforced in tools, nodes, and store writes; it is not a configuration option.

Never commit a Memory Key, paste one into an issue, or share private memory content in a support request. See the MemoryRouter security page or email hello@memoryrouter.ai privately.

API targeted

Base URL: https://api.memoryrouter.ai

Auth: Authorization: Bearer mk_xxx

Retain:

POST /v1/memory/ingest
{
  "messages": [{"role": "user", "content": "..."}, {"role": "assistant", "content": "..."}],
  "session_id": "optional",
  "model": "optional",
  "embeddings": "optional"
}

Recall:

POST /v1/memory/search
{"query": "what does the user prefer", "limit": 10}

Graph recall context:

POST /v1/memory/prepare
{
  "messages": [{"role": "user", "content": "..."}],
  "session_id": "optional",
  "density": "default",
  "context_limit": 10
}

For the current API surface, use the live API reference.

Support and package history

Changelog

0.2.0

  • Added opt-in vault mailbox tools, scoped permissions, and user-controlled external delivery.

0.1.2 — 2026-08-08

  • Replaced package-local README links with public URLs that resolve correctly from PyPI.

0.1.1 — 2026-08-08

  • Corrected official project URLs, added public-safe metadata and classifiers, and expanded integration, security, and store-semantics documentation.

0.1.0 — 2026-06-07

  • Initial release with clients, tools, LangGraph nodes, MemoryRouterStore, and write-path sanitization.

The package is maintained by MemoryRouter and available under the MIT License.

Original files

See the file attachment contract for original-file transfer, host support and explicit save. A file ID or a download URL is not evidence that any bytes were read.

Metadata

Release files for langchain-memoryrouter 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-memoryrouter 0.5.1
File Size Uploaded Provenance Actions
langchain_memoryrouter-0.5.1.tar.gz 22.9 kB Without provenance Details for langchain_memoryrouter-0.5.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for langchain-memoryrouter 0.5.1
File Interpreter ABI Platform Actions
langchain_memoryrouter-0.5.1-py3-none-any.whl Python 3 none any Details for langchain_memoryrouter-0.5.1-py3-none-any.whl

Total release size: 48.8 kB

Release files / langchain_memoryrouter-0.5.1.tar.gz

Download URL langchain_memoryrouter-0.5.1.tar.gz
Size 22.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e3def37571ee048656e89e75a41b58983caef70724aa1e7f243d75fef3a20c64
BLAKE2b-256 checksum
How to use checksums
a8e3981516e8bc7c43d152e0f33593fc098c50d6e007d40e5e1422d59d0c5d8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.30 {"installer":{"name":"uv","version":"0.9.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / langchain_memoryrouter-0.5.1-py3-none-any.whl

Download URL langchain_memoryrouter-0.5.1-py3-none-any.whl
Size 25.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1d5073fb25b20e17ba94c89e5d29acb9397597277fa8586e01624966ba845091
BLAKE2b-256 checksum
How to use checksums
a3e6132d40060ccd3fea418c6eed0331c67d8dc3150e684457e58d4ec6b9b1b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.30 {"installer":{"name":"uv","version":"0.9.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for langchain-memoryrouter 0.5.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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