An intelligent email management system that uses RAG (Retrieval-Augmented Generation) and AI agents to help you search, analyze, and interact with your emails through natural language conversations.
- Gmail Integration: Fetch and parse emails from Gmail using the Gmail API
- AI-Powered Search: Use natural language to search through your emails
- RAG Architecture: Retrieval-Augmented Generation for context-aware responses
- Vector Search: FAISS-based semantic search for finding relevant emails
- Conversational AI: Chat with an AI agent about your emails
- Web Search Integration: Combine email data with web search results
- Multi-Model Support: Compatible with Groq, Llama, and other LLM providers
The project follows a modular architecture with the following components:
Email_Reader/
├── src/email_agent/
│ ├── agent/ # AI agent implementations
│ ├── config/ # Configuration and embedding models
│ ├── utils/ # Email fetching, parsing, and utilities
│ └── web/ # Web search functionality
├── scripts/ # Utility scripts
├── docs/ # Documentation
└── test/ # Test files
- BaseAgent: Main AI agent with RAG capabilities
- EmailFetcher: Gmail API integration for fetching emails
- EmailParser: Parse and structure email content
- VectorStore: FAISS-based semantic search index
- WebSearch: Google Custom Search integration
- Python 3.8+
- Gmail account with API access
- Groq API key (or other LLM provider)
- Google Custom Search API (optional, for web search)
-
Clone the repository
git clone <repository-url> cd Email_Reader
-
Install dependencies
pip install -r requirements.txt
-
Set up environment variables Create a
.envfile in the root directory:# Gmail API Configuration CONFIG_DIR=./src/email_agent/config # LLM Configuration GROQ_API_KEY=your_groq_api_key LLAMA3_8B=llama3-8b-8192 MODEL_DEEPSEEK1=deepseek-chat # Embedding Model EMBEDDING_MODEL_NAME=all-MiniLM-L6-v2 # Web Search (Optional) GOOGLE_API_KEY=your_google_api_key SEARCH_ENGINE_ID=your_search_engine_id WEB_DIR=./src/email_agent/web
-
Set up Gmail API credentials
- Download your
client_secret.jsonfrom Google Cloud Console - Place it in the project root
- Run the credential setup (first run will authenticate you)
- Download your
python -m src.email_agent.utils.email_fetcherThis will prompt you for:
- Number of emails to fetch
- Search query (default: Columbia emails)
python -m src.email_agent.utils.email_parserThis processes the fetched emails and creates structured data.
python -m src.email_agent.mainThis launches the interactive chat interface where you can:
- Ask questions about your emails
- Search for specific content
- Get AI-powered insights
python -m src.email_agent.web.searchCombine email data with web search results for comprehensive answers.
You: Find emails about project deadlines
Agent: I found 3 emails related to project deadlines. Here are the key details...
You: What was the last communication from John?
Agent: The most recent email from John was about...
You: Summarize all emails from this week
Agent: Here's a summary of this week's emails...
Configure agent behavior in config/rules_agents.json:
[
{
"role": "system",
"content": "You are a helpful email assistant..."
}
]The system supports multiple embedding models:
all-MiniLM-L6-v2(default)Qwen3-Embedding-0.6B- Custom models
Emails are indexed using FAISS for fast semantic search. The index is automatically updated when new emails are added.
- Email Fetching: Gmail API → Email IDs and metadata
- Email Parsing: Raw emails → Structured EmailSample objects
- Vector Indexing: Email content → FAISS vector store
- Query Processing: User input → Semantic search → RAG response
- AI Response: Context + Query → LLM → Natural language response
- API keys are stored in environment variables
- Gmail credentials are handled securely through OAuth2
- No sensitive data is logged or stored in plain text
Run tests to verify functionality:
python -m pytest test/langchain-community>=0.3.1- LangChain community componentslangchain-groq>=0.3.1- Groq LLM integrationlangchain-huggingface>=0.3.1- HuggingFace embeddingsgroq>=0.1.1- Groq API client
google-api-python-client==2.174.0- Gmail API clientgoogle-auth==2.40.3- Google authentication
dotenv>=1.0.1- Environment variable managementjsonpath-ng>=1.6.0- JSON path processingrequests>=2.18.0- HTTP requests
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
-
Gmail API Quota Exceeded
- Check your Gmail API quota in Google Cloud Console
- Reduce the number of emails fetched
-
Embedding Model Not Found
- Ensure the model name is correct
- Check if the model is available in your environment
-
Vector Store Errors
- Delete the existing FAISS index to rebuild
- Check file permissions in the config directory
- Check the logs for detailed error messages
- Verify all environment variables are set correctly
- Ensure all dependencies are installed
- Multi-agent collaboration
- Task delegation capabilities
- Enhanced contextual reasoning
- Email summarization
- Sentiment analysis
- Email categorization
- Integration with other email providers