The short answer
Installcommune-mail, wrap the Commune client in BaseTool subclasses, and pass those tools to any LangChain agent. The agent can then send email, read inboxes, and act on replies — all through standard tool calls.
Step 1: Install and configure
Step 2: Create Commune tools
SubclassBaseTool for each capability you want to expose to the agent.
Python
Step 3: Add tools to a LangChain agent
Pass the tool instances tocreate_react_agent or AgentExecutor.
Python
Step 4: Handle inbound replies
Set a webhook URL in your Commune dashboard so the agent is triggered when a reply arrives. Use FastAPI (or any ASGI framework) to receive the payload.Python
extractedData field is populated automatically if you have a structured extraction schema configured on the inbox. Use it to route or enrich the agent’s context without extra parsing.
Full example
A complete working script that provisions tools, runs an agent, and starts the webhook server:Python
https://your-host/webhook/email.
Related
Email for LangChain Agents
Deeper walkthrough covering multi-agent email patterns with LangChain.
Inboxes
Create and manage per-agent inboxes programmatically via the API.
Webhooks
Webhook payload reference and signature verification for inbound email handling.

