Give AG2 conversable agents email capabilities with MultiMail — centralized oversight ensures every email from any agent in the group is properly authorized.
AG2 is a community fork of AutoGen that provides a multi-agent conversation framework. It maintains API compatibility with AutoGen while adding community-driven features for production use. When AG2 agents in a group chat need to send email, MultiMail provides centralized oversight that catches sends from any agent in the conversation.
In AG2's multi-agent setup, multiple agents may independently decide to trigger email actions. MultiMail's centralized oversight is essential here: regardless of which agent in the group chat calls the send endpoint, the email is gated for human review in gated_send mode.
Integration uses AG2's function registration system. Define email functions and register them with your AssistantAgent instances, just as you would with AutoGen.
AG2 group chats involve multiple agents that can all trigger actions. MultiMail's centralized oversight ensures every email from any agent passes through the same review queue, preventing unauthorized sends.
AG2 maintains AutoGen API compatibility, so MultiMail integrations written for AutoGen work with AG2 unchanged. Same function registration, same tool calling patterns, same email oversight.
AG2 focuses on production readiness. MultiMail's oversight modes align with this goal — graduated trust from gated_all to autonomous lets you deploy email-capable agents with appropriate safety controls.
AG2 agents can generate and execute code that might include email operations. MultiMail's API-level oversight catches email sends from both registered functions and dynamically generated code.
import requests
from autogen import AssistantAgent, UserProxyAgent
MULTIMAIL_API = "https://api.multimail.dev/v1"
HEADERS = {"Authorization": "Bearer mm_live_your_api_key"}
def send_email(to: str, subject: str, body: str,
mailbox_id: str) -> str:
"""Send an email via MultiMail.
In gated_send mode, queues for human approval."""
resp = requests.post(f"{MULTIMAIL_API}/send",
headers=HEADERS,
json={"mailbox_id": mailbox_id,
"to": to, "subject": subject,
"body": body})
return str(resp.json())
def check_inbox(mailbox_id: str, limit: int = 10) -> str:
"""Check inbox for recent messages."""
resp = requests.get(
f"{MULTIMAIL_API}/mailboxes/{mailbox_id}/inbox",
headers=HEADERS, params={"limit": limit})
return str(resp.json())
def reply_email(message_id: str, body: str) -> str:
"""Reply to an email within its thread."""
resp = requests.post(f"{MULTIMAIL_API}/reply",
headers=HEADERS,
json={"message_id": message_id,
"body": body})
return str(resp.json())Define email functions and register them with AG2's AssistantAgent for tool calling.
from autogen import AssistantAgent, UserProxyAgent, config_list_from_json
llm_config = {
"config_list": [{"model": "gpt-4o", "api_key": "your_openai_key"}],
"temperature": 0.1
}
"cm"># Create the email assistant
email_assistant = AssistantAgent(
name="EmailAssistant",
system_message=(
"You are an email assistant using MultiMail. "
"Use the provided functions to send, read, and reply to "
"emails. All outbound emails use gated_send mode — they "
"are queued for human approval before delivery. "
"Always confirm email content with the user before sending."
),
llm_config=llm_config
)
"cm"># Create the user proxy (handles function execution)
user_proxy = UserProxyAgent(
name="User",
human_input_mode="NEVER",
code_execution_config={"work_dir": "email_workspace"}
)
"cm"># Register email functions
for func in [send_email, check_inbox, reply_email]:
email_assistant.register_for_llm(
name=func.__name__,
description=func.__doc__
)(func)
user_proxy.register_for_execution(
name=func.__name__
)(func)
"cm"># Start the conversation
user_proxy.initiate_chat(
email_assistant,
message="Check my inbox and summarize any new messages."
)Configure an AG2 AssistantAgent with email tools and appropriate system message.
from autogen import GroupChat, GroupChatManager
"cm"># Create specialized agents
researcher = AssistantAgent(
name="Researcher",
system_message="You research topics and provide summaries. "
"You do not send emails directly.",
llm_config=llm_config
)
email_agent = AssistantAgent(
name="EmailAgent",
system_message=(
"You handle email communications via MultiMail. "
"Only send emails when explicitly asked or when the "
"group agrees on the content. All sends use gated_send "
"mode (queued for human approval)."
),
llm_config=llm_config
)
"cm"># Register email functions only with the email agent
for func in [send_email, check_inbox, reply_email]:
email_agent.register_for_llm(
name=func.__name__, description=func.__doc__
)(func)
user_proxy.register_for_execution(
name=func.__name__
)(func)
"cm"># Create group chat
group_chat = GroupChat(
agents=[user_proxy, researcher, email_agent],
messages=[],
max_round=10
)
manager = GroupChatManager(
groupchat=group_chat, llm_config=llm_config
)
user_proxy.initiate_chat(
manager,
message="Research AI safety best practices and email "
"a summary to [email protected]"
)Set up an AG2 group chat where agents collaborate on email tasks with centralized oversight.
Sign up at multimail.dev, create a mailbox, and generate an API key from your dashboard. Your key will start with mm_live_.
Install AG2 and the HTTP library for calling the MultiMail API.
pip install ag2 requestsCreate email functions that call the MultiMail API. Register them with your AssistantAgent using register_for_llm and with UserProxyAgent using register_for_execution.
Set up an AssistantAgent with a system message explaining the oversight mode, or create a group chat with a designated email agent.
Review emails queued by AG2 agents in the MultiMail dashboard. Approve or reject before delivery.
Email infrastructure built for AI agents. Verifiable identity, graduated oversight, and a 38-tool MCP server. Formally verified in Lean 4.