AI Email Triage & Grounded Auto-Reply Agent
This project hands inbox triage to an AI: a pipeline that reads every email landing in a connected Gmail account, classifies it, and either acts on it or drafts a grounded reply.
Challenge
Spam, invoices, general messages, and questions about internal documentation all land in the same inbox, and each needs different handling. The system had to ingest real-time email events over a webhook, classify them reliably, and either act immediately or answer from a real knowledge base — without a human reading each message first.
Our Approach
Nylas connects to Gmail and turns new messages into signed webhooks, received by a FastAPI endpoint that verifies the signature and queues the event on Celery/Redis. A workflow then classifies the email with a PydanticAI agent (gpt-4o-mini) and routes it to the right handler: delete (spam), download the attachment (invoice), send an acknowledgement (general), or answer from a pgvector knowledge base via a second agent (gpt-5.1) that grounds its reply and flags low-confidence answers for manual follow-up.
Results & Impact
- < 3 second response time for inbound emails
- End-to-end flow verified against captured webhook events for each category
- Grounded answers backed by internal documentation
- Deployed on a Hetzner VPS behind Caddy, with Sentry and Langfuse for observability
- 100% accuracy on evaluation
Solution Overview
Gmail
→ Nylas (webhooks) → FastAPI (/events) → Postgres + Celery/Redis
→ EmailWorkflow: Filter → Classify (gpt-4o-mini) → Route
→ Spam (delete) / Invoice (download) / General (reply)
→ RAG with internal docs (gpt-5.1 + pgvector)
→ back through Nylas → Gmail
Tech Stack
- Nylas API (email/calendar, OAuth, webhooks)
- Python, FastAPI, Celery, Redis
- PostgreSQL + pgvector (Supabase)
- PydanticAI, OpenAI (
gpt-4o-mini,gpt-5.1,text-embedding-3-small) - GenAI Launchpad framework (Datalumina)
- Docker, Caddy, Hetzner Cloud
- Sentry, Langfuse
-
Let's have a virtual coffee together!
Want to see if we're a match? Let's have a chat and find out. Schedule a free 30-minute strategy session to discuss your AI challenges and explore how we can work together.