Skip to content
Deep Agents

Email Assistant with Deep Agents

Build an AI email assistant that searches your inbox, drafts replies, and manages email workflows — using Deep Agents.

emailautomationproductivityassistant

Working Code

Deep Agents
from deepagents import create_deep_agent
from langchain_core.tools import tool
@tool
def search_emails(query: str, limit: int = 5) -> str:
"""Search the inbox for emails matching a query."""
results = email_client.search(query, max_results=limit)
return "\n\n".join(
f"From: {e.sender}\nSubject: {e.subject}\nDate: {e.date}\nPreview: {e.body[:200]}"
for e in results
)
@tool
def draft_email(to: str, subject: str, body: str) -> str:
"""Create an email draft."""
draft_id = email_client.create_draft(to=to, subject=subject, body=body)
return f"Draft created (ID: {draft_id}). Review before sending."
agent = create_deep_agent(
model="anthropic:claude-sonnet-4-5-20250929",
tools=[search_emails, draft_email],
system_prompt="You are an email assistant. Search emails to find context, then help draft professional replies. Always create drafts — never send directly.",
)
result = agent.invoke({
"messages": [("user", "Find the latest email from the marketing team and draft a reply confirming the deadline")]
})
print(result["messages"][-1].content)

Step by Step

1

Install dependencies

Install Deep Agents and the required tools for this use case.

2

Define your tools

Create the domain-specific tool functions your agent will use to interact with external services.

3

Create the agent and run

Initialize the Deep Agents agent with your tools, set the system prompt, and execute a query.

Ready to build with Deep Agents?

Generate a production-ready project with Deep Agents pre-configured — FastAPI + Next.js, auth, streaming, and more.

Get Started

Ready to build your first production AI agent?

Open-source tools, battle-tested patterns, zero boilerplate. Configure your stack and ship in minutes — not months.