Key Concepts
| Concept | Description |
|---|---|
| Email Triage | Categorizes emails by urgency and type |
| Priority Levels | 1-5 priority scale based on sender and content |
| Draft-Only Mode | Never auto-sends emails. Drafts require approval |
| Phishing Detection | Warns about suspicious emails |
Prerequisites
- Python 3.12+
- OpenAI API key
- Google OAuth credentials (for Gmail access)
Setup
1
Clone the repository
2
Create and activate virtual environment
3
Install dependencies
4
Set up Google OAuth credentials
- Go to Google Cloud Console
- Create a new project or select existing
- Enable the Gmail API:
- Go to “APIs & Services” > “Enable APIs and Services”
- Search for “Gmail API” and enable it
- Create OAuth credentials:
- Go to “APIs & Services” > “Credentials”
- Click “Create Credentials” > “OAuth client ID”
- Select “Desktop app” as application type
- Download the credentials
- Add redirect URI:
- Go to OAuth consent screen settings
- Add
http://127.0.0.1/as authorized redirect URI
5
Set environment variables
Run the Agent
The first run will open a browser window for OAuth authentication.Triage Inbox
Categorize and prioritize unread emails:- Retrieving unread emails
- Categorization (urgent, action_required, fyi, newsletter, spam)
- Priority scoring
Summarize Thread
Get a summary of an email conversation:- Fetching email threads
- Key point extraction
- Action item identification
Draft Response
Create a draft reply:- Context-aware draft generation
- Tone matching
- Draft storage (never auto-sends)
Agent Configuration
| Parameter | Purpose |
|---|---|
model | GPT-5.2 for email understanding and drafting |
GmailTools | Gmail API integration (read, search, draft, label) |
ReasoningTools | Plan triage and response approach |
read_chat_history | Remember previous email context |
How It Works
Email Categories
| Category | Criteria | Default Action |
|---|---|---|
| urgent | Time-sensitive, VIPs, deadlines | Surface immediately |
| action_required | Requests, questions | Queue for response |
| fyi | Updates, notifications, CC’d | Summarize briefly |
| newsletter | Marketing, subscriptions | Archive or summarize |
| spam | Unwanted promotional | Archive |
Priority Levels
| Level | Description | Timeframe |
|---|---|---|
| 1 | Critical | Immediate |
| 2 | High | 24-48 hours |
| 3 | Medium | Within a week |
| 4 | Low | Informational |
| 5 | Minimal | Archive/skip |
Gmail Tools
| Tool | Description |
|---|---|
get_unread_emails | Retrieve unread messages |
get_emails_by_thread | Get full thread |
search_emails | Search by query |
create_draft_email | Save draft (no send) |
send_email_reply | Reply to thread |
apply_label | Organize with labels |
mark_email_as_read | Mark processed |
Safety Features
- No auto-send: Emails are saved as drafts, never auto-sent
- Confirmation required: Sending requires explicit user approval
- Read-only default: Only reads emails unless action requested
- Phishing detection: Warns about suspicious emails
Troubleshooting
OAuth authentication fails
OAuth authentication fails
Verify your Google Cloud credentials are set correctly:Ensure the redirect URI is configured in Google Cloud Console.
Gmail API not enabled
Gmail API not enabled
Go to Google Cloud Console > APIs & Services > Enable APIs and Services > Search for “Gmail API” > Enable.
Token expired
Token expired
Delete Run the agent again to trigger OAuth flow.
token.json and re-authenticate: