Skip to main content

Documentation Index

Fetch the complete documentation index at: https://langchain-5e9cc07a-preview-docsad-1780072755-a0a75c0.mintlify.app/llms.txt

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

AgentMailLoader streams messages from an AgentMail inbox as LangChain Documents—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

ClassPackage
AgentMailLoaderlangchain-agentmail

Setup

Install the package:
pip install -qU langchain-agentmail
Set your AgentMail API key (get one at agentmail.to):
import getpass
import os

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

Instantiation

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

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:
for doc in loader.lazy_load():
    print(doc.metadata["subject"])

Indexing into a vector store

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.