LangGraph
Email Assistant with LangGraph
Build an AI email assistant that searches your inbox, drafts replies, and manages email workflows — using LangGraph.
emailautomationproductivityassistant
Working Code
from langchain_openai import ChatOpenAIfrom langchain_core.tools import toolfrom langgraph.prebuilt import create_react_agent
@tooldef 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 )
@tooldef 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_react_agent( ChatOpenAI(model="gpt-4o"), tools=[search_emails, draft_email], prompt="You are an email assistant. Search emails to find context, then help draft professional replies. Always create drafts — never send directly.",)
result = await agent.ainvoke({ "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 LangGraph 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 LangGraph agent with your tools, set the system prompt, and execute a query.
Build with other frameworks
Ready to build with LangGraph?
Generate a production-ready project with LangGraph pre-configured — FastAPI + Next.js, auth, streaming, and more.
Get StartedReady to build your first production AI agent?
Open-source tools, battle-tested patterns, zero boilerplate. Configure your stack and ship in minutes — not months.