Skip to main content

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 HumanMessage text as user
  • Keeps AIMessage text as assistant
  • Drops ToolMessage entirely
  • 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_retain stores sanitized conversation text with /v1/memory/ingest
  • memoryrouter_recall searches 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


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

Uploaded Python 3

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

Hashes for langchain_memoryrouter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8407e95429d133433b84cfb0f3656b490be832636e8e118b91be4999aee07526
MD5 6908bfae88d3e195ff41930a3dc370ff
BLAKE2b-256 49d024fdc7368b3d7508c14d2a359768f9e3aca8c3b35de9a426ebe93956d191

See more details on using hashes here.

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

Hashes for langchain_memoryrouter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 13fddf48ba46685bf2fd83f951ca3fce5a3210c90c9d73a4442ef2cb81ac53a1
MD5 30310650b0c6851690b70fb51910245f
BLAKE2b-256 a05657d2639bf94a4f32f4498ece8e833d7f822ce8c523f7ee2f60b788ba1d3f

See more details on using hashes here.

Supported by

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