An intelligent AI assistant for email management built with LangGraph, featuring human-in-the-loop capabilities and persistent memory.
This project implements an email assistant that can automatically triage, respond to, and manage emails using Gmail API integration. The agent learns from user feedback and adapts to preferences over time through persistent memory storage.
Inspired by the LangChain Agents From Scratch course - This project builds upon the concepts and patterns demonstrated in the course, applying them to create a production-ready email management system.
- Smart Email Triage: Automatically classifies emails as ignore, notify, or respond
- Gmail Integration: Direct connection to Gmail API for email management
- Human-in-the-Loop: User review and approval for important actions using Agent Inbox UI
- Persistent Memory: Learns from user feedback and adapts preferences
- Calendar Integration: Schedule meetings and check availability
- Structured Responses: Generates professional email responses
The system uses LangGraph to orchestrate a multi-step workflow:
- Email Triage: Analyzes incoming emails and routes them appropriately
- Response Generation: Creates contextually appropriate responses
- Human Review: Allows user intervention for important decisions via Agent Inbox interface
- Memory Updates: Persists learning from user feedback
- Python 3.11+
- Gmail API credentials
- OpenAI API key
# Clone the repository
git clone <repository-url>
cd email-agent
# Install dependencies
pip install -e .
# Set up environment variables
cp .env.example .env
# Edit .env with your API keys- Set up Gmail API credentials following the Gmail Tools README
- Add your API keys to
.env:OPENAI_API_KEY=your_openai_api_key LANGSMITH_API_KEY=your_langsmith_api_key
from src.main import create_email_agent
# Create the agent
agent = create_email_agent()
# Process an email
result = agent.invoke({
"email_input": {
"id": "email_id",
"subject": "Meeting Request",
"from_email": "sender@example.com",
"content": "Can we schedule a meeting?"
}
})src/
├── main.py # Main agent implementation
├── prompts.py # System prompts and instructions
├── schemas.py # Pydantic models and state schemas
├── utils.py # Utility functions
└── tools/
├── base_tools.py # Core tool definitions
├── gmail_tools.py # Gmail API integration
└── gmail/ # Gmail setup and configuration
- State Management: Uses LangGraph's
MessagesStatefor conversation tracking - Memory System: Persistent storage for user preferences and learning
- Tool Integration: Modular tool system for email, calendar, and scheduling operations
- Human-in-the-Loop: Interrupt handlers for user review and approval using Agent Inbox