Skip to main content

Documentation Index

Fetch the complete documentation index at: https://langchain-5e9cc07a-preview-opensw-1780069467-dc8133d.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

AgentMail is an inbox-as-an-API platform for AI agents. The langchain-agentmail package provides LangChain tools for sending messages, replying inside a thread, managing drafts, downloading attachments, and labeling—all wired to a real AgentMail inbox.

Overview

Integration details

ClassPackageSerializableJS supportVersion
AgentMailToolkitlangchain-agentmailPyPI - Version

Available tools

ToolDescription
AgentMailListInboxesToolList inboxes on the account
AgentMailCreateInboxToolCreate a new inbox
AgentMailListThreadsToolList threads inside an inbox
AgentMailGetThreadToolFetch a thread with its messages
AgentMailListMessagesToolList messages inside an inbox
AgentMailGetMessageToolFetch a single message with its body
AgentMailSendToolSend a new email from an inbox
AgentMailReplyToolReply inside an existing thread
AgentMailUpdateMessageLabelsToolAdd or remove labels on a message
AgentMailCreateDraftToolStage a draft (with optional send_at for scheduled delivery)
AgentMailUpdateDraftToolRevise an existing draft
AgentMailSendDraftToolSend a previously created draft
AgentMailDeleteDraftToolPermanently delete a draft
AgentMailGetAttachmentToolGet a presigned download URL for a message attachment

Setup

Install the package:
pip install -qU langchain-agentmail

Credentials

You need an AgentMail API key. Sign up at agentmail.to to get one.
import getpass
import os

if not os.environ.get("AGENTMAIL_API_KEY"):
    os.environ["AGENTMAIL_API_KEY"] = getpass.getpass("AgentMail API key:\n")

Instantiation

Use the toolkit to get all tools at once:
from langchain_agentmail import AgentMailToolkit

toolkit = AgentMailToolkit.from_api_key()
tools = toolkit.get_tools()
You can also instantiate individual tools directly:
from langchain_agentmail import AgentMailSendTool, AgentMailReplyTool

send = AgentMailSendTool()
reply = AgentMailReplyTool()

Invocation

Invoke directly with args

from langchain_agentmail import AgentMailSendTool

tool = AgentMailSendTool()
result = tool.invoke({
    "inbox_id": "ib_abc123",
    "to": "alice@example.com",
    "subject": "Hello from LangChain",
    "text": "This message was sent through langchain-agentmail.",
})
print(result)

Invoke with ToolCall

model_generated_tool_call = {
    "args": {
        "inbox_id": "ib_abc123",
        "to": "alice@example.com",
        "subject": "Follow up",
        "text": "Just checking in.",
    },
    "id": "1",
    "name": "agentmail_send_message",
    "type": "tool_call",
}
tool_msg = tool.invoke(model_generated_tool_call)
print(tool_msg.content)

Use within an agent

from langchain_agentmail import AgentMailToolkit
from langchain.chat_models import init_chat_model
from langgraph.prebuilt import create_react_agent

model = init_chat_model(model="claude-sonnet-4-6", model_provider="anthropic")

toolkit = AgentMailToolkit.from_api_key()
agent = create_react_agent(model, toolkit.get_tools())

response = agent.invoke({
    "messages": [(
        "user",
        "Check my inbox for anything new. Summarize the most recent thread in 2 sentences.",
    )]
})

Drafts

The draft tools let an agent compose iteratively, revise, and ship—useful when a model wants to stage a message and confirm before sending, or schedule delivery via send_at:
from langchain_agentmail import (
    AgentMailCreateDraftTool,
    AgentMailUpdateDraftTool,
    AgentMailSendDraftTool,
)

created = AgentMailCreateDraftTool().invoke({
    "inbox_id": "ib_abc123",
    "to": "alice@example.com",
    "subject": "Draft v1",
    "text": "First pass — will be revised before sending.",
})

# `created` is a JSON string; parse to get the draft_id
import json
draft_id = json.loads(created)["draft_id"]

AgentMailUpdateDraftTool().invoke({
    "inbox_id": "ib_abc123",
    "draft_id": draft_id,
    "subject": "Draft v2 — ready",
    "text": "Revised body. Sending now.",
})

AgentMailSendDraftTool().invoke({
    "inbox_id": "ib_abc123",
    "draft_id": draft_id,
})

Attachments

Outbound attachments can be passed as base64 file content or as a public URL. Inbound attachments are fetched via presigned download URLs:
import base64
from langchain_agentmail import AgentMailSendTool, SendAttachmentSpec

AgentMailSendTool().invoke({
    "inbox_id": "ib_abc123",
    "to": "alice@example.com",
    "subject": "Report attached",
    "text": "See the attached file.",
    "attachments": [
        SendAttachmentSpec(
            filename="report.txt",
            content_type="text/plain",
            content=base64.b64encode(b"hello").decode(),
        )
    ],
})

API reference

For detailed documentation of the AgentMail API, visit docs.agentmail.to. The Python package source lives at github.com/agentmail-to/langchain-agentmail.