Overview
What it is: An AI-powered inbox triage + response drafting + routing system.
Goal: Classify every inbound email, extract key details, draft a safe high-quality reply, and route to the right workflow (sales/support/billing/etc.).
Why it matters: Creates “lead coverage” for email so messages get acknowledged fast and high-value threads escalate instantly.
Architecture (5-layer system)
- Intake (email ingestion + normalization)
- Ingests from Gmail/Outlook, shared mailboxes, and form-to-email.
- Normalizes each message into a structured record:
thread_id, message_id, sender, subject, cleaned body, attachments metadata, timestamp, mailbox
- Prior thread context (last N messages)
- Cleans content by stripping signatures, quoted replies, tracking pixels, and optional forwarded chains.
- Pre-processing + safety filters (deterministic rules)
- Spam / threat / noise filters
- Known spam patterns, blacklisted domains, suspicious formatting, excessive links, sender mismatch.
- Compliance / risk guardrails
- Detect payment/sensitive-info requests, legal threats, refund disputes.
- Blocks auto-send and forces human review on risky categories.
- Identity + relationship checks
- Existing customer, CRM known sender, reply to outbound, net-new inbound lead.
- Produces a preliminary safety tag:
safe_to_draft, requires_human_review, spam_ignore
- AI understanding (intent classification + extraction)
- Uses GPT as a structured classifier, returning strict JSON:
- intent category (sales/support/billing/partnership/hiring/spam)
- urgency, sentiment, action required
- key fields (company, product, issue type, budget indicator, timeline)
- Generates a 1–2 sentence human summary.
- Response composer (draft replies + templates)
- Template-first routing by intent (sales/support/billing/partnership/not-a-fit).
- AI-enhanced personalization fills templates with constraints:
- short, professional, minimal fluff
- references the exact ask
- clear next step
- no hallucinated promises
- no legal/financial commitments
- no passwords/payment links
- Link + scheduling injection
- Sales: calendar link only after qualification.
- Support: create ticket + request missing info (account email, screenshots).
- Routing, handoff, and logging (ops layer)
- Executes routing actions and creates operational artifacts:
- CRM create/update + owner assignment + tags
- Helpdesk ticket creation + categorization
- Finance routing for billing
- Slack notifications (summary + draft)
- Logs everything for auditability:
- classification result, draft version, routing outcome, response time, resolution time (optional)
End-to-end flow
- New email arrives → webhook triggers ingestion + cleaning + thread context.
- Safety filters run first (spam/risk/relationship).
- AI classifies + extracts structured fields + recommended action.
- Draft generated via template + constrained personalization.
- Routing executes (CRM, Slack, tasks, tickets).
- Optional human review gate:
- Safe items can be auto-sent (optional mode).
- Risky items go to Drafts with an explanation.
Key components (conceptual)
inbox_agent/email_ingest.py
inbox_agent/text_cleaner.py