OpenAI Agents SDK
Getting started
The OpenAI Agents SDK is OpenAI’s Python framework for building agents. The agentmail-toolkit package exposes the AgentMail API as OpenAI Agents SDK tools, so an agent can create inboxes, send, receive, reply, forward, and manage threaded email with no glue code.
To give your OpenAI agent an email address, install agentmail-toolkit, import AgentMailToolkit from agentmail_toolkit.openai, and pass AgentMailToolkit().get_tools() as the agent’s tools. The agent can then call create_inbox to provision its own address and use the other tools to send and read mail from it.
Use cases
- Give agents their own inboxes: Provision a dedicated email address per agent so it can send and receive mail independently.
- Triage and reply: Read recent threads and reply inside the same thread, with threading handled automatically.
- Forward and label: Route messages to the right people with
forward_messageand track what’s been handled with labels. - Inbound-driven agents: Pair the toolkit with AgentMail webhooks so your agent reacts the moment mail arrives.
Prerequisites
- An AgentMail account with an API key from the AgentMail Console.
- Python 3.11+ and the OpenAI Agents SDK (
openai-agents), with anOPENAI_API_KEYset.
Setup
Install the toolkit alongside the OpenAI Agents SDK:
Set your API key:
Quickstart
Create an agent with the AgentMail tools:
Then run it with Runner:
Configuring the toolkit
Authentication
AgentMailToolkit() reads AGENTMAIL_API_KEY from the environment. For custom configuration, pass your own AgentMail client from the agentmail SDK:
Selecting tools
get_tools() returns every tool. Pass a list of names to get only that subset:
Production agents should usually pass only the tools they need. A smaller tool set keeps the model focused and limits what it can do, for example leaving out delete_inbox.
Tool names and parameters are both snake_case (send_message, inbox_id, thread_id). An inbox_id is the inbox’s full email address, such as my-agent@agentmail.to.
Error handling
A failed tool call raises RuntimeError, which the OpenAI Agents SDK surfaces as a tool failure. The model can tell it apart from a successful result and decide whether to retry or change course.
Available tools
Inboxes
Messages
Threads
Attachments
Agent verification
Resources
- Source code: github.com/agentmail-to/agentmail-toolkit
- PyPI: pypi.org/project/agentmail-toolkit
- OpenAI Agents SDK docs: openai.github.io/openai-agents-python
- Other frameworks: The same package ships LangChain and LiveKit Agents bindings through
agentmail_toolkit.langchainandagentmail_toolkit.livekit. See the LiveKit guide for a voice agent example, or the MCP integration for the hosted server.
