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.1.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.1-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: agentsmcp-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 2b21458532bcac2e63392d34273787e406a55127675522674019fd60c5fbcda7
MD5 d05591c1c4df3d796f7ad05f5fbcc1aa
BLAKE2b-256 2b2f5e49db8575a929f4aa51f5ab080383a1f5063505a9c0194907e433b50afe

See more details on using hashes here.

File details

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

File metadata

  • Download URL: agentsmcp-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.2 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3163dd1fafcec19060dd135a5644da81b91e5c0bedbf4334f6463fcf4999289b
MD5 309cb84cd5b9774b66afcbc1aae56506
BLAKE2b-256 17a12bbd19c5f7f731652a432c4d8548e9c8114a18cdacc2e5268c70ad16237f

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