MemoryRouter integration for LangChain and LangGraph
Project description
langchain-memoryrouter
MemoryRouter memory for LangChain and LangGraph.
MemoryRouter gives every user in your AI product a private memory vault. This package lets LangChain developers use that memory layer through tools, graph nodes, or a LangChain BaseStore.
Install
pip install langchain-memoryrouter
Get a Memory Key at memoryrouter.ai. In multi-user products, map each app user to their own Memory Key.
Storage hygiene
Every write path sanitizes messages before ingest. MemoryRouter stores conversation text only:
- Keeps
HumanMessagetext asuser - Keeps
AIMessagetext asassistant - Drops
ToolMessageentirely - Drops AI tool calls and function-call args
- Drops AI messages that are only tool calls with no text
This is enforced in tools, nodes, and store writes. It is not a config option.
Pattern 1: tools
Works with LangChain bind_tools() and LangGraph create_react_agent().
from langchain_memoryrouter import create_memory_tools
tools = create_memory_tools(memory_key="mk_user_123")
model_with_tools = model.bind_tools(list(tools))
The package exposes two primitives only:
memoryrouter_retainstores sanitized conversation text with/v1/memory/ingestmemoryrouter_recallsearches memory with/v1/memory/search
No reflect tool. MemoryRouter is retain and recall.
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 and calls /v1/memory/ingest.
Pattern 3: BaseStore
Use MemoryRouterStore as a semantic long-term store for LangGraph.
from langchain_memoryrouter import MemoryRouterStore
store = MemoryRouterStore(memory_key="mk_user_123")
graph = builder.compile(store=store)
MemoryRouter is semantic memory, not a literal KV database. mset retains text into the user's vault. mget searches by key and returns the best matching memory content.
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
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_memoryrouter-0.1.0.tar.gz.
File metadata
- Download URL: langchain_memoryrouter-0.1.0.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8407e95429d133433b84cfb0f3656b490be832636e8e118b91be4999aee07526
|
|
| MD5 |
6908bfae88d3e195ff41930a3dc370ff
|
|
| BLAKE2b-256 |
49d024fdc7368b3d7508c14d2a359768f9e3aca8c3b35de9a426ebe93956d191
|
File details
Details for the file langchain_memoryrouter-0.1.0-py3-none-any.whl.
File metadata
- Download URL: langchain_memoryrouter-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13fddf48ba46685bf2fd83f951ca3fce5a3210c90c9d73a4442ef2cb81ac53a1
|
|
| MD5 |
30310650b0c6851690b70fb51910245f
|
|
| BLAKE2b-256 |
a05657d2639bf94a4f32f4498ece8e833d7f822ce8c523f7ee2f60b788ba1d3f
|