langchain-mnemoverse
Long-term memory for LangChain agents and chains, backed by Mnemoverse. The memory lives in your Mnemoverse account, so what an agent saves here is also there in Claude, ChatGPT, Cursor, VS Code and any other tool connected to the same account.
MnemoverseRetrieverreturns the memories relevant to a query as LangChainDocumentobjects, for chains and RAG.MnemoverseToolkitgives an agent three tools:mnemoverse_search,mnemoverse_saveandmnemoverse_rate. Rating a recalled memory as helpful or misleading changes what comes back next for similar questions. The tools are also importable one by one:MnemoverseSearchTool,MnemoverseSaveTool,MnemoverseRateTool.MnemoverseMiddlewarerecalls the memories relevant to the user's latest message once percreate_agentrun and adds them to the system message, within a time budget. If recall is slow or fails, the run goes on without memory.
This integration is maintained by the Mnemoverse team, who run the Mnemoverse memory service.
Installation
pip install langchain-mnemoverse
The middleware needs the langchain package, which the retriever and the tools do not:
pip install "langchain-mnemoverse[agents]"
or with uv:
uv add "langchain-mnemoverse[agents]"
Without the extra, MnemoverseMiddleware raises an ImportError that says how to install it, and from langchain_mnemoverse import * leaves it out.
Create an API key at console.mnemoverse.com and set it in the environment, or pass api_key=. With neither, and no client passed in (see Settings), building any of the components raises ValueError.
export MNEMOVERSE_API_KEY=mk_live_...
Usage
An agent with memory
The example below needs a chat model; it uses OpenAI through create_agent's model string, which needs pip install langchain-openai and OPENAI_API_KEY. Any LangChain chat model works the same way.
from langchain.agents import create_agent
from langchain_mnemoverse import MnemoverseMiddleware, MnemoverseToolkit
agent = create_agent(
model="openai:gpt-4.1-mini",
tools=MnemoverseToolkit(domain="user:ana").get_tools(),
middleware=[MnemoverseMiddleware(domain="user:ana")],
system_prompt="You are a helpful assistant.",
)
agent.invoke({"messages": [{"role": "user", "content": "Remember that I always take the window seat."}]})
result = agent.invoke({"messages": [{"role": "user", "content": "Which seat do I take on flights?"}]})
print(result["messages"][-1].content)
The middleware reads once at the start of every run, so a tool loop does not read again. The agent saves only when it calls mnemoverse_save, which its description limits to things the user asks it to remember.
A retriever for chains
from langchain_mnemoverse import MnemoverseRetriever
retriever = MnemoverseRetriever(domain="project:docs", k=4)
for doc in retriever.invoke("Which database does the ledger use?"):
print(doc.id, doc.metadata["relevance"], doc.page_content)
Each document's id is the memory's id. metadata holds atom_id, relevance, similarity, valence, importance, domain, concepts, created_at, source, provenance, metadata (what was saved with the memory) and superseded_by. ainvoke works the same way.
Calling a tool directly
from langchain_mnemoverse import MnemoverseSearchTool
search = MnemoverseSearchTool(domain="user:ana")
message = search.invoke(
{"type": "tool_call", "id": "1", "name": "mnemoverse_search", "args": {"query": "seat", "limit": 3}}
)
print(message.content)
The answer lists one memory per line with its id, which is what mnemoverse_rate takes.
Which memory a run uses
Every call reads and writes one Mnemoverse domain, a namespace inside your account such as user:ana or project:support, of up to 100 characters.
-
One user: pass
domain="user:ana"to the components. -
Several users in one app: leave
domainout of the tools and the middleware, and name the domain per run:agent.invoke( {"messages": [{"role": "user", "content": "Which seat do I take?"}]}, config={"configurable": {"mnemoverse_domain": f"user:{user_id}"}}, )
The middleware and the tools also read
mnemoverse_domainfrom the agent run'scontext(agent.invoke(..., context=...), a mapping key or an attribute). If a run names it in both places, the two must agree: when they differ, the tools answer the model with an error and the middleware runs without memory, so one run never reads one user's memory and writes another's. The retriever takesdomain=per call,retriever.invoke(query, domain=f"user:{user_id}"), or as a configurable field:retriever.configurable_fields(domain=ConfigurableField(id="mnemoverse_domain")).
Take user_id from your app's signed-in user on the server, never from client input or model output. The domain is never an argument the model can set. A run with no domain gets no memory: the tools answer the model with an error and the middleware logs one warning; it is never served from another domain.
A domain separates how memory is used, not who may read it: the API key can read every domain of its account. Give each app its own key, so you can revoke one without the others. A shared room's address, xroom:<room_id>, works as a domain. How Mnemoverse handles keys and data: mnemoverse.com/docs/api/security.
Settings
Every component takes api_key (default: MNEMOVERSE_API_KEY), base_url (default https://core.mnemoverse.com), and client and async_client for a ready mnemoverse.MnemoClient and AsyncMnemoClient. Sync calls (invoke) use the sync client and async calls (ainvoke) the async one.
- Neither passed: the package opens its own clients from the key. Components built with the same key and
base_urlshare them, including the copiesconfigurable_fieldsmakes for each call: one sync client, and one async client per event loop, so a component also works from severalasyncio.run()calls. - Only
client: async calls run it in a worker thread. - Only
async_client: sync calls raiseValueErrorunless you also passapi_key=. They never fall back toMNEMOVERSE_API_KEY, which may belong to another account than your client. - An
AsyncMnemoClientyou pass in works on one event loop: SDK 0.5.2 binds its connections to the loop that first used it, and from a secondasyncio.run()its calls fail with "Event loop is closed". Pass one per loop, or let the package open its own.
Clients you pass in are never closed by this package.
MnemoverseRetriever |
Default | What it does |
|---|---|---|
domain |
required | The domain every call reads; override per call with invoke(query, domain=...) |
k |
4 | Documents per call, 1 to 500; override per call with invoke(query, k=...) |
min_relevance |
0.3 | Lowest relevance, 0 to 1, of a returned memory |
Tools and MnemoverseToolkit |
Default | What it does |
|---|---|---|
domain |
None |
The domain every call uses; without it, the run's config or context |
save (toolkit) |
True |
Include mnemoverse_save |
rate (toolkit) |
True |
Include mnemoverse_rate |
limit (search argument, set by the model) |
5 | Memories per search, 1 to 50 |
There is no delete tool. The toolkit's tools share one pair of clients.
MnemoverseMiddleware |
Default | What it does |
|---|---|---|
domain |
None |
The domain every run reads; without it, the run's context or config |
top_k |
5 | Memories per recall, 1 to 500 |
min_relevance |
0.3 | Lowest relevance, 0 to 1, of a recalled memory. A broad message ("what do you know about me?") scores lower than a specific one; lower this if broad messages recall nothing |
recall_timeout |
8.0 | Seconds the run waits for recall before it goes on without it; also how long it waits for a capture. A call that has started is not cancelled: it finishes in the background, with ainvoke only while the event loop keeps running. asyncio.run() cancels it when it returns, and the middleware logs that it did not complete |
context_prompt |
a heading and one line | Text above the recalled memories. The default line tells the model the memories are reference data, not instructions; keep it if you write your own |
capture |
False |
Save the user's messages of each run as one memory. Prefer the mnemoverse_save tool, which saves only what the user asks to keep |
With invoke, the middleware runs each recall and capture on one of four worker threads, each with a client of its own when the middleware opens its clients from the key. A slow call therefore never holds up the agent's tool calls, and a call still waiting for a worker when its run stops waiting is dropped, not sent later. A MnemoClient passed as client= runs one call at a time, so the middleware gives it a single worker; do not pass the tools the same client, because a recall that outlives recall_timeout keeps it busy and the next tool call waits for it. For a server with many users at once, call the agent with ainvoke, where calls run concurrently on the async client.
At most k, limit or top_k memories are used, also when the server returns more.
Memory text is written by other people and tools too: members of a shared room, the other AI tools on the account. In the middleware's memory block and in the search tool's answer each memory is therefore one line, with line breaks turned into spaces and < and > into ‹ and ›, so a memory cannot close the block or pose as another memory with an id the server never returned. The retriever's documents keep the text unchanged.
Errors
- Retriever: SDK errors propagate unchanged (
MnemoAuthError,MnemoRateLimitError,MnemoUnavailableError,MnemoError), so a chain fails loudly; wrap it with.with_fallbacks(...)if you prefer. An invalid domain orkraisesValueError. - Tools: every failure reaches the model as a
ToolMessagewithstatus="error", so the agent can tell the user what happened: a refused call with the server's reason, and arguments that fail the schema (such aslimitover 50) with the field and why. This holds insidecreate_agentand when you invoke a tool yourself with aToolCall. - Middleware: memory never breaks a run. A timeout or a failed call is logged under the
langchain_mnemoverselogger and the run continues without memory. A refusal is logged with the server's reason and stops recall, or capture, for 15 minutes: a 401 (the key is refused) for every domain, a 403 (the key may not use this domain, such as a room it is not a member of) for that domain only. After the pause the middleware tries again. - Logs: nothing this package logs contains the key, a query or memory text. Domains often carry a user id, so a refused domain is logged as
#and the first 12 hex digits of its SHA-256 (hashlib.sha256(domain.encode()).hexdigest()[:12]), not by name.
Input is kept within the API limits before any request: queries and memories are stripped of surrounding space, queries are then cut to their last 5,000 characters, the save tool refuses a memory over 10,000 characters, and capture saves the first 10,000. A blank query or memory makes no request: the retriever returns no documents, and the search and save tools answer the model with an error.
Cost
Each retriever call and each tool call is one API call, which counts as at most one query against your plan: the SDK retries a call that failed for a passing reason (a timeout, a lost connection, a rate limit or a server error) up to three more times, and only successful requests count. A blank query or memory, a save refused for its length and a rating with no ids make no call. The middleware makes at most one read per agent run, and one write more with capture=True. Reads, writes and ratings count together against your plan's daily query limit: the Free plan allows 1,000 queries a day. Plans and limits are on mnemoverse.com/pricing.
Examples
examples/agent_with_memory.py is an agent with the middleware and the toolkit, and examples/rag_retriever.py a retriever in a small chain. Both need MNEMOVERSE_API_KEY and OPENAI_API_KEY:
pip install "langchain-mnemoverse[agents]" langchain-openai
python examples/agent_with_memory.py
Compatibility
Tested with the mnemoverse Python SDK 0.5.2, langchain-core 1.8.4, langchain 1.5.2 and langchain-tests 1.1.9 on Python 3.11, 3.12, 3.13 and 3.14, and with the lowest supported versions, langchain-core 1.4.7, langchain 1.3.0 and pydantic 2.9.1, on Python 3.11. The tests use fake SDK clients; a live suite runs on demand. It needs SDK 0.5.2 or later: in earlier versions a call refused with a client error (such as 401, 403 or a quota 429) while the client was probing the service after an outage could leave that client refusing every call until the process restarted.
Links
- Python SDK: mnemoverse on PyPI, docs
- Pricing and limits: mnemoverse.com/pricing
- Security and data handling: mnemoverse.com/docs/api/security
- Issues: github.com/mnemoverse/langchain-mnemoverse/issues
License
MIT, as LangChain. See LICENSE.
Metadata
Release files for langchain-mnemoverse 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| langchain_mnemoverse-0.1.0.tar.gz | 48.1 kB | With provenance | Details for langchain_mnemoverse-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| langchain_mnemoverse-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for langchain_mnemoverse-0.1.0-py3-none-any.whl |
Total release size: 75.1 kB
Release files / langchain_mnemoverse-0.1.0.tar.gz
| Download URL | langchain_mnemoverse-0.1.0.tar.gz |
|---|---|
| Size | 48.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b96a3aba1c527caef90c00ac50dec065ac32db7cf88cb2249747ce00f7f5fe22
|
|
BLAKE2b-256 checksum How to use checksums |
ba374cbdda5e9cb01952967416114a336c0b1ac0097a3105d0759f05cd97849f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logRelease files / langchain_mnemoverse-0.1.0-py3-none-any.whl
| Download URL | langchain_mnemoverse-0.1.0-py3-none-any.whl |
|---|---|
| Size | 27.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6827b3b94a498cdd86264addffc41a2c36ba88662ab09120053aa42bdd40682d
|
|
BLAKE2b-256 checksum How to use checksums |
41b03928587568b9f8613f1db99dfcc7e57b167db10747bc8f6d2fdec1c4c282
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logSecurity for langchain-mnemoverse 0.1.0
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for langchain_mnemoverse-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logA 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.