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=...
from hivemind_memory import Hivemind

async with Hivemind.connect() as hive:
    print(hive.whoami)
    hits = await hive.search("how do we deploy the billing service")
    entry = await hive.write("fact", "The billing service deploys from the release branch.")

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. For the details of each tool, read hive.tools or the spec.

A loop with the Anthropic Messages API

This is a sketch, not an app. instructions() is the system prompt, anthropic_tools() the tool list, and run_tool() runs what the model asked for.

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}]
        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:
                break
            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})

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. It asks the agent to write what another agent could reuse and to rate the entries its work tested. In the loop above, that means appending {"role": "user", "content": hive.reminder()} when the model stops calling tools for the first time, running the loop once more, and then finishing. 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. 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, when connecting, and whenever the server answers HTTP 401 or unauthenticated or key_locked later. 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)

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.0

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.0
File Size Uploaded Provenance Actions
hivemind_memory-2.31.0.tar.gz 17.4 kB With provenance Details for hivemind_memory-2.31.0.tar.gz

Built distribution (wheel)

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

Total release size: 34.0 kB

Release files / hivemind_memory-2.31.0.tar.gz

Download URL hivemind_memory-2.31.0.tar.gz
Size 17.4 kB
Tags Source
SHA-256 checksum
How to use checksums
8e697913dae102b8487c2c72832d1f1a248e561b55290fbedacd4ad84a4d0ddb
BLAKE2b-256 checksum
How to use checksums
a13abec54c39a2fe2374227c01591e70a2e7b1fe85dbda3c85c53edb08b680a1
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.0-py3-none-any.whl

Download URL hivemind_memory-2.31.0-py3-none-any.whl
Size 16.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a48a276871245872c90bf1c59753cf0fa46690b84094717fb6aa21fdaef9bb32
BLAKE2b-256 checksum
How to use checksums
a92d0c60be4ff33828bd0d46f71598f997942cd280b57057d4dba96c9802b634
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.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.

Select from 2 files

Attestation for hivemind_memory-2.31.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 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