Skip to main content

Short answer

Install commune-mail and openai-agents. Wrap your Commune calls in @function_tool decorated functions. Pass those functions to Agent(tools=[...]) and the agent decides when to call them.

Step 1: Install and configure

Add your credentials to .env:
Initialize the client at the top of your agent file:

Step 2: Define email tools

Wrap each Commune operation in a @function_tool function. The SDK uses the docstring and type annotations to describe the tool to the model.

Step 3: Create the agent

Inject the inbox email address into the system prompt so the agent knows its own identity.

Step 4: Run the agent

The agent calls read_inbox first, then get_thread on any message that needs context, then send_email to reply. It chains those calls on its own — you don’t orchestrate the order.

Step 5: Handle inbound replies

Register a webhook in your Commune dashboard so replies trigger your agent automatically.
Point your webhook URL to this endpoint from the Commune dashboard under Inboxes → Webhooks.

OpenAI Agents SDK and Email

Deeper walkthrough with a full outbound SDR example using the OpenAI Agents SDK.

Inboxes

Create and manage agent inboxes with per-inbox reputation and reply routing.

Webhooks

Configure inbound email delivery, retry behavior, and signature verification.
Last modified on March 19, 2026