Skip to content

Commit c7adb96

Browse files
authored
Add AgentMail integration docs (provider, toolkit, loader, retriever) (#4055)
1 parent e07a5ff commit c7adb96

9 files changed

Lines changed: 397 additions & 0 deletions

File tree

packages.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,3 +792,6 @@ packages:
792792
js: "@oracle/langchain-oracledb"
793793
downloads: 44000
794794
downloads_updated_at: "2026-05-18T00:23:32.797657+00:00"
795+
- name: langchain-agentmail
796+
repo: agentmail-to/langchain-agentmail
797+
js: "n/a"
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
title: "AgentMail"
3+
description: "Load messages from an AgentMail inbox as LangChain Documents."
4+
---
5+
6+
`AgentMailLoader` streams messages from an [AgentMail](https://agentmail.to) inbox as LangChain `Document`s—one document per message, plain-text body as `page_content`, sender / subject / labels / thread / attachment metadata on `metadata`. Useful for indexing an inbox into a vector store for RAG over email.
7+
8+
## Overview
9+
10+
| Class | Package |
11+
|:------|:--------|
12+
| `AgentMailLoader` | [`langchain-agentmail`](https://pypi.org/project/langchain-agentmail/) |
13+
14+
## Setup
15+
16+
Install the package:
17+
18+
```bash
19+
pip install -qU langchain-agentmail
20+
```
21+
22+
Set your AgentMail API key (get one at [agentmail.to](https://agentmail.to)):
23+
24+
```python
25+
import getpass
26+
import os
27+
28+
if not os.environ.get("AGENTMAIL_API_KEY"):
29+
os.environ["AGENTMAIL_API_KEY"] = getpass.getpass("AgentMail API key:\n")
30+
```
31+
32+
## Instantiation
33+
34+
```python
35+
from langchain_agentmail import AgentMailLoader
36+
37+
loader = AgentMailLoader(
38+
inbox_id="ib_abc123",
39+
labels=["inbox"], # optional — filter messages by label
40+
limit=100, # optional — cap the number of messages loaded
41+
)
42+
```
43+
44+
## Load
45+
46+
```python
47+
docs = loader.load()
48+
print(docs[0].page_content[:200])
49+
print(docs[0].metadata)
50+
```
51+
52+
Each `Document` includes the following metadata keys (when present):
53+
54+
- `inbox_id`, `message_id`, `thread_id`
55+
- `from`, `to`, `cc`, `subject`, `labels`, `timestamp`
56+
- `has_attachments`, `attachments`: a list of `{attachment_id, filename, content_type, size}`
57+
58+
To download attachment bytes, pair the loader with `AgentMailGetAttachmentTool` from the toolkit—it returns a presigned download URL.
59+
60+
## Lazy load
61+
62+
For larger inboxes, stream documents one at a time instead of materializing the full list:
63+
64+
```python
65+
for doc in loader.lazy_load():
66+
print(doc.metadata["subject"])
67+
```
68+
69+
## Indexing into a vector store
70+
71+
```python
72+
from langchain_core.vectorstores import InMemoryVectorStore
73+
from langchain_openai import OpenAIEmbeddings
74+
75+
docs = AgentMailLoader(inbox_id="ib_abc123", limit=200).load()
76+
77+
store = InMemoryVectorStore.from_documents(docs, OpenAIEmbeddings())
78+
retriever = store.as_retriever(search_kwargs={"k": 5})
79+
80+
retriever.invoke("Q3 invoice from acme")
81+
```
82+
83+
## API reference
84+
85+
The package source lives at [github.com/agentmail-to/langchain-agentmail](https://github.com/agentmail-to/langchain-agentmail).

src/oss/python/integrations/document_loaders/index.mdx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ for document in loader.lazy_load():
3434

3535
## By category
3636

37+
### Productivity tools
38+
39+
The below document loaders allow you to load data from commonly used productivity tools.
40+
41+
| Document Loader | API reference |
42+
|----------------|---------------|
43+
| [AgentMail](/oss/integrations/document_loaders/agentmail) | [`AgentMailLoader`](https://github.com/agentmail-to/langchain-agentmail) |
44+
3745
### Webpages
3846

3947
The below document loaders allow you to load webpages.
@@ -82,6 +90,7 @@ The below document loaders allow you to load data from common data formats.
8290
## All document loaders
8391

8492
<Columns cols={3}>
93+
<Card title="AgentMail" icon="link" href="/oss/integrations/document_loaders/agentmail" arrow="true" cta="View guide" />
8594
<Card title="AgentQLLoader" icon="link" href="/oss/integrations/document_loaders/agentql" arrow="true" cta="View guide" />
8695
<Card title="AirbyteLoader" icon="link" href="/oss/integrations/document_loaders/airbyte" arrow="true" cta="View guide" />
8796
<Card title="Apify Dataset" icon="link" href="/oss/integrations/document_loaders/apify_dataset" arrow="true" cta="View guide" />
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
title: "AgentMail integrations"
3+
description: "Integrate with AgentMail using LangChain Python."
4+
---
5+
6+
[AgentMail](https://agentmail.to) is an inbox-as-an-API platform built for AI agents—provisioning, sending, replying, drafting, and inbound webhooks all available over a single HTTP API. The `langchain-agentmail` package wraps the AgentMail SDK as LangChain tools, plus a document loader and a retriever over an inbox.
7+
8+
## Installation and setup
9+
10+
<CodeGroup>
11+
```bash pip
12+
pip install langchain-agentmail
13+
```
14+
15+
```bash uv
16+
uv add langchain-agentmail
17+
```
18+
</CodeGroup>
19+
20+
Get your API key from [agentmail.to](https://agentmail.to) and set it as an environment variable:
21+
22+
```bash
23+
export AGENTMAIL_API_KEY="your-api-key"
24+
```
25+
26+
## Tools
27+
28+
See the [AgentMail Toolkit](/oss/integrations/tools/agentmail) guide for details on the available tools, including sending and replying to messages, managing drafts, attachments, and labels.
29+
30+
## Document loader
31+
32+
See the [AgentMail Document Loader](/oss/integrations/document_loaders/agentmail) guide for loading messages from an inbox as LangChain `Document`s—useful for indexing into a vector store for RAG over email.
33+
34+
## Retriever
35+
36+
See the [AgentMail Retriever](/oss/integrations/retrievers/agentmail) guide for keyword search over an inbox.

src/oss/python/integrations/providers/all_providers.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ Browse the complete collection of integrations available for Python. LangChain P
4141
Open event-based protocol for connecting LangGraph agents to any frontend.
4242
</Card>
4343

44+
<Card
45+
title="AgentMail"
46+
href="/oss/integrations/providers/agentmail"
47+
icon="link"
48+
>
49+
Inbox-as-an-API platform for AI agents — sending, replying, drafts, attachments, and inbound webhooks.
50+
</Card>
51+
4452
<Card
4553
title="AgentPhone"
4654
href="/oss/integrations/providers/agentphone"
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
title: "AgentMail"
3+
description: "Keyword retriever over an AgentMail inbox."
4+
---
5+
6+
`AgentMailRetriever` performs a keyword search over an [AgentMail](https://agentmail.to) inbox. It loads recent messages via `AgentMailLoader`, scores them in-process with a case-insensitive substring match (subject hits weighted 2×), and returns the top-`k` as LangChain `Document`s. For semantic search, pair `AgentMailLoader` with your own vector store instead.
7+
8+
## Overview
9+
10+
| Class | Package |
11+
|:------|:--------|
12+
| `AgentMailRetriever` | [`langchain-agentmail`](https://pypi.org/project/langchain-agentmail/) |
13+
14+
## Setup
15+
16+
Install the package:
17+
18+
```bash
19+
pip install -qU langchain-agentmail
20+
```
21+
22+
Set your AgentMail API key (get one at [agentmail.to](https://agentmail.to)):
23+
24+
```python
25+
import getpass
26+
import os
27+
28+
if not os.environ.get("AGENTMAIL_API_KEY"):
29+
os.environ["AGENTMAIL_API_KEY"] = getpass.getpass("AgentMail API key:\n")
30+
```
31+
32+
## Instantiation
33+
34+
```python
35+
from langchain_agentmail import AgentMailRetriever
36+
37+
retriever = AgentMailRetriever(
38+
inbox_id="ib_abc123",
39+
k=5, # number of documents to return
40+
labels=["inbox"], # optional — filter messages by label
41+
scan_limit=50, # number of messages to scan before ranking
42+
)
43+
```
44+
45+
## Usage
46+
47+
```python
48+
docs = retriever.invoke("invoice from acme")
49+
for doc in docs:
50+
print(doc.metadata["subject"], "", doc.metadata.get("from"))
51+
```
52+
53+
The retriever returns the same `Document` shape as `AgentMailLoader` — full plain-text body in `page_content`, plus inbox/message/thread/sender metadata.
54+
55+
## When to use the loader instead
56+
57+
`AgentMailRetriever` is the "just give me recent messages matching X" escape hatch — no embeddings, no vector store. If you need semantic retrieval, ranking by relevance, or filtering across millions of messages, use `AgentMailLoader` to materialize `Document`s and feed them into a real vector store. See the [document loader page](/oss/integrations/document_loaders/agentmail) for that flow.
58+
59+
## API reference
60+
61+
The package source lives at [github.com/agentmail-to/langchain-agentmail](https://github.com/agentmail-to/langchain-agentmail).

src/oss/python/integrations/retrievers/index.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ The below retrievers will search over an external index (e.g., constructed from
4040
## All retrievers
4141

4242
<Columns cols={3}>
43+
<Card title="AgentMail" icon="link" href="/oss/integrations/retrievers/agentmail" arrow="true" cta="View guide" />
4344
<Card title="Bedrock (Knowledge Bases)" icon="link" href="/oss/integrations/retrievers/bedrock" arrow="true" cta="View guide" />
4445
<Card title="Box" icon="link" href="/oss/integrations/retrievers/box" arrow="true" cta="View guide" />
4546
<Card title="Cognee" icon="link" href="/oss/integrations/retrievers/cognee" arrow="true" cta="View guide" />

0 commit comments

Comments
 (0)