Combine HuggingFace's smolagents framework with MultiMail's email infrastructure for simple, effective email agents — with human oversight at the API level.
smolagents is HuggingFace's lightweight agent framework that supports both code-based and tool-calling agents. It emphasizes simplicity and works with any LLM available on the HuggingFace Hub, making it easy to build agents that interact with external services. MultiMail provides the email infrastructure that smolagents need to send, receive, and manage email.
By integrating MultiMail with smolagents, your agents can compose and send emails, check inboxes, and manage contacts through simple tool definitions. smolagents' code execution mode can write arbitrary email-sending code, but MultiMail's API-level oversight ensures that even code-generated send calls go through approval when configured in gated_send mode.
Connect smolagents to MultiMail by defining Tool subclasses that call the REST API. Both ToolCallingAgent and CodeAgent can use these tools to perform email operations within their respective execution patterns.
smolagents uses a clean Tool base class pattern. Define MultiMail tools by subclassing Tool with a name, description, inputs, and a forward method that calls the API. No complex abstractions required.
smolagents' CodeAgent can write and execute arbitrary Python code, including HTTP requests. MultiMail's oversight operates at the API level, so even dynamically generated code that calls the send endpoint goes through approval in gated_send mode.
smolagents works with any LLM on HuggingFace Hub or via API. Pair your preferred model with MultiMail tools to build email agents without being locked into a specific LLM provider.
Both smolagents and MultiMail's REST API are designed for simplicity. No complex SDK installations or heavy dependencies — just define tools, create an agent, and start processing email.
Start with gated_send where every email your smolagent drafts requires human approval. As you build confidence in the agent's output quality, graduate to monitored or autonomous modes for less friction.
import requests
from smolagents import Tool
MULTIMAIL_API = "https://api.multimail.dev/v1"
HEADERS = {"Authorization": "Bearer mm_live_your_api_key"}
class SendEmailTool(Tool):
name = "send_email"
description = "Send an email through MultiMail. In gated_send mode, queues for human approval."
inputs = {
"to": {"type": "string", "description": "Recipient email address"},
"subject": {"type": "string", "description": "Email subject line"},
"body": {"type": "string", "description": "Email body content"},
"mailbox_id": {"type": "string", "description": "Mailbox ID to send from"}
}
output_type = "string"
def forward(self, to, subject, body, mailbox_id):
resp = requests.post(f"{MULTIMAIL_API}/send", headers=HEADERS, json={
"mailbox_id": mailbox_id, "to": to,
"subject": subject, "body": body
})
return str(resp.json())
class CheckInboxTool(Tool):
name = "check_inbox"
description = "Check the inbox for recent messages."
inputs = {
"mailbox_id": {"type": "string", "description": "Mailbox ID to check"},
"limit": {"type": "integer", "description": "Max messages to return", "nullable": True}
}
output_type = "string"
def forward(self, mailbox_id, limit=10):
resp = requests.get(
f"{MULTIMAIL_API}/mailboxes/{mailbox_id}/inbox",
headers=HEADERS, params={"limit": limit}
)
return str(resp.json())Create smolagents Tool subclasses that wrap MultiMail API endpoints.
from smolagents import ToolCallingAgent, HfApiModel
"cm"># Use any HuggingFace Hub model or API-based model
model = HfApiModel(model_id="meta-llama/Llama-3.1-70B-Instruct")
agent = ToolCallingAgent(
tools=[SendEmailTool(), CheckInboxTool()],
model=model,
system_prompt="You are an email assistant using MultiMail. "
"The mailbox operates in gated_send mode, so sent emails "
"are queued for human approval before delivery. "
"Always confirm what you&"cm">#039;ve done after each action."
)
result = agent.run("Check my inbox for mailbox your_mailbox_id and summarize unread messages")
print(result)Create a smolagents ToolCallingAgent that uses MultiMail tools for email operations.
from smolagents import CodeAgent, HfApiModel
model = HfApiModel(model_id="Qwen/Qwen2.5-Coder-32B-Instruct")
"cm"># CodeAgent writes Python code that calls your tools
code_agent = CodeAgent(
tools=[SendEmailTool(), CheckInboxTool()],
model=model,
system_prompt="You are an email assistant. Write Python code to "
"accomplish email tasks using the provided tools. The mailbox "
"uses gated_send mode — emails are queued for human approval. "
"The mailbox ID is &"cm">#039;your_mailbox_id'."
)
# The agent will generate and execute code like:
# inbox = check_inbox(mailbox_id="your_mailbox_id")
"cm"># for email in inbox['emails']:
"cm"># if 'urgent' in email['subject'].lower():
"cm"># send_email(to=email['from'], subject=f"Re: {email['subject']}", ...)
result = code_agent.run(
"Check my inbox and reply to any emails with &"cm">#039;urgent' in the subject"
)
print(result)Use smolagents' CodeAgent which writes and executes Python code to handle email tasks.
Sign up at multimail.dev, create a mailbox, and generate an API key. Your key will start with mm_live_.
Install smolagents and requests for calling the MultiMail API.
pip install smolagents requestsCreate Tool subclasses for send_email, check_inbox, and reply_email that wrap MultiMail API endpoints.
Choose ToolCallingAgent or CodeAgent based on your needs, and pass your MultiMail tools along with a system prompt explaining the email context.
agent = ToolCallingAgent(tools=[SendEmailTool(), CheckInboxTool()], model=model)Execute the agent with agent.run(). Review and approve pending emails in the MultiMail dashboard when using gated_send mode.
result = agent.run("Check my inbox")Email infrastructure built for AI agents. Verifiable identity, graduated oversight, and a 38-tool MCP server. Formally verified in Lean 4.