Most up-to-date AI & Gen AI coaching for senior IT professionals
AI Agent for email assistance using LangGraph

Managing emails efficiently is crucial for professionals in today’s fast-paced digital world.
AI Agents for email assistants can help by classifying emails, responding to critical messages, and even scheduling meetings.
Namaste and Welcome to Build It Yourself.
In this guide, we’ll walk through the process of building an AI email assistant using LangChain (LangGraph) and OpenAI’s models.
If you are a senior It professional and looking to learn AI + LLM in a simple language, check out the courses and other details – https://www.aimletc.com/online-instructor-led-ai-llm-coaching-for-it-technical-professionals/
Building an AI Agent for email assistance
The AI agent we will build can perform the following tasks:
- Classify incoming emails
- Respond to important emails
- Notify the user about informative emails
- Ignore marketing or spam emails
- Draft responses for important emails
- Schedule meetings based on calendar availability
Workflow Breakdown – AI Agent for email assistance
The AI assistant follows a structured workflow:
- Triage Router: Determines whether to respond, notify, or ignore an email.
- Response Generation: If an email requires action, the assistant drafts an appropriate response.
- Meeting Scheduler: If the email requires scheduling a meeting, the assistant checks the user’s calendar availability.
Setting Up the Environment
Code Notebook – https://github.com/tayaln/email-assistant-ai-agent
Before coding, install the necessary libraries:
pip install langchain openai
We will be using OpenAI’s API, so ensure you have an API key:
import os
os.environ["OPENAI_API_KEY"] = "your-api-key-here"
Defining the User Profile and Triage Rules
We define the user profile and email classification rules:
user_profile = {
"name": "Rahul Dravid",
"background": "Senior Software Engineer leading a team of five developers"
}
triage_rules = {
"ignore": ["marketing newsletter", "spam email", "mass company announcements"],
"notify": ["team member out-of-office", "system notifications", "project status updates"],
"respond": ["direct questions", "meeting requests", "critical bug reports"]
}
Implementing Email Classification
We use GPT-4o-mini to classify incoming emails:
from langchain.schema import BaseModel
class EmailTriage(BaseModel):
def classify_email(self, email_content):
if any(keyword in email_content for keyword in triage_rules["ignore"]):
return "ignore"
elif any(keyword in email_content for keyword in triage_rules["notify"]):
return "notify"
else:
return "respond"
Implementing AI-Generated Responses
When an email requires a response, the AI drafts a reply:
from langchain.tools import Tool
def write_email(to, subject, content):
return f"To: {to}\nSubject: {subject}\n\n{content}"
write_email_tool = Tool(
name="Write Email",
func=write_email,
description="Writes and sends an email based on the given input."
)
Implementing Meeting Scheduling
To automate scheduling, we define a tool to check availability:
def check_calendar(day):
available_times = {"Tuesday": ["9 AM", "2 PM", "4 PM"]}
return available_times.get(day, "No availability")
calendar_tool = Tool(
name="Check Calendar",
func=check_calendar,
description="Checks available times for scheduling meetings."
)
Putting It All Together
Finally, we integrate all components into the AI assistant:
email = "Hi Rahul, I was reviewing the API documentation and noticed missing endpoints. Can you confirm?"
triage = EmailTriage().classify_email(email)
if triage == "respond":
response = write_email("anjali.singh@example.com", "Re: API Documentation", "I'll check with the development team and get back to you.")
print("Response Sent:", response)
elif triage == "notify":
print("Notification Sent to Rahul.")
elif triage == "ignore":
print("Email Ignored.")
Conclusion
We have successfully built an AI-powered email assistant using LangChain and OpenAI.
This assistant can classify emails, draft responses, and schedule meetings. Future improvements can include integrating it with email services like Gmail and Outlook.
Stay tuned for more AI automation tutorials!
If you have any queries or suggestions, share them with me on LinkedIn – https://www.linkedin.com/in/nikhileshtayal/
Let’s learn to build a basic AI/ML model in 4 minutes (Part 1)
Happy learning!