Skip to main content

Context-sync protocol for AI agents. Every agent has a mailbox. No agent ever starts cold.

Project description

AgentMailbox — Python SDK

Python client for AgentMailbox, the context-sync protocol for AI agents. Mirrors the JS SDK feature-for-feature.

Install

pip install agentsmcp

The PyPI distribution is named agentsmcp (matching the npm SDK); the import name stays agentmailbox:

from agentmailbox import AgentMailbox

For local development from a clone:

pip install -e ".[dev]"

Requires Python 3.10+.

Start the server

The Python SDK is a pure HTTP client — it talks to the AgentMailbox Node server. Start it first:

cd ~/agentmailbox
npm start

Async usage

import asyncio
from agentmailbox import AgentMailbox

async def main():
    async with AgentMailbox("researcher@demo", server="http://localhost:3000") as a:
        await a.connect()
        result = await a.send(
            "writer@demo",
            {"task": "summarize diffusion models"},
            context_snapshot={"step": "research_complete", "paper_count": 2},
        )
        print(result.thread_id)

asyncio.run(main())

Multi-agent (CC/BCC/ReplyAll)

async with AgentMailbox("orchestrator@demo", server=SERVER) as orchestrator:
    await orchestrator.connect()
    sent = await orchestrator.send(
        "researcher@demo",
        {"task": "find 50 papers on diffusion models"},
        cc=["writer@demo"],
        bcc=["logger@demo"],
        context_snapshot={"step": "task_dispatched", "priority": "high"},
    )

async with AgentMailbox("researcher@demo", server=SERVER) as researcher:
    await researcher.connect()
    inbound = await researcher.receive()
    # inbound.context.snapshot → {"step": "task_dispatched", "priority": "high"}
    # inbound.messages[0].cc   → ["writer@demo"]
    # inbound.messages[0].bcc  → None  (stripped from non-sender's view)

    await researcher.reply_all(
        sent.thread_id,
        {"result": "found 50 papers"},
        context_snapshot={"step": "research_complete", "paper_count": 50},
    )

Run the bundled demos:

python examples/basic.py
python examples/multi_agent.py

Sync usage

For scripts and notebooks that aren't async-friendly:

from agentmailbox import AgentMailboxSync

agent = AgentMailboxSync("researcher@demo")
agent.connect()
result = agent.send("writer@demo", {"task": "..."})
print(result.thread_id)

AgentMailboxSync drives a fresh event loop per call via asyncio.run. It's convenient but slower than the async client.

API

All methods return typed dataclasses (SendResult, ReceiveResult, Thread, ContextFrame, Message, ParticipantRole, Context). No untyped dicts in the public surface.

Method HTTP
connect() POST /agents/register
send(to, payload, ...) POST /messages/send
reply_all(thread_id, payload) POST /messages/reply-all
unread() GET /mailbox/:id/unread
receive(from_agent=None) GET /mailbox/:id/unread + filter
threads() GET /mailbox/:id
sync(thread_id) GET /threads/:id/sync?as=:id
participants(thread_id) GET /threads/:id/participants?as=
mark_read(thread_id) POST /mailbox/:id/read

Exceptions

  • AgentMailboxError — base class. .status_code set when raised from HTTP.
  • NotFoundError — 404
  • ServerError — 5xx
  • ConnectionError — server unreachable

License

MIT

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

agentsmcp-0.1.2.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agentsmcp-0.1.2-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file agentsmcp-0.1.2.tar.gz.

File metadata

  • Download URL: agentsmcp-0.1.2.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for agentsmcp-0.1.2.tar.gz
Algorithm Hash digest
SHA256 a8d69cee2c690773693a24ffd402b97283e6b878416d1913d652fe8ffbe6839c
MD5 bd101c81e5751caa4492e1db5e44c4c4
BLAKE2b-256 1bc1cd2dc0264cadf9b3cdcfcc3baa01006c62e0e6c73949afb160cc9a49ef6b

See more details on using hashes here.

File details

Details for the file agentsmcp-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: agentsmcp-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for agentsmcp-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 85ee9cbd8ab21d6a1bd3910773b32be730073277597b5d4ee160939305b15e95
MD5 d5f8f9edac824e50b38afdd1951bc96d
BLAKE2b-256 3995f36c44a01eb717862a3a8605a4be9c21f9660cce97fd03e052ec15c29175

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