Metadata-Version: 2.4
Name: langchain-agentmail
Version: 0.1.0
Summary: Official AgentMail integration for LangChain
License: MIT
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: agentmail-to>=0.1.0
Requires-Dist: langchain-core>=0.3.0
Requires-Dist: httpx>=0.25.0

# LangChain + AgentMail

Official AgentMail integration for [LangChain](https://python.langchain.com/). Give your AI agents the ability to create email inboxes, send and receive emails, and automate email-based workflows like OTP verification.

## Install

```bash
pip install langchain-agentmail
```

## Quick Start

```python
from langchain_agentmail import AgentMailToolkit

# Uses AGENTMAIL_API_KEY env var by default
toolkit = AgentMailToolkit()
tools = toolkit.get_tools()
```

### Create an Inbox

```python
result = tools[0].invoke({"name": "test-inbox"})  # CreateInbox
print(result)  # {"inbox_id": "...", "email": "..."}
```

### Send and Read Emails

```python
# Send an email
tools[1].invoke({"to": "user@example.com", "subject": "Hello", "body": "Hi there!", "from": "inbox_abc123"})

# Wait for a reply (blocks up to 60s)
msg = tools[6].invoke({"inbox_id": "inbox_abc123", "timeout": 60})
```

### Use with a LangGraph Agent

```python
from langgraph.prebuilt import create_react_agent
from langchain_openai import ChatOpenAI
from langchain_agentmail import AgentMailToolkit

toolkit = AgentMailToolkit()
agent = create_react_agent(ChatOpenAI(model="gpt-4o-mini"), toolkit.get_tools())

result = agent.invoke({"messages": [{"role": "user", "content": "Create an inbox and wait for a verification email"}]})
```

See [`example.py`](https://github.com/agentmail-to/langchain-agentmail/blob/main/src/langchain_agentmail/example.py) for a full OTP-automation agent.

## Environment Variables

| Variable | Description |
|---|---|
| `AGENTMAIL_API_KEY` | Your AgentMail API key (required) |

## Tools

| Tool | Description |
|---|---|
| `CreateInbox` | Create a new email inbox |
| `SendEmail` | Send an email |
| `ListMessages` | List messages in an inbox |
| `GetMessage` | Get a single message by ID |
| `ReplyToEmail` | Reply to a message |
| `ForwardEmail` | Forward a message |
| `WaitForMessage` | Block until a new message arrives |
| `SearchMessages` | Search messages by query |
| `CreateLabel` | Create an organizational label |
| `ApplyLabel` | Apply a label to a message |
| `DeleteInbox` | Delete an inbox permanently |

## License

MIT
