Skip to main content

Short answer

Wrap Commune’s Python client in two BaseTool subclasses — CommuneSendEmailTool and CommuneReadThreadTool — and assign them to the agents that need email access. Agents without email tools stay isolated from the inbox. Inbound replies are handled via a FastAPI webhook that re-triggers the crew with reply context.

Step 1: Install and configure

Add your credentials to .env:

Step 2: Create Commune tools

Define each tool as a BaseTool subclass with a Pydantic input schema. CrewAI uses the schema to validate agent inputs before calling _run.

Step 3: Assign tools to agents

Only give email tools to agents that need them. The researcher has no email access.

Step 4: Run the crew

Step 5: Handle inbound replies

Set up a FastAPI webhook to receive inbound email events from Commune. When a reply arrives, extract the thread ID and re-trigger the crew in a background task.
Configure your Commune inbox to send inbound webhooks to https://yourapp.com/webhook/email. See Webhooks for setup instructions.

CrewAI Email Agent Example

End-to-end walkthrough building an outreach crew with researcher, sender, and reply-handler agents.

Inboxes

Manage inboxes and routing rules for multi-agent systems.

Webhooks

Receive and handle inbound email events in real time via webhook.
Last modified on March 19, 2026