CrewAI
Email Assistant with CrewAI
Build an AI email assistant that searches your inbox, drafts replies, and manages email workflows — using CrewAI.
emailautomationproductivityassistant
Working Code
from crewai import Agent, Crew, Taskfrom langchain_openai import ChatOpenAIfrom langchain_core.tools import tool
@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 = Agent( role="Specialist", goal="You are an email assistant. Search emails to find context, then help draft professional replies. Always create drafts — never send directly.", tools=[search_emails, draft_email], llm=ChatOpenAI(model="gpt-4o"),)
task = Task( description="Find the latest email from the marketing team and draft a reply confirming the deadline", expected_output="Detailed response", agent=agent,)
crew = Crew(agents=[agent], tasks=[task])result = crew.kickoff()print(result.raw)Step by Step
1
Install dependencies
Install CrewAI 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 CrewAI agent with your tools, set the system prompt, and execute a query.
Build with other frameworks
Ready to build with CrewAI?
Generate a production-ready project with CrewAI 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.