-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add AgentMail integration docs (provider, toolkit, loader, retriever) #4055
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Naomi Pentrel (npentrel)
merged 5 commits into
langchain-ai:main
from
agentmail-to:agentmail/integration-docs
May 29, 2026
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
60f9390
Add AgentMail integration docs (provider, toolkit, loader, retriever)
josephfeleke 35c1195
Merge branch 'main' into agentmail/integration-docs
npentrel e0f4584
Apply suggestions from code review
npentrel 32ba079
Apply suggestions from code review
npentrel 1705b32
Apply suggestions from code review
npentrel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/oss/python/integrations/document_loaders/agentmail.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| --- | ||
| title: "AgentMail" | ||
| description: "Load messages from an AgentMail inbox as LangChain Documents." | ||
| --- | ||
|
|
||
| `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. | ||
|
|
||
| ## Overview | ||
|
|
||
| | Class | Package | | ||
| |:------|:--------| | ||
| | `AgentMailLoader` | [`langchain-agentmail`](https://pypi.org/project/langchain-agentmail/) | | ||
|
|
||
| ## Setup | ||
|
|
||
| Install the package: | ||
|
|
||
| ```bash | ||
| pip install -qU langchain-agentmail | ||
| ``` | ||
|
|
||
| Set your AgentMail API key (get one at [agentmail.to](https://agentmail.to)): | ||
|
|
||
| ```python | ||
| import getpass | ||
| import os | ||
|
|
||
| if not os.environ.get("AGENTMAIL_API_KEY"): | ||
| os.environ["AGENTMAIL_API_KEY"] = getpass.getpass("AgentMail API key:\n") | ||
| ``` | ||
|
|
||
| ## Instantiation | ||
|
|
||
| ```python | ||
| from langchain_agentmail import AgentMailLoader | ||
|
|
||
| loader = AgentMailLoader( | ||
| inbox_id="ib_abc123", | ||
| labels=["inbox"], # optional — filter messages by label | ||
| limit=100, # optional — cap the number of messages loaded | ||
| ) | ||
| ``` | ||
|
|
||
| ## Load | ||
|
|
||
| ```python | ||
| docs = loader.load() | ||
| print(docs[0].page_content[:200]) | ||
| print(docs[0].metadata) | ||
| ``` | ||
|
|
||
| Each `Document` includes the following metadata keys (when present): | ||
|
|
||
| - `inbox_id`, `message_id`, `thread_id` | ||
| - `from`, `to`, `cc`, `subject`, `labels`, `timestamp` | ||
| - `has_attachments`, `attachments`: a list of `{attachment_id, filename, content_type, size}` | ||
|
|
||
| To download attachment bytes, pair the loader with `AgentMailGetAttachmentTool` from the toolkit—it returns a presigned download URL. | ||
|
|
||
| ## Lazy load | ||
|
|
||
| For larger inboxes, stream documents one at a time instead of materializing the full list: | ||
|
|
||
| ```python | ||
| for doc in loader.lazy_load(): | ||
| print(doc.metadata["subject"]) | ||
| ``` | ||
|
|
||
| ## Indexing into a vector store | ||
|
|
||
| ```python | ||
| from langchain_core.vectorstores import InMemoryVectorStore | ||
| from langchain_openai import OpenAIEmbeddings | ||
|
|
||
| docs = AgentMailLoader(inbox_id="ib_abc123", limit=200).load() | ||
|
|
||
| store = InMemoryVectorStore.from_documents(docs, OpenAIEmbeddings()) | ||
| retriever = store.as_retriever(search_kwargs={"k": 5}) | ||
|
|
||
| retriever.invoke("Q3 invoice from acme") | ||
| ``` | ||
|
|
||
| ## API reference | ||
|
|
||
| The package source lives at [github.com/agentmail-to/langchain-agentmail](https://github.com/agentmail-to/langchain-agentmail). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| --- | ||
| title: "AgentMail integrations" | ||
| description: "Integrate with AgentMail using LangChain Python." | ||
| --- | ||
|
|
||
| [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. | ||
|
|
||
| ## Installation and setup | ||
|
|
||
| <CodeGroup> | ||
| ```bash pip | ||
| pip install langchain-agentmail | ||
| ``` | ||
|
|
||
| ```bash uv | ||
| uv add langchain-agentmail | ||
| ``` | ||
| </CodeGroup> | ||
|
|
||
| Get your API key from [agentmail.to](https://agentmail.to) and set it as an environment variable: | ||
|
|
||
| ```bash | ||
| export AGENTMAIL_API_KEY="your-api-key" | ||
| ``` | ||
|
|
||
| ## Tools | ||
|
|
||
| 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. | ||
|
|
||
| ## Document loader | ||
|
|
||
| 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. | ||
|
npentrel marked this conversation as resolved.
Outdated
|
||
|
|
||
| ## Retriever | ||
|
|
||
| See the [AgentMail Retriever](/oss/integrations/retrievers/agentmail) guide for keyword search over an inbox. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| --- | ||
| title: "AgentMail" | ||
| description: "Keyword retriever over an AgentMail inbox." | ||
| --- | ||
|
|
||
| `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. | ||
|
|
||
| ## Overview | ||
|
|
||
| | Class | Package | | ||
| |:------|:--------| | ||
| | `AgentMailRetriever` | [`langchain-agentmail`](https://pypi.org/project/langchain-agentmail/) | | ||
|
|
||
| ## Setup | ||
|
|
||
| Install the package: | ||
|
|
||
| ```bash | ||
| pip install -qU langchain-agentmail | ||
| ``` | ||
|
|
||
| Set your AgentMail API key (get one at [agentmail.to](https://agentmail.to)): | ||
|
|
||
| ```python | ||
| import getpass | ||
| import os | ||
|
|
||
| if not os.environ.get("AGENTMAIL_API_KEY"): | ||
| os.environ["AGENTMAIL_API_KEY"] = getpass.getpass("AgentMail API key:\n") | ||
| ``` | ||
|
|
||
| ## Instantiation | ||
|
|
||
| ```python | ||
| from langchain_agentmail import AgentMailRetriever | ||
|
|
||
| retriever = AgentMailRetriever( | ||
| inbox_id="ib_abc123", | ||
| k=5, # number of documents to return | ||
| labels=["inbox"], # optional — filter messages by label | ||
| scan_limit=50, # number of messages to scan before ranking | ||
| ) | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| ```python | ||
| docs = retriever.invoke("invoice from acme") | ||
| for doc in docs: | ||
| print(doc.metadata["subject"], "—", doc.metadata.get("from")) | ||
| ``` | ||
|
|
||
| The retriever returns the same `Document` shape as `AgentMailLoader` — full plain-text body in `page_content`, plus inbox/message/thread/sender metadata. | ||
|
|
||
| ## When to use the loader instead | ||
|
|
||
| `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. | ||
|
|
||
| ## API reference | ||
|
|
||
| The package source lives at [github.com/agentmail-to/langchain-agentmail](https://github.com/agentmail-to/langchain-agentmail). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.