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.0.tar.gz (10.4 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.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: agentsmcp-0.1.0.tar.gz
  • Upload date:
  • Size: 10.4 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.0.tar.gz
Algorithm Hash digest
SHA256 24b71234e200503319c4ec6bb425dc73bcf33e0d5356850b59564ea9016f0f40
MD5 14128701e73a1cd9c450015731cab136
BLAKE2b-256 fcf7feef0ffa6386720b31efb560a94a414e02f3d10b19489b1b49b486762fb9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: agentsmcp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.8 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 98fc1aa58f8cc8e8afba8782e0a745c2533df6803ca2bb48636ef87262074215
MD5 d580f8cc92711adc8129338cc76791bf
BLAKE2b-256 e033489c820397b9789e93bf368499bd31becf7ed3e65527617cfb0d551529a4

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