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.

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 and this package's SECURITY.md.

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

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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_memoryrouter-0.1.1.tar.gz (8.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_memoryrouter-0.1.1-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file langchain_memoryrouter-0.1.1.tar.gz.

File metadata

  • Download URL: langchain_memoryrouter-0.1.1.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.2

File hashes

Hashes for langchain_memoryrouter-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d4d2c1a8257d49053eab8f82d001f863e9470872706030c00c6190c8c012001c
MD5 a6dd390452b50d9370683962e44c2723
BLAKE2b-256 3477b9cd05314f6ba8469dc8f474d427f0b48fa28aa20981207380c0fe76d5c5

See more details on using hashes here.

File details

Details for the file langchain_memoryrouter-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_memoryrouter-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 78b5ce0a15960c85c5e743420d33c1672b9908436126365a59ff3dd2b93febd2
MD5 f4d5962870794d648cfb527df5bcc7c0
BLAKE2b-256 1933f99e9582e8788ff86dfa9ad26b56ce434b444ceab53d7da1001ef391aa81

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.2

2 files

This release

0.1.1 This release

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page