An intelligent email automation system powered by LangGraph and LLM agents with supervisor coordination.
- Supervisor Pattern: Dynamic agent coordination with intelligent routing
- Smart Categorization: Automatically categorizes emails (inquiries, complaints, feedback)
- RAG-Powered Responses: Uses retrieval-augmented generation for accurate answers
- Quality Assurance: AI proofreader ensures professional responses
- Gmail Integration: Seamless inbox monitoring and reply drafting
- Flexible Workflow: Supervisor adapts routing based on context and agent feedback
The system uses a supervisor pattern where a supervisor agent coordinates specialized worker agents:
┌─────────────┐
│ Load Emails │
└──────┬──────┘
│
▼
┌─────────────┐
│ Check Inbox │
└──────┬──────┘
│
▼
┌─────────────────┐
│ SUPERVISOR │◀──────────┐
│ (Coordinator) │ │
└──────┬──────────┘ │
│ │
│ Routes dynamically │
│ │
┌───┴───┬─────────┬─────────┴───┐
▼ ▼ ▼ ▼
┌──────┐ ┌──────┐ ┌──────┐ ┌────────┐
│ Cat. │ │ RAG │ │Write │ │Proofread│
└──┬───┘ └──┬───┘ └──┬───┘ └────┬───┘
│ │ │ │
└────────┴────────┴─────────────┘
│
▼
┌─────────┐
│ Send │
└─────────┘
- Dynamic Routing: Supervisor makes context-aware decisions
- Agent Coordination: Workers can request supervisor guidance
- Quality Control: Supervisor monitors workflow quality
- Flexibility: Adapts to edge cases and complex scenarios
- No Rigid Flow: Avoids "robotics only working" limitations
- LangChain & LangGraph - AI workflow orchestration
- Groq API - LLM inference (Llama 3.3)
- Google Gemini - Embeddings for RAG
- ChromaDB - Vector storage
- Gmail API - Email integration
- FastAPI - API deployment
- Python 3.9+
- Groq API key
- Google Gemini API key
- Gmail API credentials
# Clone repository
git clone https://github.com/pauxd26/ai-email-agent
cd ai-email-agent
# Create virtual environment
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txtCreate a .env file:
MY_EMAIL=your_email@gmail.com
GROQ_API_KEY=your_groq_key
GOOGLE_API_KEY=your_gemini_keypython create_index.py# CLI mode
python main.py
# API mode
python deploy_api.pyai-email-agent/
├── src/
│ ├── agents.py # AI agent definitions (with supervisor)
│ ├── graph.py # Supervisor-based LangGraph workflow
│ ├── nodes.py # Graph node functions
│ ├── prompts.py # LLM prompts (including supervisor)
│ ├── state.py # State definitions (with supervisor context)
│ ├── structure_outputs.py # Pydantic schemas
│ └── tools/
│ └── gmail_tools.py # Gmail integration
├── data/
│ └── knowledge_base.txt # RAG knowledge source
├── main.py # CLI entry point
├── create_index.py # Build vector index
├── deploy_api.py # API server
└── requirements.txt
The supervisor pattern enables:
- Context-Aware Routing: Supervisor analyzes state and routes to appropriate agents
- Dynamic Workflow: No fixed sequence - adapts to each email's needs
- Quality Monitoring: Supervisor tracks agent performance and workflow quality
- Error Handling: Supervisor can redirect workflow when issues arise
- Agent Communication: Workers can flag issues for supervisor review
This version migrated from a rigid workflow to supervisor pattern to:
- Handle edge cases more gracefully
- Provide more flexible routing
- Enable better quality control
- Support complex multi-step scenarios