Email Across OpenAI Swarm Handoff Chains

Give Swarm agents email capabilities that persist across handoffs — with MultiMail's oversight ensuring every send is gated regardless of which agent triggers it.


OpenAI Swarm is an experimental framework for lightweight multi-agent orchestration using function-based routing and agent handoffs. When email tasks pass through a handoff chain — from a triage agent to a support agent to a follow-up agent — MultiMail ensures oversight is enforced at every step.

Swarm's handoff pattern means an email action might be initiated by one agent and completed by another. MultiMail's API-level oversight catches every send call regardless of which agent in the chain makes it, preventing oversight gaps during agent transitions.

Integration is natural: define email functions that call the MultiMail REST API, then pass them as tools to your Swarm agents. The functions follow Swarm's convention of returning strings for the next agent to process.

Built for Swarm (OpenAI) developers

Oversight Across Handoffs

Swarm agents hand off tasks to each other. MultiMail's API-level oversight ensures that email sends are gated regardless of which agent in the chain initiates the action — no oversight gaps during transitions.

Context Variables for Email State

Swarm's context_variables carry state across handoffs. Store mailbox IDs, thread IDs, and email context in context_variables so agents downstream in the chain have the information they need for email actions.

Function-Based Email Tools

Swarm uses plain Python functions as tools, matching exactly how you define MultiMail API wrappers. No adapters or special integrations needed — just define functions and pass them to agents.

Lightweight Multi-Mailbox Routing

Different Swarm agents can use different mailboxes. A sales agent sends from the sales mailbox while a support agent uses the support mailbox, each with appropriate oversight settings.


Try it with your agent

No code, no dashboard. Paste this to your AI agent — it connects MultiMail, creates an inbox, and builds the flow for you.

1. Get MultiMail ready first: read https://multimail.dev/llms.txt, connect the MultiMail MCP server in your agent environment, create a free inbox for this project, and set up a verified sending domain so the agent can send from an approved address. 2. Wire MultiMail into my Swarm (OpenAI) implementation using Swarm’s real function tool mechanism: define normal Python functions for checking the inbox, drafting a reply, and sending or scheduling email, then pass those functions in the Swarm Agent’s functions list so any handoff-capable agent can call them. 3. Give the Swarm agents exactly these email capabilities: inbox-check to inspect recent mail for the MultiMail inbox, draft-reply to prepare a response without sending it, and send to compose, send, or schedule email through MultiMail. Keep the same tools available across handoffs so email context persists when one Swarm agent transfers to another. 4. Send a test email from the verified sender to a test recipient, then check the MultiMail inbox and confirm the Swarm agent can see the message, draft an appropriate reply, and identify the send action it would take. 5. Run MultiMail in gated_send oversight mode for this integration. Do not allow the Swarm agent to send automatically; every send, including sends triggered after handoff to another Swarm agent, must pause for my review and approval before MultiMail sends it.

Step by step

1

Create a MultiMail Account and API Key

Sign up at multimail.dev, create a mailbox, and generate an API key from your dashboard. Your key will start with mm_live_.

2

Install Dependencies

Install the OpenAI Python package (which includes Swarm) and the HTTP library for API calls.

3

Define Email Functions

Create functions that accept context_variables and call MultiMail API endpoints. Follow Swarm's convention of returning strings.

4

Create Your Agent Chain

Define Swarm Agent instances with appropriate email functions and handoff transfer functions. Include oversight mode details in each agent's instructions.

5

Approve Pending Emails

Review emails queued by any agent in the Swarm chain via the MultiMail dashboard. Approve or reject before delivery.


Common questions

Does oversight persist across Swarm handoffs?
Yes. MultiMail enforces oversight at the API level, not the agent level. Regardless of which Swarm agent triggers a send_email or reply_email call, the API checks the mailbox's oversight mode and gates the message accordingly. No agent can bypass this.
How do I share email thread context across handoffs?
Use Swarm's context_variables to carry thread IDs and message IDs across agent handoffs. When the triage agent reads an email, store the thread_id in context_variables so the support agent can reply within the same thread using reply_email.
Can different Swarm agents use different mailboxes?
Yes. Store the active mailbox_id in context_variables and update it during handoffs. A sales agent can hand off to a support agent while switching the mailbox context, so each agent sends from the appropriate address with its own oversight settings.
Is Swarm production-ready for email automation?
Swarm is experimental and educational. For production email automation, consider pairing Swarm's patterns with a more robust framework like OpenAI Agents SDK. MultiMail works with both, and the email function definitions are identical since both use standard Python functions.

Explore more

The only agent email with a verifiable sender

Email infrastructure built for AI agents. Verifiable identity, graduated oversight, and a hosted MCP server. Formally verified in Lean 4.