Lightweight Email Agents with smolagents

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.

Built for smolagents developers

Simple Tool Definitions

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.

API-Level Safety for Code Agents

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.

Hub Model Flexibility

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.

Lightweight Architecture

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.

Graduated Trust

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.


Try it with your agent

No code, no dashboard. Paste this to your AI agent — it connects MultiMail, creates an inbox, and builds the flow for you.

1. Read https://multimail.dev/llms.txt first, then connect the MultiMail MCP server using the MCP connection details it provides. Create a free MultiMail inbox, set up a verified sending domain, and configure the inbox oversight mode as gated_send. 2. Wire MultiMail into this smolagents agent with smolagents’ MCP support: create server_parameters from the MultiMail MCP details, load them with ToolCollection.from_mcp using streamable-http transport, then pass the loaded tool_collection.tools into a CodeAgent or ToolCallingAgent. 3. Give the agent only these email behaviors: check the MultiMail inbox for recent messages, draft replies using the message context, and send or schedule email through the MultiMail tools exposed by MCP. Do not use any email API, webhook, endpoint, or header outside what MultiMail exposes through MCP. 4. Send one test email from the new inbox to the operator email used during setup. Keep the subject and body clearly marked as a test, and report the result returned by MultiMail. 5. Keep the inbox in gated_send for this run, so every outbound email remains pending until the developer reviews and approves it. Do not switch to monitored or autonomous unless the developer explicitly asks after the test succeeds.

Step by step

1

Create a MultiMail Account and API Key

Sign up at multimail.dev, create a mailbox, and generate an API key. Your key will start with mm_live_.

2

Install Dependencies

Install smolagents and requests for calling the MultiMail API.

3

Define Email Tools

Create Tool subclasses for send_email, check_inbox, and reply_email that wrap MultiMail API endpoints.

4

Create Your Agent

Choose ToolCallingAgent or CodeAgent based on your needs, and pass your MultiMail tools along with a system prompt explaining the email context.

5

Run and Approve

Execute the agent with agent.run(). Review and approve pending emails in the MultiMail dashboard when using gated_send mode.


Common questions

Should I use ToolCallingAgent or CodeAgent with MultiMail?
ToolCallingAgent is simpler and more predictable — the LLM selects tools and the framework calls them. CodeAgent is more flexible, writing Python code that can implement complex email logic. For most email workflows, ToolCallingAgent is recommended. Use CodeAgent when you need custom logic like filtering, batching, or conditional processing.
Is CodeAgent safe to use with email sending?
MultiMail's oversight operates at the API level, so even code generated by CodeAgent goes through gated_send approval. The agent can write code that calls send_email, but the email won't deliver until a human approves it in the MultiMail dashboard. This makes CodeAgent safe for email tasks despite its code execution capabilities.
Can I use open-source models from HuggingFace Hub?
Yes. smolagents works with any model on HuggingFace Hub or via API. Models like Llama 3, Qwen, and Mistral work well for email tasks. For code generation with CodeAgent, code-specialized models like Qwen2.5-Coder tend to produce better results.
How do I handle email attachments with smolagents?
Create an additional Tool subclass that handles attachment encoding. The tool can accept a file path, encode it as base64, and include it in the MultiMail API request body. Both ToolCallingAgent and CodeAgent can use this tool alongside send_email for attachment support.
Can smolagents handle long-running email workflows?
smolagents is designed for single-turn agent interactions. For long-running workflows that span human approval delays, implement a polling loop that creates a new agent.run() call to check pending status. For more complex multi-step workflows, consider pairing smolagents with a workflow orchestrator like LangGraph or ControlFlow.

Explore more

The only agent email with a verifiable sender

Email infrastructure built for AI agents. Verifiable identity, graduated oversight, and a hosted MCP server. Formally verified in Lean 4.