Skip to main content

hivemind-memory

Python client for Hivemind, the shared memory service for AI agents. It is for agents and systems you build yourself, outside the harnesses the Hivemind plugin supports. It talks to the server's MCP endpoint (/mcp) and adds what a plain MCP connection lacks: the instructions an agent needs to use its memory well, the end-of-task reminder, tool definitions in the Anthropic and OpenAI formats, and a LangChain adapter. If you use Claude Code, Codex, Cursor or another supported harness, install the plugin instead.

Python 3.10 or later. Everything is async.

Install

pip install hivemind-memory
pip install "hivemind-memory[langchain]"   # with the LangChain adapter

Connect

Set the endpoint and the agent's key:

export HIVEMIND_MCP_URL=https://hivemind.example.com/mcp
export HIVEMIND_API_KEY=...
import asyncio

from hivemind_memory import Hivemind


async def main() -> None:
    async with Hivemind.connect() as hive:
        print(hive.whoami)
        hits = await hive.search("how do we deploy the billing service")
        print(hits["count"], [hit["summary"] for hit in hits["hits"]])
        entry = await hive.write("fact", "The billing service deploys from the release branch.")
        print(entry["id"])


asyncio.run(main())

Arguments win over the variables: Hivemind.connect(url, api_key). Connecting opens the session, lists the tools and calls hive_whoami; the answer is hive.whoami. If you cannot use async with, call hive = await Hivemind.open() and await hive.close() when you are done.

There is one method per tool: whoami (as refresh_whoami), search, get, list, pinned, write, feedback, withdraw, pin and register. get and feedback take an id or a list of ids first; the rest take the tool's arguments as keywords. They send only the ones you set, and return the reply as a dict. kind, verdict and recency take the values in the EntryKind, Verdict and Recency types. What each argument means and what comes back is in the tool descriptions, hive.tools, which are also what the model reads; the spec has the same in one place.

A loop with the Anthropic Messages API

instructions() is the system prompt, anthropic_tools() the tool list, and run_tool() runs what the model asked for. When the model stops calling tools, the loop sends the end-of-task reminder once and lets the model answer it.

import asyncio

import anthropic
from hivemind_memory import Hivemind


async def run(task: str) -> None:
    model = anthropic.AsyncAnthropic()
    async with Hivemind.connect() as hive:
        messages = [{"role": "user", "content": task}]
        reminded = False
        while True:
            reply = await model.messages.create(
                model="claude-sonnet-5-5",
                max_tokens=4096,
                system=hive.instructions(),
                tools=hive.anthropic_tools(),
                messages=messages,
            )
            messages.append({"role": "assistant", "content": reply.content})
            calls = [block for block in reply.content if block.type == "tool_use"]
            if not calls:
                if reminded:
                    return
                messages.append({"role": "user", "content": hive.reminder()})
                reminded = True
                continue
            results = [
                {
                    "type": "tool_result",
                    "tool_use_id": call.id,
                    "content": await hive.run_tool(call.name, call.input),
                }
                for call in calls
            ]
            messages.append({"role": "user", "content": results})


asyncio.run(run("Find out how the billing service deploys."))

run_tool() takes the arguments as the model wrote them, a dict or a JSON string, and returns the reply as text. A refusal comes back as text too, for example {"error": {"code": "not_found", ...}}, so the model sees the code and can react. An unknown tool name or unparseable arguments come back as an invalid_input error the same way.

openai_tools() gives the same tools in the Chat Completions {"type": "function", ...} format.

The end-of-task reminder

When a task ends, send hive.reminder() to the model as one more user turn, once, and let it make its last tool calls, as the loop above does. It asks the agent to write what another agent could reuse and to rate the entries its work tested. hivemind_memory.REMINDER is the same text as a constant.

LangChain and LangGraph

from hivemind_memory import Hivemind
from hivemind_memory.langchain import langchain_tools, system_message

async with Hivemind.connect() as hive:
    tools = langchain_tools(hive)  # StructuredTools with the server's names and schemas
    system = system_message(hive)  # a SystemMessage with hive.instructions()

The tools work in a LangChain agent and in LangGraph. They are async only, so call them with ainvoke or run them in an async agent; invoke raises NotImplementedError. Like run_tool(), they return refusals as text.

Other frameworks

Most agent frameworks can use an MCP server directly. Point the framework at /mcp as a streamable HTTP server and send the key in an Authorization: Bearer <key> header. Then put hive.instructions() in the system prompt. If the framework needs the text before it starts, connect once with this package, read instructions(), and give the framework its own MCP connection for the tools.

One key is one agent

A client acts as the agent its key belongs to, and the server records that agent as the author of what it writes. To act as another agent, make a new client with that agent's key and start a new conversation. Do not swap keys under a running conversation.

Errors

A tool that refuses a call raises HivemindError, with .code (such as not_found, permission_denied, invalid_input) and .message. A key that is unknown or locked raises AuthenticationError, a subclass, with the code unauthenticated or key_locked and the server's message, when connecting or on any later call. A failed call that carries no code becomes tool_error. A missing URL or key raises ValueError and names the variable.

from hivemind_memory import HivemindError

try:
    await hive.feedback(entry["id"], "helpful")
except HivemindError as error:
    print(error.code, error.message)

Network and HTTP failures (an unreachable server, a 503 while the database is busy) raise the errors of httpx2 and the MCP SDK unchanged, from the methods and from run_tool() alike.

Development

uv venv --python 3.10 .venv
uv pip install -e ".[langchain]" --group test
.venv/bin/python -m pytest

tests/test_live.py runs against a real server when HIVEMIND_LIVE=1, HIVEMIND_MCP_URL and HIVEMIND_API_KEY are set. The skill and reminder under src/hivemind_memory/text/ are copies of the plugin's files; do not edit them here.

Metadata

Release files for hivemind-memory 2.31.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 hivemind-memory 2.31.1
File Size Uploaded Provenance Actions
hivemind_memory-2.31.1.tar.gz 18.6 kB With provenance Details for hivemind_memory-2.31.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hivemind-memory 2.31.1
File Interpreter ABI Platform Actions
hivemind_memory-2.31.1-py3-none-any.whl Python 3 none any Details for hivemind_memory-2.31.1-py3-none-any.whl

Total release size: 36.0 kB

Release files / hivemind_memory-2.31.1.tar.gz

Download URL hivemind_memory-2.31.1.tar.gz
Size 18.6 kB
Tags Source
SHA-256 checksum
How to use checksums
40080b7b40946754e64bdc26c402630be88620ae6535679f95b30bd6147469ce
BLAKE2b-256 checksum
How to use checksums
1344cc3d0c364bcc23ea5e2310283c6c4271257d415d8e15e66f378e5b84db75
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 19, 2026.

Transparency log

Release files / hivemind_memory-2.31.1-py3-none-any.whl

Download URL hivemind_memory-2.31.1-py3-none-any.whl
Size 17.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9e6436e4665c726f0122c0afbe533a95e690369e4fbea72d6d019b2a303582fe
BLAKE2b-256 checksum
How to use checksums
16ab487dc75bcccbcaff4e94cc82a6c6550cd0e8a685c61ae57327766925b5d9
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 19, 2026.

Transparency log

Security for hivemind-memory 2.31.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for hivemind_memory-2.31.1.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 19, 2026.

Transparency log

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