A multi-user AI Email Agent Web application based on Gmail + Google Calendar, with LangGraph implementation for email analysis, reply draft generation, calendar event extraction, a Cursor-style executable Thread Chat Agent, and a global Assist Chat Agent (similar to Google Gemini).
Email-Agent/
├── backend/ # FastAPI + Python backend
│ ├── app/
│ │ ├── config.py # Configuration
│ │ ├── routes/ # API routes
│ │ ├── agents/ # LangGraph agents (to be implemented)
│ │ └── services/ # Service layer (Gmail, Calendar)
│ ├── main.py # FastAPI application
│ └── requirements.txt # Python dependencies
├── frontend/ # React frontend
│ ├── src/
│ │ ├── pages/ # Page components
│ │ └── services/ # API services
│ └── public/
├── client_secret.json # Google OAuth credentials (gitignored)
└── prd.md # Product requirements document
- Python 3.10 or higher
- Node.js (v18 or higher)
- npm or yarn
- Google Cloud Project with OAuth credentials
- Navigate to backend directory:
cd backend- Create virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Create
.envfile:
# Copy the example (if .env.example exists)
cp .env.example .env- Update
.envwith your configuration:
PORT=5000
DEBUG=True
FRONTEND_URL=http://localhost:3000
SESSION_SECRET=your-secret-key-change-in-production-
Ensure
client_secret.jsonis in the project root with your Google OAuth credentials. -
Start the server:
python main.pyOr with uvicorn:
uvicorn main:app --reload --port 5000The backend will run on http://localhost:5000
API documentation: http://localhost:5000/docs
- Navigate to frontend directory:
cd frontend- Install dependencies:
npm install- Create
.envfile:
# Copy the example (if .env.example exists)
cp .env.example .env- Update
.envif needed:
REACT_APP_API_URL=http://localhost:5000/api- Start the development server:
npm startThe frontend will run on http://localhost:3000
- Go to Google Cloud Console
- Create a new project or select an existing one
- Enable Gmail API and Calendar API
- Create OAuth 2.0 credentials (Web application)
- Add authorized redirect URI:
http://localhost:5000/api/auth/google/callback - Download credentials and save as
client_secret.jsonin the project root
https://www.googleapis.com/auth/gmail.readonlyhttps://www.googleapis.com/auth/gmail.composehttps://www.googleapis.com/auth/calendar.events
- ✅ Google OAuth authentication (FastAPI)
- ✅ Gmail API access test
- ✅ Calendar API access test
- ✅ Session management
- ✅ Multi-user support (session-based)
- ✅ LangGraph dependencies installed
- ✅ Service layer structure (Gmail, Calendar)
- ✅ Email display with details (subject, from, date, snippet)
For local development, use a local PostgreSQL database (free and fast):
-
Install PostgreSQL (macOS):
brew install postgresql@15 brew services start postgresql@15
-
Create database:
createdb email_agent
-
Configure
.envinbackend/directory:DATABASE_HOST=localhost DATABASE_PORT=5432 DATABASE_NAME=email_agent DATABASE_USER=postgres DATABASE_PASSWORD=your_password
-
Install dependencies and test:
cd backend pip install -r requirements.txt python test_db_connection.py -
Initialize database:
python init_database.py
📖 Detailed guide: See backend/LOCAL_DATABASE_SETUP.md
For production deployment, use GCP Cloud SQL: 📖 See backend/GCP_DATABASE_SETUP.md
- Database setup (PostgreSQL) - Use local for development
- Token storage in database
- LangGraph agent implementation
- Email triage agent
- Thread chat agent
- Assist chat agent (global AI assistant)
- Draft generation agent
- Calendar event extraction
- Inbox sync functionality
- Gmail service implementation
- Calendar service implementation
GET /api/auth/google/login- Initiate Google OAuth loginGET /api/auth/google/callback- OAuth callback handlerGET /api/auth/me- Get current authenticated userPOST /api/auth/logout- Logout current user
GET /api/auth/test/gmail- Test Gmail API accessGET /api/auth/test/calendar- Test Calendar API access
POST /api/gmail/sync- Sync inbox (to be implemented)GET /api/threads/{thread_id}- Get email thread (to be implemented)
POST /api/chat/thread- Thread Chat Agent conversation (to be implemented)POST /api/chat/confirm- Confirm and execute action (to be implemented)
POST /api/chat/assist- Assist Chat Agent conversation (to be implemented)POST /api/chat/assist/confirm- Confirm and execute action (to be implemented)GET /api/chat/assist/history- Get conversation history (to be implemented)
POST /api/calendar/events- Create calendar event (to be implemented)
POST /api/drafts/save- Save email draft (to be implemented)
GET /api/health- Health check endpoint
- FastAPI - Modern Python web framework
- Google APIs - Gmail and Calendar integration
- LangGraph - Agent orchestration framework
- LangChain - LLM framework
- Pydantic - Data validation
- React - UI framework
- React Router - Routing
- Axios - HTTP client
- Never commit
client_secret.jsonor.envfiles - Use strong
SESSION_SECRETin production - Enable HTTPS in production
- All write operations require user confirmation (human-in-the-loop)
- OAuth tokens are stored securely (currently in-memory, will be in database)
The backend uses FastAPI with automatic API documentation:
- Swagger UI:
http://localhost:5000/docs - ReDoc:
http://localhost:5000/redoc
- Create route file in
app/routes/ - Import and include in
main.py
- Create agent file in
app/agents/ - Implement using LangGraph framework
- Add routes in
app/routes/to expose agent endpoints
- Thread Chat Agent: Context-aware agent for specific email threads
- Assist Chat Agent: Global AI assistant (similar to Gemini) that can be opened anywhere in the app
ISC