Animated data flow diagram

AI Smart Email Handler: RAG-Powered Replies with Human Approval

Version: 1.0.0 | Last Updated: 2025-05-16

Integrates with:

OpenAI Gmail Google Drive Qdrant IMAP

Overview

Unlock Automated & Intelligent Email Handling with this AI Agent

This powerful n8n AI Agent transforms your email management. It intelligently processes incoming emails by first summarizing them using LLMs (e.g., DeepSeek, OpenAI). Then, it consults your custom knowledge base, built from documents in Google Drive and stored in a Qdrant vector database (Retrieval Augmented Generation - RAG), to draft contextually relevant replies with OpenAI's GPT models. Before any email is sent to the original sender, a draft is routed to a designated human reviewer via Gmail. The agent then uses AI to interpret the reviewer's feedback (approve/request changes) and either sends the email as is, or revises it with AI assistance based on the feedback. This 'human-in-the-loop' approach ensures accuracy and brand alignment while massively boosting response efficiency.

Key Features & Benefits

  • AI-Powered Summarization: Quickly grasps the essence of incoming emails using LLMs.
  • RAG-Enhanced Responses: Generates highly relevant replies by tapping into your company-specific knowledge (FAQs, product docs, etc.) stored in Qdrant.
  • Intelligent Email Drafting: Leverages OpenAI (e.g., GPT-4o-mini) to compose professional, concise email replies.
  • Human-in-the-Loop Approval: Ensures quality control by sending draft replies for human review via Gmail (using 'sendAndWait' for direct feedback integration).
  • AI Feedback Interpretation: Automatically classifies reviewer feedback to either send approved emails or trigger AI-assisted revisions.
  • Automated Email Revision: AI refines emails based on human suggestions, reducing manual editing cycles.
  • Dynamic Knowledge Base: Easily build and update your RAG knowledge base by syncing documents from a specified Google Drive folder into Qdrant.
  • End-to-End Automation: Streamlines the entire process from receiving an email to sending an approved, context-aware response.

Use Cases

  • Automating first-response for B2C e-commerce customer inquiries (e.g., order status, returns) using FAQs, with human oversight for complex cases.
  • Streamlining B2B SaaS support by drafting initial answers to technical questions from a documentation-driven knowledge base, then routing for expert approval.
  • Managing high-volume sales inquiries by providing quick, AI-generated initial information, ensuring a human touchpoint before detailed engagement.
  • Improving internal helpdesk efficiency by auto-drafting responses to common IT or HR questions based on internal policies, with an approval step.

Prerequisites

  • An n8n instance (Cloud or self-hosted).
  • OpenAI API Key (e.g., for gpt-4o-mini or a more capable model for drafting, classification, and embeddings).
  • Qdrant instance URL and API Key.
  • Google Drive account credentials (for knowledge base documents).
  • IMAP/SMTP email account credentials for the primary email address being monitored and used for sending replies.
  • A separate Gmail account credentials for the approval workflow (the 'Send and Wait for Response' feature in the Gmail node works best with Gmail). Refer to n8n documentation for Gmail node setup.
  • (Optional) DeepSeek API Key if you intend to use the pre-configured 'DeepSeek Chat Model' for summarization; otherwise, the 'Email Summarization Chain' will require configuration with an alternative LLM (e.g., another OpenAI model).

Setup Instructions

  1. Download the n8n workflow JSON file.
  2. Import the workflow into your n8n instance.
  3. Configure Email Nodes:
    • 'Email Trigger (IMAP)': Set up with your incoming email server details and credentials.
    • 'Send Email' (final reply): Configure with your outgoing SMTP server details and credentials.
  4. Configure OpenAI Nodes:
    • 'Embeddings OpenAI' & 'Embeddings OpenAI1': Enter your OpenAI API Key.
    • 'OpenAI' (Chat Model connected to 'Write email', 'Text Classifier', 'Email Reviewer'): Select your desired model (e.g., gpt-4o-mini) and add your OpenAI API Key credential.
  5. Configure Qdrant & Knowledge Base Setup:
    • In 'Create collection' and 'Refresh collection' (HTTP Request nodes): Update the URL placeholder QDRANTURL with your Qdrant instance URL and the COLLECTION path segment with your desired collection name. Configure the 'Qdrant API (Hetzner)' credential with your Qdrant API key.
    • In 'Qdrant Vector Store' (retrieve mode) and 'Qdrant Vector Store1' (insert mode): Configure with your Qdrant URL, API key, and the same collection name used above.
    • In 'Get folder' (Google Drive node): Set up your Google Drive credentials. Update the folderId parameter from the default test-whatsapp to the ID or name of your Google Drive folder containing knowledge base documents.
    • Run the 'When clicking ‘Test workflow’' manual trigger once. This will trigger the sub-flow to create the Qdrant collection (if it doesn't exist), then fetch, process, and embed documents from your specified Google Drive folder into Qdrant.
  6. Configure Approval Workflow:
    • 'Gmail' (Send and Wait node): Configure with your Gmail credentials. This account will send the approval email and wait for a reply. Set the 'Send To' email to the address of the human reviewer.
  7. Configure Summarization (Optional - DeepSeek):
    • 'DeepSeek Chat Model': If using, configure with your DeepSeek API Key. Otherwise, replace or reconfigure the 'Email Summarization Chain' to use a different LLM (e.g., an OpenAI model via the 'OpenAI' chat model node).
  8. Customize Prompts:
    • Review and tailor the prompts within 'Email Summarization Chain', 'Write email' (AI Agent), 'Text Classifier', and 'Email Reviewer' (AI Agent) nodes to align with your desired tone, response style, and classification logic.
  9. Activate the main workflow (connected to 'Email Trigger (IMAP)').

Tags:

AI AgentEmail AutomationOpenAIRAGQdrantGoogle DriveHuman-in-the-loopCustomer SupportProductivity

Want your own unique AI agent?

Talk to us - we know how to build custom AI agents for your specific needs.

Schedule a Consultation