This guide provides a complete walkthrough for setting up, running, and using the Flux AI Email Automation system.
- Python 3.12+ installed
- Gmail Account with API access
- API Keys:
- Google Gemini API key
- Pinecone API key
- (Optional) Anthropic Claude API key for fallback
git clone https://github.com/NayaneshGupte/RAG-Demo.git
cd RAG-Demopython3.12 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activatepip install -r requirements.txtCreate a .env file in the project root:
# LLM Configuration
GOOGLE_API_KEY=your_gemini_api_key
ANTHROPIC_API_KEY=your_claude_api_key # Optional fallback
LLM_PRIMARY_PROVIDER=gemini
LLM_FALLBACK_PROVIDERS=claude
# Vector Database
PINECONE_API_KEY=your_pinecone_api_key
PINECONE_INDEX_NAME=your_index_name
VECTOR_DB_TYPE=pinecone
# Web Application
SECRET_KEY=your_secret_key_for_sessions
# Document Processing
CHUNK_SIZE=1000
CHUNK_OVERLAP=150Follow the OAuth Setup Guide to:
- Create a Google Cloud project
- Enable Gmail API
- Download
credentials.json - Place
credentials.jsonin the project root
Important: The first time you log in via the web interface, you'll be redirected to Google OAuth consent screen. After authorization, a token.json file will be created automatically.
The system consists of two main components that run concurrently:
source venv/bin/activate
python wsgi.pyAccess the application: http://127.0.0.1:5001
This will show the Landing Page with:
- Features showcase
- "How It Works" link
- "Connect Gmail" button for authentication
In a separate terminal:
source venv/bin/activate
python run.py agent --poll-interval 60The agent will:
- Poll for new emails every 60 seconds
- Process customer support inquiries
- Generate and send automated responses
- Log all activities to the database
- Open Dashboard: Navigate to http://127.0.0.1:5001
- Landing Page: You'll see the unauthenticated landing page
- Connect Gmail: Click the "Connect Gmail" button
- OAuth Flow:
- Redirected to Google OAuth consent screen
- Authorize Flux to access your Gmail account
- Redirected back to Dashboard upon success
- Dashboard Access: Now you can access http://127.0.0.1:5001/dashboard
- Automatic Redirect: If you visit
/, you'll be automatically redirected to/dashboardwhen authenticated - Session-Based: Your session persists until you logout or clear cookies
For testing without Gmail OAuth:
# Visit: http://127.0.0.1:5001/auth/demo/loginThis creates a demo session with email demo@example.com.
-
Navigate to Knowledge Base:
- From Dashboard, click "Knowledge Base" in the sidebar
- Or visit: http://127.0.0.1:5001/knowledge-base
-
Upload PDF:
- Click "Select PDF" or drag-and-drop a file
- Example: "Product_Return_Policy.pdf"
- Click "Upload & Ingest"
- Wait for success message: "β Ingested X chunks"
-
Verify Upload:
- Browse uploaded documents in the Knowledge Base viewer
- Check "Total Knowledge Chunks" count on Dashboard
A customer sends an email to your Gmail account:
From: customer@example.com
Subject: Need help with product return
Body:
Hi,
I received my order yesterday, but the product is defective.
How can I return it and get a refund?
Thanks,
John
The agent (running in background) automatically:
- Detects new unread email
- Classifies it as "Customer Support Inquiry"
- Retrieves relevant context from Knowledge Base (RAG):
- Searches for "return" and "refund" policies
- Finds top 3 relevant chunks from uploaded PDFs
- Generates response using Gemini (or Claude if quota exceeded)
- Sends threaded reply to customer
- Marks email as read
- Logs activity to database
-
View Dashboard: http://127.0.0.1:5001/dashboard
-
Key Metrics (updated every 30 seconds):
- Total Processed: 1
- Responded: 1
- Ignored: 0
-
Agent Status:
- π’ Agent Running
- Uptime: 2h 15m
- Last Poll: 5 seconds ago
-
Email Volume Chart:
- Interactive ApexCharts line chart
- Filter by date range (Today, 7D, 1M, 3M, etc.)
- See email processing trends
-
Recent Activity page:
- Navigate to http://127.0.0.1:5001/recent-activity
- View detailed log entry:
- Email Time: 2025-11-30 14:23:15
- Response Time: 2025-11-30 14:23:22
- Status: RESPONDED
- Customer: customer@example.com
- Subject: Need help with product return
- Category: Customer Support Inquiry
- Modern, visually appealing design
- Features showcase with glassmorphism effects
- "How It Works" link to workflow explanation
- "Connect Gmail" authentication button
- Real-Time Metrics: Auto-refresh every 30 seconds
- ApexCharts Visualizations:
- Email volume line chart
- Category distribution donut chart
- Agent Status Indicator: Running/Stopped with pulse animation
- Date Range Selector: Flatpickr integration for custom ranges
- Browse uploaded PDF documents
- Infinite scroll pagination (3 documents per load)
- Chunk preview with metadata
- Comprehensive activity logs
- Filter by status: All, Responded, Ignored, Failed
- Pagination support
- Search and date range filtering
- Step-by-step workflow explanation
- Visual screenshots of each step
- Feature highlights
- Primary: Google Gemini (gemini-1.5-flash)
- Fallback: Anthropic Claude (claude-3-5-sonnet)
- Automatic Switching: On quota errors (HTTP 429)
- Exponential Backoff: For transient errors
- Session-Based Auth: Each user sees only their data
- Database Filtering: All queries filtered by
agent_email - Multi-User Support: Multiple agents can run concurrently
- Landing Page (
/): Public, unauthenticated - Dashboard (
/dashboard): Protected, requires authentication - Client-Side Routing:
auth.jsmanages redirects automatically
To clear all email logs:
rm email_logs.dbThe database will be recreated automatically on next run.
Click "Logout" in the dashboard sidebar to:
- Clear session
- Redirect to landing page
- Require re-authentication
If your token.json expires or is deleted:
- Delete
token.json - Navigate to Dashboard
- Click "Connect Gmail"
- Complete OAuth flow again
- Check Agent Status: Verify "Agent Running" on dashboard
- Check Logs: Review terminal output for errors
- Verify Gmail Authentication: Ensure
token.jsonexists and is valid
- Clear Browser Cache: Hard refresh with Ctrl+Shift+R (Cmd+Shift+R on Mac)
- Check Console: Open browser DevTools β Console for JavaScript errors
- Verify Port: Ensure Flask is running on http://127.0.0.1:5001
- Check File Type: Only PDF files are supported
- Check File Size: Very large PDFs may take longer to process
- Check Logs: Review terminal output for processing errors
- OAuth Setup Guide - Detailed Gmail OAuth configuration
- Gmail Setup Guide - Gmail API setup
- Architecture Overview - System architecture
- Code Walkthrough - Critical code flows
- PRD - Product requirements and specifications
Need Help? Check the troubleshooting section or review the comprehensive documentation in the docs/ directory.