Skip to main content

Adaptive email auto-responder with GPT-4, RAG and human feedback loop

Workflow preview

Workflow preview
100%
Adaptive email auto-responder with GPT-4, RAG and human feedback loop preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

️ Self Learning Agent: AI Powered Email Auto Responder that Improves with Feedback ‍ Author: LeeWei Overview of the n8n Workflow This n8n workflow builds a self improving AI agent for handling...

Best for

  • Ticket Management automation workflows
  • AI RAG automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

@n8n/n8n-nodes-langchain.embeddingsopenai, @n8n/n8n-nodes-langchain.vectorstoresupabase, @n8n/n8n-nodes-langchain.lmchatopenai, @n8n/n8n-nodes-langchain.agent, @n8n/n8n-nodes-langchain.outputparserautofixing, @n8n/n8n-nodes-langchain.outputparserstructured, n8n-nodes-base.if, n8n-nodes-base.googlesheets

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by LeeWei.

Original n8n.io source

1.1 Workflow description

Title
Adaptive email auto-responder with GPT-4, RAG and human feedback loop
Workflow name
Adaptive email auto-responder with GPT-4, RAG and human feedback loop

⚙️ Self Learning Agent: AI-Powered Email Auto-Responder that Improves with Feedback

🧑‍💻 Author: LeeWei


Overview of the n8n Workflow

This n8n workflow builds a self-improving AI agent for handling email responses. It integrates Gmail for incoming messages, uses an AI agent with a Supabase vector store for knowledge retrieval, drafts replies based on dynamic prompts, and evaluates confidence scores. High-confidence drafts are sent automatically, while low-confidence ones are routed to Google Sheets for human review. Feedback from Sheets triggers updates to the prompt or knowledge base, enabling the agent to learn and refine its responses over time. The workflow supports OpenAI and OpenRouter models, with structured output parsing and conditional routing for efficiency.


How it Works

• Triggers on new Gmail emails, extracts content, and uses an AI agent with company knowledge from Supabase to draft a response.
• Assesses confidence; auto-sends high-confidence replies or saves drafts to Google Sheets for human feedback.
• Monitors Sheets for updates, extracts feedback via AI, and applies changes—either refining the dynamic prompt or adding new info to the vector store.
• Loops back improvements to enhance future responses without manual reconfiguration.


Set Up Steps

Setup takes about 20-30 minutes, focused on credentials and basic resource creation (e.g., Google Sheet and Supabase table). Detailed node-level guidance is in the workflow's sticky notes—clone the JSON for plug-and-play nodes, then edit only essentials like credentials and IDs. No need to rebuild nodes; they're pre-connected and ready.


🚀 Steps to Connect:

  1. Gmail Setup

    • Set up OAuth2 credentials at console.cloud.google.com with scopes for Gmail (read/send).
    • Paste into the Gmail Trigger and Gmail nodes' credentials fields.
    • Test by sending a sample email to your connected inbox.
  2. OpenAI API Key

    • Generate at platform.openai.com.
    • Paste into the OpenAI Chat Model and OpenAI Chat Model1 nodes' credentials.
    • 💡 Use a model like gpt-4o-mini for cost efficiency; adjust temperature in options for response creativity.
  3. OpenRouter API Key

    • Sign up at openrouter.ai and create an API key.
    • Paste into the OpenAI Chat Model2 node's credentials (used for feedback extraction).
    • Select a model like gpt-4o-mini in the node for consistency.
  4. Supabase Connection

    • Create a free account at supabase.com, set up a project, and add a table named documents with vector support (enable pgvector extension).
    • Paste API URL and key into the Supabase Vector Store and Supabase Vector Store1 nodes' credentials.
    • Initialize with sample docs via the workflow or dashboard for knowledge base testing.
  5. Google Sheets Setup

    • Create OAuth2 credentials at console.cloud.google.com with scopes for Sheets (read/write).
    • Paste into all Google Sheets nodes' credentials.
    • Duplicate the sample sheet (ID: 1YDzwYd5LdTnSQlFM5YrDhhbCnNH7oHVvNg6x3mYu8I4) or create one with tabs: "Dynamic Var" (for prompts) and "Feedback" (columns: Id, Original Email, Draft, Human Feedback, Status). Replace the documentId in nodes with your sheet's ID.

Plug and Play Instructions

Clone the provided JSON directly into n8n—all nodes (triggers, agents, parsers, switches) are pre-wired and functional. No re-setup required beyond the steps above. Key editable fields (detailed in sticky notes):

  • AI Agent Node: System Message
    Customize the prompt template for response style (e.g., add rules for tone or specific facts). Default handles factual, concise replies.

  • Structured Output Parser Node: JSON Schema
    Adjust if adding output fields (e.g., include "suggested_followup" alongside "final_response" and "resolution_score").

  • If Node: Conditions
    Tweak the confidence threshold (default: <4 routes to review) based on your risk tolerance.

  • Information Extractor Node: Prompt
    Refine the feedback analysis (e.g., prioritize certain feedback types like "add facts" vs. "update prompt").

Test with a sample email: Send a query to your Gmail, review in Sheets if low-confidence, provide feedback, and watch the agent improve on the next run.


Potential Customizations

  • Switch AI Models: Swap OpenAI/OpenRouter nodes for alternatives like Anthropic via compatible n8n nodes.
  • Add Notifications: Insert a Slack or email node post-Sheets save for alerts on low-confidence drafts.
  • Expand Knowledge Base: Add a loader node to ingest more docs into Supabase automatically.
  • Confidence Routing: Duplicate the If node for multi-tier reviews (e.g., score 1-2 escalates to admin).

Considerations and Improvements

  • API Limits: Monitor OpenAI/OpenRouter usage for costs; start with mini models. Supabase free tier handles small knowledge bases—upgrade for scale.
  • Data Privacy: Emails and feedback pass through AI providers—ensure compliance for sensitive info.
  • Feedback Loop: Test iterations to confirm improvements; initial runs may need manual prompt tweaks.
  • Enhancements: Integrate audio transcription for voice feedback or export logs for auditing.

This workflow turns email handling into an adaptive, low-maintenance system—ideal for support teams or busy inboxes. For tweaks, reference the sticky notes or experiment in a test clone!

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - Embeddings OpenAI

Type / Role
@n8n/n8n-nodes-langchain.embeddingsOpenAi - embeddingsOpenAi
Config choices
Version 1.2

Block 2 - Supabase Vector Store

Type / Role
@n8n/n8n-nodes-langchain.vectorStoreSupabase - vectorStoreSupabase
Config choices
Version 1.1

Block 3 - OpenAI Chat Model

Type / Role
@n8n/n8n-nodes-langchain.lmChatOpenAi - lmChatOpenAi
Config choices
Version 1.2

Block 4 - AI Agent

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 1.8

Block 5 - Auto-fixing Output Parser

Type / Role
@n8n/n8n-nodes-langchain.outputParserAutofixing - outputParserAutofixing
Config choices
Version 1

Block 6 - OpenAI Chat Model1

Type / Role
@n8n/n8n-nodes-langchain.lmChatOpenAi - lmChatOpenAi
Config choices
Version 1.2

Block 7 - Structured Output Parser

Type / Role
@n8n/n8n-nodes-langchain.outputParserStructured - outputParserStructured
Config choices
Version 1.2

Block 8 - If

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.2

Block 9 - Get Dynamic Prompt

Type / Role
n8n-nodes-base.googleSheets - googleSheets
Config choices
Version 4.6

Block 10 - Edit Fields

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 11 - Gmail

Type / Role
n8n-nodes-base.gmail - gmail
Config choices
Version 2.1

Block 12 - Google Sheets

Type / Role
n8n-nodes-base.googleSheets - googleSheets
Config choices
Version 4.6

Block 13 - Markdown

Type / Role
n8n-nodes-base.markdown - markdown
Config choices
Version 1

Block 14 - Google Sheets Trigger

Type / Role
n8n-nodes-base.googleSheetsTrigger - googleSheetsTrigger
Config choices
Version 1

Block 15 - OpenAI Chat Model2

Type / Role
@n8n/n8n-nodes-langchain.lmChatOpenAi - lmChatOpenAi
Config choices
Version 1.2

Block 16 - Information Extractor

Type / Role
@n8n/n8n-nodes-langchain.informationExtractor - informationExtractor
Config choices
Version 1.1

Block 17 - If1

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.2

Block 18 - Original Reply

Type / Role
n8n-nodes-base.markdown - markdown
Config choices
Version 1

Block 19 - If2

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.2

Block 20 - Get Dynamic Prompt1

Type / Role
n8n-nodes-base.googleSheets - googleSheets
Config choices
Version 4.6

Block 21 - Markdown1

Type / Role
n8n-nodes-base.markdown - markdown
Config choices
Version 1

Block 22 - Switch

Type / Role
n8n-nodes-base.switch - switch
Config choices
Version 3.2

Block 23 - Gmail1

Type / Role
n8n-nodes-base.gmail - gmail
Config choices
Version 2.1

Block 24 - Google Sheets1

Type / Role
n8n-nodes-base.googleSheets - googleSheets
Config choices
Version 4.6

Showing the first 24 of 38 workflow blocks. Download the JSON for the full node graph.

3. Summary Table

Workflow Adaptive email auto-responder with GPT-4, RAG and human feedback loop
Complexity advanced
Nodes 38
Categories Ticket Management, AI RAG
Author LeeWei
Published 21 Sept 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/8802/8802.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Adaptive email auto-responder with GPT-4, RAG and human feedback loop do?

️ Self Learning Agent: AI Powered Email Auto Responder that Improves with Feedback ‍ Author: LeeWei Overview of the n8n Workflow This n8n workflow builds a self improving AI agent for handling...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Ticket Management, AI RAG use case.