Email Tools for OpenAI Agents SDK

Extend OpenAI's official agent framework with MultiMail's email infrastructure — complete with guardrails, handoffs, and human oversight for every message.


The OpenAI Agents SDK is OpenAI's official framework for building agentic applications. It features a minimal, opinionated API with built-in support for handoffs between agents, guardrails for input/output validation, and tracing for observability. MultiMail provides the email infrastructure layer that these agents need to interact with the real world through email.

By integrating MultiMail with the OpenAI Agents SDK, your agents can send emails, check inboxes, manage contacts, and handle threads — all while benefiting from both OpenAI's guardrails and MultiMail's email-specific oversight. The SDK's guardrails validate agent outputs structurally, while MultiMail's gated_send mode adds human judgment before delivery.

Connect your agents to MultiMail by defining function tools that call the REST API. The SDK's tool-calling pattern makes it straightforward to register MultiMail operations as agent capabilities.

Built for OpenAI Agents SDK developers

Guardrails Plus Oversight

The SDK's guardrails validate agent outputs but cannot catch email-specific risks like wrong recipients or inappropriate tone. MultiMail's oversight modes add a human review layer specifically for email, complementing OpenAI's structural validation.

Agent Handoffs for Email Workflows

Use the SDK's handoff feature to route between specialized email agents. A triage agent can hand off to a customer support agent or an escalation agent, each with their own email handling logic and MultiMail mailbox.

Built-in Tracing for Email Actions

The SDK's tracing system records every tool call, including MultiMail email operations. Combined with MultiMail's audit log, you get end-to-end observability from agent reasoning through email delivery.

Minimal Boilerplate

The OpenAI Agents SDK is designed for simplicity. Registering MultiMail tools requires just a few function definitions with type hints — the SDK handles tool schema generation, invocation, and response parsing automatically.

Graduated Trust with Oversight Modes

Start agents in gated_send mode where every email requires human approval. Progress to monitored or autonomous as the agent proves reliable. MultiMail's five oversight levels let you calibrate trust precisely.


Get started in minutes

Define MultiMail Tools
python
import requests
from agents import function_tool

MULTIMAIL_API = "https://api.multimail.dev/v1"
HEADERS = {"Authorization": "Bearer mm_live_your_api_key"}

@function_tool
def send_email(to: str, subject: str, body: str, mailbox_id: str) -> str:
    """Send an email through MultiMail. In gated_send mode, queues for human approval."""
    resp = requests.post(f"{MULTIMAIL_API}/send", headers=HEADERS, json={
        "mailbox_id": mailbox_id, "to": to,
        "subject": subject, "body": body
    })
    return str(resp.json())

@function_tool
def check_inbox(mailbox_id: str, limit: int = 10) -> str:
    """Check the inbox for recent messages."""
    resp = requests.get(
        f"{MULTIMAIL_API}/mailboxes/{mailbox_id}/inbox",
        headers=HEADERS, params={"limit": limit}
    )
    return str(resp.json())

@function_tool
def reply_email(message_id: str, body: str) -> str:
    """Reply to an email by message ID, maintaining thread context."""
    resp = requests.post(f"{MULTIMAIL_API}/reply", headers=HEADERS, json={
        "message_id": message_id, "body": body
    })
    return str(resp.json())

Create function tools that the OpenAI Agents SDK can invoke to interact with MultiMail.

Build an Email Agent with Guardrails
python
from agents import Agent, Runner, GuardrailFunctionOutput, InputGuardrail
from pydantic import BaseModel

class EmailSafetyCheck(BaseModel):
    is_safe: bool
    reasoning: str

guardrail_agent = Agent(
    name="Email Safety",
    instructions="Check if the user&"cm">#039;s email request is appropriate. "
    "Flag requests to send spam, phishing, or abusive content.",
    output_type=EmailSafetyCheck
)

async def email_guardrail(ctx, agent, input_text):
    result = await Runner.run(guardrail_agent, input_text, context=ctx.context)
    return GuardrailFunctionOutput(
        output_info=result.final_output,
        tripwire_triggered=not result.final_output.is_safe
    )

email_agent = Agent(
    name="Email Assistant",
    instructions="You are an email assistant using MultiMail. The mailbox "
    "uses gated_send mode, so sent emails queue for human approval. "
    "Use the provided tools to check inbox, send, and reply to emails.",
    tools=[send_email, check_inbox, reply_email],
    input_guardrails=[InputGuardrail(guardrail_function=email_guardrail)]
)

result = await Runner.run(email_agent, "Check my inbox and summarize new messages")
print(result.final_output)

Create an agent with email tools and a guardrail that validates email content before sending.

Multi-Agent Handoffs for Email Processing
python
from agents import Agent, Runner

triage_agent = Agent(
    name="Triage",
    instructions="You triage inbound emails. Check the inbox and classify "
    "each email. Hand off urgent emails to the Urgent Responder and "
    "routine emails to the Auto Responder.",
    tools=[check_inbox],
    handoffs=["urgent_responder", "auto_responder"]
)

urgent_responder = Agent(
    name="Urgent Responder",
    instructions="You handle urgent emails. Draft thoughtful replies "
    "using reply_email. These will go through gated_send approval.",
    tools=[reply_email, send_email]
)

auto_responder = Agent(
    name="Auto Responder",
    instructions="You handle routine emails with standard replies. "
    "Use reply_email to respond with appropriate templates.",
    tools=[reply_email]
)

"cm"># The SDK handles handoffs automatically based on agent decisions
result = await Runner.run(triage_agent, "Process today&"cm">#039;s inbox")
print(result.final_output)

Use the SDK's handoff feature to route between specialized email agents.


Step by step

1

Create a MultiMail Account and API Key

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

2

Install Dependencies

Install the OpenAI Agents SDK and requests for calling the MultiMail API.

bash
pip install openai-agents requests
3

Define Email Tools

Create functions decorated with @function_tool that wrap MultiMail API endpoints. Define at minimum send_email and check_inbox.

4

Create Your Agent

Build an Agent with your email tools, a system prompt explaining the email context, and optionally input guardrails for content validation.

bash
agent = Agent(
    name="Email Assistant",
    instructions="You manage email via MultiMail in gated_send mode.",
    tools=[send_email, check_inbox, reply_email]
)
5

Run and Review

Execute the agent with Runner.run(). Review and approve pending emails in the MultiMail dashboard when using gated_send mode.

bash
result = await Runner.run(agent, "Check my inbox")

Common questions

How do OpenAI Agents SDK guardrails interact with MultiMail's oversight?
They operate at different layers. SDK guardrails validate the structure and content of agent inputs/outputs at the application level. MultiMail's oversight modes control whether emails are actually delivered at the infrastructure level. Together, guardrails catch bad content before it becomes an email, and oversight catches anything guardrails miss.
Can I use the SDK's handoff feature to route between email agents?
Yes. Define specialized agents for different email tasks (triage, urgent response, auto-reply) and use handoffs to route between them. Each agent can have its own tools and instructions while sharing the same MultiMail API key and mailbox configuration.
Does the SDK support async email operations?
Yes. The OpenAI Agents SDK is async-native with Runner.run() being an async function. Your MultiMail tool functions can use httpx or aiohttp for async HTTP calls to the MultiMail API, and the SDK handles the async execution seamlessly.
Can I use the SDK's tracing to monitor email activity?
Yes. The SDK's built-in tracing records every tool call including MultiMail operations. You can see which emails were checked, what drafts were composed, and which sends were initiated. Combined with MultiMail's audit log, you get full observability from agent reasoning to email delivery.
Is there rate limiting I should handle in my tools?
MultiMail rate limits depend on your plan tier, from 200 emails per month on the free Starter plan to 150,000 on Scale. The API returns standard 429 responses when limits are hit. Implement retry logic in your tool functions, or use the SDK's error handling to gracefully inform the agent when limits are reached.

Explore more

The only agent email with a verifiable sender

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