Multi-Agent Interface Layer reference implementation
Project description
Multi-Agent Interface Layer (MAIL)
| Single-swarm example | Multi-swarm example |
|---|---|
MAIL is an open protocol for letting autonomous agents communicate, coordinate, and cooperate across local runtimes and distributed swarms. This repository hosts both the normative specification and a production-grade Python/FastAPI reference implementation that demonstrate how to build interoperable agent systems on top of the MAIL contract.
Quick Links
- Protocol specification: spec/SPEC.md
- JSON Schemas: spec/MAIL-core.schema.json, spec/MAIL-interswarm.schema.json
- REST transport (OpenAPI 3.1): spec/openapi.yaml
- Reference implementation source: src/mail/
- Command-line interface: docs/cli.md,
uv run mail … - Asynchronous HTTP client: docs/client.md, src/mail/client.py
- Deployment examples and docs: docs/
1. MAIL Protocol Overview
Goals
- Provide a transport-agnostic message contract so agents from different vendors can interoperate.
- Encode routing, addressing, and task lifecycle semantics that work for single-swarm and cross-swarm topologies.
- Support reliable inter-swarm federation over standard HTTP infrastructure.
- Remain minimal enough to embed inside bespoke agent runtimes or platform orchestrators.
Message Primitives
MAIL defines five core message types that all conforming systems MUST understand. Each payload is validated against MAIL-core.schema.json.
msg_type |
Required payload fields | Typical use case |
|---|---|---|
request |
task_id, request_id, sender, recipient, subject, body |
Agent-to-agent task delegation |
response |
task_id, request_id, sender, recipient, subject, body |
Reply that correlates with a prior request |
broadcast |
task_id, broadcast_id, sender, recipients[], subject, body |
Notify many agents in a swarm |
interrupt |
task_id, interrupt_id, sender, recipients[], subject, body |
High-priority stop/alter instructions |
broadcast_complete |
task_id, broadcast_id, sender, recipients[], subject, body (MAILBroadcast) |
Marks task completion by a supervisor agent |
All messages are wrapped in a MAILMessage envelope with an id (UUID) and RFC 3339 timestamp. Optional fields such as sender_swarm, recipient_swarm, and routing_info carry federation metadata without altering the core contract.
Addressing & Routing
- Local agents are addressed by name (
agent-name). - Interswarm addresses append the remote swarm (
agent-name@swarm-name). - Routers MUST wrap cross-swarm traffic in a
MAILInterswarmMessagethat includes source/target swarm identifiers and optional metadata. - Priority tiers ensure urgent system and user messages preempt regular agent chatter. Within a tier, messages are FIFO by enqueue sequence.
Transport Requirements
- The normative HTTP binding is published in spec/openapi.yaml and implemented by the reference FastAPI service.
/messagehandles user tasks and local agent traffic./tasksreturns the caller's in-flight and completed tasks, and/taskfetches a specific task record by ID./interswarm/forward//interswarm/backmove agent traffic between swarms, and/interswarm/messageproxies user/admin requests to a remote swarm.- Implementations MUST replay responses from remote swarms back into the local queue to complete task lifecycles.
Conformance & Validation
- Use the included JSON Schemas for request/response validation in any runtime.
- Run
uv run spec/validate_samples.pyto check sample payloads against the schemas. - Terms defined in the spec follow RFC 2119/RFC 8174 keywords.
2. Reference Implementation
Key Features
- Persistent swarm runtime with pluggable agents, tools, and memory backends.
- Task resume safety via automatic queue snapshots that stash pending task messages on completion/breakpoints and restore them when the user resumes work.
- FastAPI HTTP server exposing REST endpoints, Server-Sent Events (SSE) streams, and interswarm messaging routes.
- Task introspection API surfaces
GET /tasksandGET /taskso callers can audit active work, inspect SSE timelines, and resume confidently from any state. - CLI launcher (
mail server,mail client) for running the server and an interactive REPL without writing code. - Async MAIL client (
MAILClient) mirroring the REST API with SSE helpers for quick integrations. - Built-in swarm registry with health checks and service discovery for distributed deployments.
- Configurable authentication layer that plugs into external auth/token providers.
- Example agents (
supervisor,weather,math, cross-swarm demos) showcasing MAIL usage patterns.
Architecture Highlights
- src/mail/core/runtime.py: Mailbox scheduling, task orchestration, priority queues, and tool execution.
- src/mail/server.py: FastAPI application with REST + SSE endpoints and interswarm routing.
- src/mail/net/router.py: HTTP federation between swarms, including metadata rewriting.
- src/mail/net/registry.py: Service registry and liveness monitoring for remote swarms.
- src/mail/factories/: Agent functions that instantiate agents with their LLM/tool configuration.
- src/mail/examples/: Example agents and prompts.
The runtime processes MAIL messages asynchronously, tracks per-task state, and produces broadcast_complete events to signal overall task completion.
3. Getting Started
Prerequisites
- Python 3.12+
uvpackage manager (recommended) orpip- LiteLLM proxy endpoint for LLM calls
- Authentication service providing
/auth/loginand/auth/check(see below)
Installation
# Clone and enter the repository
git clone https://github.com/charonlabs/mail --branch v1.3.6
cd mail
# Install dependencies (preferred)
uv sync
# or, using pip
pip install -e .
Configuration
Set the following environment variables before starting the server:
# Authentication endpoints
export AUTH_ENDPOINT=http://your-auth-server/auth/login
export TOKEN_INFO_ENDPOINT=http://your-auth-server/auth/check
# LLM proxy (required only if your swarm uses use_proxy=true)
export LITELLM_PROXY_API_BASE=http://your-litellm-proxy
# Optional provider keys (required for direct provider calls)
export OPENAI_API_KEY=sk-your-openai-api-key
export ANTHROPIC_API_KEY=sk-your-anthropic-key
# Optional persistence (set to "none" to disable)
export DATABASE_URL=postgresql://...
Defaults for host, port, swarm metadata, and client behaviour are loaded from mail.toml. The [server.settings] table exposes task_message_limit, which bounds how many messages the runtime will process per task when run_continuous is active (default 15), and print_llm_streams (default true), which controls whether runtime-managed agents print LLM reasoning/response stream chunks to server stdout. Set print_llm_streams=false (or pass mail server --print-llm-streams false) for quieter server logs; task/event SSE streaming is unaffected. Override the file or point MAIL_CONFIG_PATH at an alternate TOML to adjust these values per environment. Use CLI flags such as --swarm-name, --swarm-source, --swarm-registry, and --print-llm-streams true|false (or edit mail.toml) to override these at launch; mail server exports SWARM_NAME, SWARM_SOURCE, SWARM_REGISTRY_FILE, and BASE_URL for downstream tools but does not read them as config overrides.
MAIL will create the parent directory for SWARM_REGISTRY_FILE on startup if it is missing, so you can rely on the default registries/ path without committing the folder.
Swarm definitions live in swarms.json. Each entry declares the agents, entrypoint, tools, and default models for a swarm.
Run a Local Swarm
# Start the FastAPI server (includes SSE + registry)
uv run mail server
# or explicitly
uv run -m mail.server
Federate Two Swarms (Example)
# Terminal 1
uv run mail server --port 8000 --swarm-name swarm-alpha --swarm-registry registries/swarm-alpha.json
# Terminal 2
uv run mail server --port 8001 --swarm-name swarm-beta --swarm-registry registries/swarm-beta.json
# Register each swarm with the other (requires admin bearer token)
curl -X POST http://localhost:8000/swarms \
-H "Authorization: Bearer $ADMIN_TOKEN" \
-H "Content-Type: application/json" \
-d '{"name": "swarm-beta", "base_url": "http://localhost:8001"}'
curl -X POST http://localhost:8001/swarms \
-H "Authorization: Bearer $ADMIN_TOKEN" \
-H "Content-Type: application/json" \
-d '{"name": "swarm-alpha", "base_url": "http://localhost:8000"}'
Agents can now address peers using agent-name@swarm-name, and responses will route back automatically.
4. Repository Layout
mail/
├── spec/ # Protocol specification, schemas, validation utilities
├── src/mail/ # Reference implementation (core runtime + FastAPI services)
├── docs/ # Supplemental docs (registry, inter-swarm, auth, etc.)
├── swarms.json # Default swarm configurations
├── tests/ # Pytest suite covering protocol + runtime behaviors
├── scripts/ # Operational helpers (deploy, smoke tests, tooling)
├── registries/ # Swarm registry persistence (created as needed)
├── assets/ # Diagrams and static assets (README image, etc.)
└── pyproject.toml # Project metadata and dependency definitions
5. Development Workflow
uv run mail server– run the reference server locally.uv run pytest -q– execute the automated test suite.uv run ruff check --fix .– lint and auto-fix style issues.uv run spec/validate_samples.py– validate example MAIL payloads against the schemas.
6. Documentation & Resources
- Quickstart guide: docs/quickstart.md
- Architecture deep-dive: docs/architecture.md
- Protocol message format reference: docs/message-format.md
- HTTP/API surface: docs/api.md
- Swarm configuration & registry operations: docs/configuration.md, docs/registry.md
- Database persistence: docs/database.md
- HTTP client usage: docs/client.md
- Security hardening checklist: docs/security.md
- Agents, tools, and examples: docs/agents-and-tools.md, docs/examples.md
- Testing and troubleshooting: docs/testing.md, docs/troubleshooting.md
- Runtime source directories: src/mail/examples/, src/mail/factories/
7. Contributing
- Read CONTRIBUTING.md for branching, issue, and review guidelines.
- All commits require a Developer Certificate of Origin sign-off (
git commit -s). - Please open an issue to propose significant protocol changes before implementation.
- Core maintainers are listed in MAINTAINERS.md.
8. Licensing & Trademarks
- Reference implementation code: Apache License 2.0 (LICENSE).
- Specification text: Creative Commons Attribution 4.0 (SPEC-LICENSE).
- Essential patent claims: Open Web Foundation Final Specification Agreement 1.0 (SPEC-PATENT-LICENSE).
- Trademarks and descriptive use policy: TRADEMARKS.md.
Using the spec or code implies acceptance of their respective terms.
For questions, bug reports, or feature requests, open an issue or start a discussion in this repository.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mail_swarms-1.3.6.tar.gz.
File metadata
- Download URL: mail_swarms-1.3.6.tar.gz
- Upload date:
- Size: 3.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b2cedc31040f2aaf433825462718dc4ed42115cd3b41497e1c3052e5abf61e51
|
|
| MD5 |
ee2f1fb00e13b65420318812b11efd49
|
|
| BLAKE2b-256 |
62b53b868183797eab21c6bab349f0de1c3146614bf2e58a23e670342c8646cc
|
Provenance
The following attestation bundles were made for mail_swarms-1.3.6.tar.gz:
Publisher:
python-publish.yml on charonlabs/mail
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mail_swarms-1.3.6.tar.gz -
Subject digest:
b2cedc31040f2aaf433825462718dc4ed42115cd3b41497e1c3052e5abf61e51 - Sigstore transparency entry: 975109529
- Sigstore integration time:
-
Permalink:
charonlabs/mail@45841499830973116946d4b356b1931897ecce6b -
Branch / Tag:
refs/tags/v1.3.6 - Owner: https://github.com/charonlabs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@45841499830973116946d4b356b1931897ecce6b -
Trigger Event:
release
-
Statement type:
File details
Details for the file mail_swarms-1.3.6-py3-none-any.whl.
File metadata
- Download URL: mail_swarms-1.3.6-py3-none-any.whl
- Upload date:
- Size: 332.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6996cb09987a7d18a23289d4bed660eed77e86e64da59bd2a34b5519a47dc84e
|
|
| MD5 |
909e70628aecd445c1d827e4ab1beb0f
|
|
| BLAKE2b-256 |
7eef1945f9e7a20006504d776bc6d81d2f79dbc2505097e4a71aedc59f25e8fa
|
Provenance
The following attestation bundles were made for mail_swarms-1.3.6-py3-none-any.whl:
Publisher:
python-publish.yml on charonlabs/mail
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mail_swarms-1.3.6-py3-none-any.whl -
Subject digest:
6996cb09987a7d18a23289d4bed660eed77e86e64da59bd2a34b5519a47dc84e - Sigstore transparency entry: 975109551
- Sigstore integration time:
-
Permalink:
charonlabs/mail@45841499830973116946d4b356b1931897ecce6b -
Branch / Tag:
refs/tags/v1.3.6 - Owner: https://github.com/charonlabs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@45841499830973116946d4b356b1931897ecce6b -
Trigger Event:
release
-
Statement type: