Skip to content
Writing
OpenAI SwarmPythonMulti-AgentArchitecture

OpenAI Swarm Email Delegation: Coordinating Specialist Sub-Agents with Scoped Keys

Learn how to implement lightweight multi-agent delegation routines using OpenAI Swarm patterns to isolate email credentials and enforce permission boundaries.

Tayyab MughalFounder & AI Chief2 min read

Lightweight agent handoffs vs heavyweight frameworks

OpenAI Swarm introduces a minimalist pattern for multi-agent coordination centered on stateless routines and function-based handoffs.

Instead of passing global credentials to a monolithic agent, Swarm allows a Customer Triage Agent to hand off execution to a dedicated Outbound Email Agent that alone holds scoped sending permissions.

Implementing the Swarm Handoff Pattern

Here is how to structure a triage agent that inspects customer questions and transfers control to an email agent with allowlist validation.

PYTHON
from swarm import Swarm, Agent
import requests
import os

client = Swarm()

def send_transactional_email(to_email: str, subject: str, message: str) -> str:
    """Dispatches email via SadaSend scoped credentials."""
    res = requests.post(
        "https://api.sadasend.com/v1/emails",
        headers={"Authorization": f"Bearer {os.getenv('SADASEND_AGENT_KEY')}"},
        json={"to": to_email, "subject": subject, "text": message}
    )
    return "Dispatched" if res.status_code == 200 else f"Failed: {res.text}"

# Dedicated Outbound Specialist
email_agent = Agent(
    name="Outbound Email Agent",
    instructions="You are a dedicated sender. Format the email clearly and call send_transactional_email.",
    functions=[send_transactional_email]
)

def transfer_to_email_agent():
    """Handoff function for triage agent."""
    return email_agent

# Front-line Triage Agent (No email execution tools)
triage_agent = Agent(
    name="Triage Agent",
    instructions="Determine if the user requires an email notification. If yes, transfer to Outbound Email Agent.",
    functions=[transfer_to_email_agent]
)

response = client.run(
    agent=triage_agent,
    messages=[{"role": "user", "content": "Please send a confirmation email to sam@partner.io about project launch."}]
)
print(response.messages[-1]["content"])

Security isolation benefits

  • Triage and reasoning agents never hold API secrets in their context window.
  • Tool execution is localized to leaf agents with explicit allowlists.
  • Zero bloat: Python execution finishes in milliseconds without heavyweight background daemons.
Free plan

Building AI agents that send email?

Scoped API keys, per-key recipient allowlists, approval mode and a hosted MCP server with ten tools — on the free plan, without a card.