<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nambirajan R S</title>
    <description>The latest articles on DEV Community by Nambirajan R S (@nambirajan_rs_44d819feba).</description>
    <link>https://dev.to/nambirajan_rs_44d819feba</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3649148%2F916af4ba-6400-44af-9bd6-fe2289ba63b5.jpg</url>
      <title>DEV Community: Nambirajan R S</title>
      <link>https://dev.to/nambirajan_rs_44d819feba</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nambirajan_rs_44d819feba"/>
    <language>en</language>
    <item>
      <title>📩 Email Automation Agent — A Multi-Agent System to Read, Categorize, Extract &amp; Auto-Escalate Emails</title>
      <dc:creator>Nambirajan R S</dc:creator>
      <pubDate>Sat, 06 Dec 2025 11:53:07 +0000</pubDate>
      <link>https://dev.to/nambirajan_rs_44d819feba/email-automation-agent-a-multi-agent-system-to-read-categorize-extract-auto-escalate-emails-2aak</link>
      <guid>https://dev.to/nambirajan_rs_44d819feba/email-automation-agent-a-multi-agent-system-to-read-categorize-extract-auto-escalate-emails-2aak</guid>
      <description>&lt;p&gt;🧠 &lt;strong&gt;Reflection — What I Learned from the AI Agents Intensive&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before the AI Agents Intensive, I mostly saw LLMs as “smart prediction models.” The course completely changed my perspective. I learned how agentic systems break complex workflows into smaller, specialized roles, how to design autonomous pipelines, and how to use structured prompting to create deterministic, production-ready systems.&lt;/p&gt;

&lt;p&gt;The biggest mindset shift for me:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;“Don’t build monolithic LLM flows. Build specialized agents that communicate.”&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The course helped me understand:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How role-based agents dramatically improve accuracy&lt;/li&gt;
&lt;li&gt;Why handoffs and memory matter for reliability&lt;/li&gt;
&lt;li&gt;How to design for traceability, safety, and auditability&lt;/li&gt;
&lt;li&gt;When to combine LLM extraction with regex + validation&lt;/li&gt;
&lt;li&gt;How multi-agent workflows reduce hallucinations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This reflection directly influenced my project design below.&lt;/p&gt;

&lt;p&gt;🚀** Project — Email Automation Agent**&lt;/p&gt;

&lt;p&gt;A multi-agent system that processes incoming emails, extracts important details, and identifies urgent cases that require escalation — helping automate business communication workflows.&lt;/p&gt;

&lt;p&gt;🎯 &lt;strong&gt;Project Goals&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This agent performs three core tasks:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Read &amp;amp; Categorize incoming emails&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;(e.g., Billing, Support, HR, Sales, Other)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Extract key details&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Invoice numbers&lt;/li&gt;
&lt;li&gt;Amounts&lt;/li&gt;
&lt;li&gt;Dates / due dates&lt;/li&gt;
&lt;li&gt;Vendor / sender names&lt;/li&gt;
&lt;li&gt;Action items&lt;/li&gt;
&lt;li&gt;Attachments&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Detect urgent / escalated emails&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;(Overdue payments, angry tone, deadlines, SLA breaches)&lt;/p&gt;

&lt;p&gt;All outputs are structured in machine-readable JSON, making the agent suitable for real automation systems.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Multi-Agent Architecture&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Below is the architecture of the system — completely agent-driven:&lt;/p&gt;

&lt;p&gt;+-----------+      +-------------+      +--------------+      +---------------+      +-------------+&lt;br&gt;
|  Email    | ---&amp;gt; | Fetcher     | ---&amp;gt; | Classifier   | ---&amp;gt; | Extractor     | ---&amp;gt; | Urgency     |&lt;br&gt;
| Provider  |      | Agent       |      | Agent        |      | Agent         |      | Detector    |&lt;br&gt;
| (Gmail)   |      +-------------+      +--------------+      +---------------+      +-------------+&lt;br&gt;
                                                                  |                         |&lt;br&gt;
                                                                  v                         v&lt;br&gt;
                                                          +----------------+        +----------------+&lt;br&gt;
                                                          | Orchestrator   | &amp;lt;----&amp;gt; | Audit / Logger |&lt;br&gt;
                                                          | / Router       |        +----------------+&lt;br&gt;
                                                          +----------------+&lt;br&gt;
                                                                  |&lt;br&gt;
                                                       decisions/actions: escalate, route, ticket&lt;/p&gt;

&lt;p&gt;🏗️ &lt;strong&gt;Agents &amp;amp; Their Responsibilities&lt;/strong&gt;&lt;br&gt;
🔹 Fetcher Agent&lt;/p&gt;

&lt;p&gt;Connects to Gmail/Outlook&lt;/p&gt;

&lt;p&gt;Downloads unread emails&lt;/p&gt;

&lt;p&gt;Normalizes into a standard message object&lt;/p&gt;

&lt;p&gt;🔹 Classifier Agent&lt;/p&gt;

&lt;p&gt;Labels the email: Billing, Support, HR, Sales, Other&lt;/p&gt;

&lt;p&gt;Assigns a confidence score&lt;/p&gt;

&lt;p&gt;Extracts intent keywords&lt;/p&gt;

&lt;p&gt;🔹 Extractor Agent&lt;/p&gt;

&lt;p&gt;Extracts structured fields:&lt;/p&gt;

&lt;p&gt;invoice number&lt;/p&gt;

&lt;p&gt;amount (value + currency)&lt;/p&gt;

&lt;p&gt;due date&lt;/p&gt;

&lt;p&gt;vendor name&lt;/p&gt;

&lt;p&gt;action items&lt;/p&gt;

&lt;p&gt;attachments&lt;/p&gt;

&lt;p&gt;🔹 Urgency Detector Agent&lt;/p&gt;

&lt;p&gt;Computes urgency (low/medium/high)&lt;/p&gt;

&lt;p&gt;Detects deadlines, tone, escalation triggers&lt;/p&gt;

&lt;p&gt;Gives reasons + a 0–1 score&lt;/p&gt;

&lt;p&gt;🔹 Orchestrator Agent&lt;/p&gt;

&lt;p&gt;Decides action based on the above agents:&lt;/p&gt;

&lt;p&gt;escalate&lt;/p&gt;

&lt;p&gt;create ticket&lt;/p&gt;

&lt;p&gt;route to department&lt;/p&gt;

&lt;p&gt;send human-review request&lt;/p&gt;

&lt;p&gt;🔹 Audit / Logger Agent&lt;/p&gt;

&lt;p&gt;Every decision is logged for:&lt;/p&gt;

&lt;p&gt;Traceability&lt;/p&gt;

&lt;p&gt;Debugging&lt;/p&gt;

&lt;p&gt;Compliance&lt;/p&gt;

&lt;p&gt;🗂️ &lt;strong&gt;Example JSON Output (Final Email Analysis)&lt;/strong&gt;&lt;br&gt;
{&lt;br&gt;
  "email_id": "msg_abc123",&lt;br&gt;
  "from": "&lt;a href="mailto:supplier@example.com"&gt;supplier@example.com&lt;/a&gt;",&lt;br&gt;
  "subject": "Invoice #INV-2025-1104 — Payment overdue",&lt;br&gt;
  "category": {&lt;br&gt;
    "label": "Billing",&lt;br&gt;
    "confidence": 0.94&lt;br&gt;
  },&lt;br&gt;
  "extracted": {&lt;br&gt;
    "invoice_number": "INV-2025-1104",&lt;br&gt;
    "amount": { "value": 45200, "currency": "INR" },&lt;br&gt;
    "due_date": "2025-11-30",&lt;br&gt;
    "vendor_name": "ABC Supplies Pvt Ltd",&lt;br&gt;
    "action_items": [&lt;br&gt;
      { "type": "payment_followup", "text": "Confirm payment schedule" }&lt;br&gt;
    ]&lt;br&gt;
  },&lt;br&gt;
  "urgency": {&lt;br&gt;
    "level": "high",&lt;br&gt;
    "score": 0.92,&lt;br&gt;
    "reasons": ["overdue payment", "tone: urgent"]&lt;br&gt;
  },&lt;br&gt;
  "suggested_action": "escalate_to_finance"&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;📌 &lt;strong&gt;Prompts Used (Production-Ready)&lt;/strong&gt;&lt;br&gt;
📍 Classifier Prompt&lt;br&gt;
You are a mail classifier. Analyze the email subject + body.&lt;br&gt;
Return JSON:&lt;br&gt;
{&lt;br&gt;
 "label": "",&lt;br&gt;
 "confidence": &amp;lt;0.0 to 1.0&amp;gt;,&lt;br&gt;
 "intent": [""]&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;📍 Extractor Prompt&lt;br&gt;
Extract: invoice_number, amount, due_date, vendor_name, attachments_present, action_items.&lt;br&gt;
Return strict JSON. Use ISO date format (YYYY-MM-DD).&lt;br&gt;
If unknown, use null.&lt;/p&gt;

&lt;p&gt;📍 Urgency Prompt&lt;br&gt;
Classify urgency based on tone, deadlines, overdue items, complaints.&lt;br&gt;
Return JSON:&lt;br&gt;
{ "level": "low|medium|high", "score": 0.0-1.0, "reasons": [] }&lt;/p&gt;

&lt;p&gt;🧪 &lt;strong&gt;Evaluation Plan&lt;/strong&gt;&lt;br&gt;
Metrics used:&lt;br&gt;
Component   Metric  Target&lt;br&gt;
Classifier  Accuracy    ≥ 88%&lt;br&gt;
Extraction  F1 score    ≥ 0.85&lt;br&gt;
Urgency Precision   ≥ 0.90&lt;br&gt;
End-to-end  Automation rate ≥ 70%&lt;br&gt;
Example Results&lt;br&gt;
Classification accuracy: 91.2%&lt;br&gt;
Extraction F1: invoice_number 0.93, amount 0.89, due_date 0.86&lt;br&gt;
Urgency precision: 0.91&lt;br&gt;
Automation rate: 72.4%&lt;/p&gt;

&lt;p&gt;🖥️ &lt;strong&gt;Implementation (Simplified Code Snippets)&lt;/strong&gt;&lt;br&gt;
🔸 Fetcher (Python)&lt;br&gt;
def fetch_unread_messages(service):&lt;br&gt;
    results = service.users().messages().list(userId='me', q='is:unread').execute()&lt;br&gt;
    for m in results.get('messages', []):&lt;br&gt;
        msg = service.users().messages().get(userId='me', id=m['id'], format='raw').execute()&lt;br&gt;
        yield parse_raw(msg)&lt;/p&gt;

&lt;p&gt;🔸 Orchestrator&lt;br&gt;
def process_email(email_msg):&lt;br&gt;
    cls = classify_email(email_msg)&lt;br&gt;
    extracted = extract_fields(email_msg)&lt;br&gt;
    urgency = detect_urgency(email_msg, extracted)&lt;br&gt;
    action = decide_action(cls, urgency)&lt;br&gt;
    log_all(email_msg, cls, extracted, urgency, action)&lt;br&gt;
    return action&lt;/p&gt;

&lt;p&gt;🔸 Action Logic&lt;br&gt;
def decide_action(cls, urgency):&lt;br&gt;
    if urgency["level"] == "high" and urgency["score"] &amp;gt; 0.9:&lt;br&gt;
        return "escalate_to_finance"&lt;br&gt;
    if cls["label"] == "Support":&lt;br&gt;
        return "create_support_ticket"&lt;br&gt;
    return "route_to_ops"&lt;/p&gt;

&lt;p&gt;🧪 &lt;strong&gt;Test Emails (Used for Evaluation)&lt;/strong&gt;&lt;br&gt;
Test 1 — Urgent Billing&lt;br&gt;
Subject: Payment overdue — invoice INV-2025-1104&lt;br&gt;
Body: This invoice is overdue since Nov 30. Please treat as urgent.&lt;/p&gt;

&lt;p&gt;Test 2 — Support Issue&lt;br&gt;
Subject: App error when submitting form&lt;br&gt;
Body: User getting 500 error while saving profile.&lt;/p&gt;

&lt;p&gt;🛠️ Tools Used&lt;/p&gt;

&lt;p&gt;Python&lt;/p&gt;

&lt;p&gt;OpenAI GPT-4 / GPT-4.1&lt;/p&gt;

&lt;p&gt;LangChain-style orchestration&lt;/p&gt;

&lt;p&gt;Gmail API&lt;/p&gt;

&lt;p&gt;Chroma DB (optional)&lt;/p&gt;

&lt;p&gt;Docker&lt;/p&gt;

&lt;p&gt;🔐 Safety &amp;amp; Human Review&lt;/p&gt;

&lt;p&gt;Low classifier confidence (&amp;lt; 0.6)&lt;/p&gt;

&lt;p&gt;Missing mandatory fields&lt;/p&gt;

&lt;p&gt;Ambiguous urgency&lt;br&gt;
→ Routed to manual review to ensure safety.&lt;/p&gt;

&lt;p&gt;🚀 Future Improvements&lt;/p&gt;

&lt;p&gt;Add memory for vendor history&lt;/p&gt;

&lt;p&gt;Add learning loop from human review corrections&lt;/p&gt;

&lt;p&gt;Add sentiment + conflict detection&lt;/p&gt;

&lt;p&gt;Add auto-reply with supervised templates&lt;/p&gt;

&lt;p&gt;** Conclusion**&lt;/p&gt;

&lt;p&gt;This project showed me the real power of multi-agent systems — clarity, modularity, interpretability, and reliability. Instead of a large monolithic LLM call, the pipeline becomes transparent and controllable.&lt;/p&gt;

&lt;p&gt;The Email Automation Agent is a practical, production-ready workflow that can be used in finance, operations, HR, ticketing, and customer success teams to automate email-heavy processes.&lt;/p&gt;

</description>
      <category>googleaichallenge</category>
      <category>ai</category>
      <category>agents</category>
      <category>devchallenge</category>
    </item>
  </channel>
</rss>
