AutomationFlowsAI & RAG › Adaptive Email Auto-responder with Gpt-4, RAG and Human Feedback Loop

Adaptive Email Auto-responder with Gpt-4, RAG and Human Feedback Loop

ByLeeWei @leeweihernandez07 on n8n.io

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.…

Event trigger★★★★★ complexityAI-powered38 nodesOpenAI EmbeddingsSupabase Vector StoreOpenAI ChatAgentOutput Parser AutofixingOutput Parser StructuredGoogle SheetsGmail
AI & RAG Trigger: Event Nodes: 38 Complexity: ★★★★★ AI nodes: yes Added:

This workflow corresponds to n8n.io template #8802 — we link there as the canonical source.

This workflow follows the Agent → Documentdefaultdataloader recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "e432c58f-163b-4a96-8a23-5c2749c2bcd1",
      "name": "Embeddings OpenAI",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        368,
        960
      ],
      "parameters": {},
      "typeVersion": 1.2
    },
    {
      "id": "25b0117a-152b-4ad3-9114-606d42a8d7f1",
      "name": "Supabase Vector Store",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "position": [
        400,
        800
      ],
      "parameters": {},
      "typeVersion": 1.1
    },
    {
      "id": "8fbca9a7-f3cc-4d13-ba37-427d62cedc9d",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        176,
        800
      ],
      "parameters": {},
      "typeVersion": 1.2
    },
    {
      "id": "d67fb10b-10f5-4d02-9a9d-1d69c07fd658",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        384,
        416
      ],
      "parameters": {},
      "typeVersion": 1.8
    },
    {
      "id": "0b7e252b-8e97-4ec7-9d9e-2ee120cb09a7",
      "name": "Auto-fixing Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserAutofixing",
      "position": [
        720,
        800
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "8156059d-5ae2-41a4-bc27-92ff8f2a46b7",
      "name": "OpenAI Chat Model1",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        656,
        960
      ],
      "parameters": {},
      "typeVersion": 1.2
    },
    {
      "id": "f543ac29-3eb4-4554-b6aa-0e2285cdfb6b",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        848,
        960
      ],
      "parameters": {},
      "typeVersion": 1.2
    },
    {
      "id": "85b72d77-0541-45e6-b037-770acec610e9",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        1040,
        416
      ],
      "parameters": {},
      "typeVersion": 2.2
    },
    {
      "id": "dc370570-4695-4ba9-9c46-8f08472bc910",
      "name": "Get Dynamic Prompt",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -448,
        416
      ],
      "parameters": {},
      "typeVersion": 4.6
    },
    {
      "id": "a064b42d-5aba-4745-8ed5-4adde17b1dd4",
      "name": "Edit Fields",
      "type": "n8n-nodes-base.set",
      "position": [
        16,
        416
      ],
      "parameters": {},
      "typeVersion": 3.4
    },
    {
      "id": "d8cec49d-2aa5-413e-af1b-9c77895e91d5",
      "name": "Gmail",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1296,
        656
      ],
      "parameters": {},
      "typeVersion": 2.1
    },
    {
      "id": "55196c92-edcd-4dc7-ad96-48ab287d81bf",
      "name": "Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1488,
        352
      ],
      "parameters": {},
      "typeVersion": 4.6
    },
    {
      "id": "02fcd994-63fc-4b9c-a9b5-61c6562abb5c",
      "name": "Markdown",
      "type": "n8n-nodes-base.markdown",
      "position": [
        1296,
        352
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "2a83bb18-6ef0-42f2-ab9d-75b3bcc1a35e",
      "name": "Google Sheets Trigger",
      "type": "n8n-nodes-base.googleSheetsTrigger",
      "position": [
        -944,
        1584
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "0cee2309-721d-4ed9-b1be-9b7607cc22fe",
      "name": "OpenAI Chat Model2",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -176,
        1792
      ],
      "parameters": {},
      "typeVersion": 1.2
    },
    {
      "id": "acc3ff75-16c4-4737-a25f-f7527898e387",
      "name": "Information Extractor",
      "type": "@n8n/n8n-nodes-langchain.informationExtractor",
      "position": [
        -160,
        1584
      ],
      "parameters": {},
      "typeVersion": 1.1
    },
    {
      "id": "6605a7d8-cd6c-4260-a698-229139887305",
      "name": "If1",
      "type": "n8n-nodes-base.if",
      "position": [
        -720,
        1584
      ],
      "parameters": {},
      "typeVersion": 2.2
    },
    {
      "id": "12ea4994-6d77-4094-853c-38c1430bfcc8",
      "name": "Original Reply",
      "type": "n8n-nodes-base.markdown",
      "position": [
        -208,
        416
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "5620dca5-25ce-412e-8984-068ae1c8a3fb",
      "name": "If2",
      "type": "n8n-nodes-base.if",
      "position": [
        -720,
        416
      ],
      "parameters": {},
      "typeVersion": 2.2
    },
    {
      "id": "b0e81371-4e0b-437d-9e9e-17cb4588fd95",
      "name": "Get Dynamic Prompt1",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -416,
        1584
      ],
      "parameters": {},
      "typeVersion": 4.6
    },
    {
      "id": "9ce74bbc-bc67-4d71-b137-ccc0f8084195",
      "name": "Markdown1",
      "type": "n8n-nodes-base.markdown",
      "position": [
        448,
        1424
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "b89cfee9-17f4-48b9-a308-6cc81c2ceecc",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "position": [
        368,
        1728
      ],
      "parameters": {},
      "typeVersion": 3.2
    },
    {
      "id": "09a6bf0a-af94-42b2-91d1-d642f1b80cf1",
      "name": "Gmail1",
      "type": "n8n-nodes-base.gmail",
      "position": [
        672,
        1424
      ],
      "parameters": {},
      "typeVersion": 2.1
    },
    {
      "id": "7771aa20-b79e-40b8-a485-c63e378c72d3",
      "name": "Google Sheets1",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        672,
        1760
      ],
      "parameters": {},
      "typeVersion": 4.6
    },
    {
      "id": "202edba7-7a79-4acd-8107-71067b04ed0f",
      "name": "Supabase Vector Store1",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "position": [
        1248,
        1376
      ],
      "parameters": {},
      "typeVersion": 1.2
    },
    {
      "id": "5fdd5b0f-3b2e-43f3-8bf5-9a70f3807f5f",
      "name": "Embeddings OpenAI1",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        1184,
        1568
      ],
      "parameters": {},
      "typeVersion": 1.2
    },
    {
      "id": "cc316e14-9675-4b74-a94c-8bca710b1a0f",
      "name": "Default Data Loader",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        1392,
        1504
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "b6b530ef-4720-4fdf-80a6-87c01547b01b",
      "name": "Recursive Character Text Splitter",
      "type": "@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter",
      "position": [
        1344,
        1808
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "8d8e4d6b-86f1-40cb-bf0a-ff92ceac6463",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1040,
        1424
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "c33f3ce5-ed89-4c8c-92c6-b117313f0251",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1168,
        192
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "95773e14-3954-4a7a-805d-1f088d8ba01a",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1168,
        576
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "b38c1b19-1e0a-41d4-8c67-c0b6aa628dac",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -240,
        1312
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "453f19a5-4378-47a0-bb30-6b13ac1a9216",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        288,
        1312
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "c33d9300-1069-4e4b-a54d-04d9eb8b0262",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        608,
        1648
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "39cffcf5-647b-441c-8a5e-9032a827bbbe",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1120,
        1296
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "08939064-db0b-4cc8-9c72-03feed930813",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1040,
        32
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "5107b6a4-b428-473b-957f-4c65a90b897b",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2512,
        32
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "e8bc49f7-64f1-4cc5-8f81-cf63b2f36840",
      "name": "Gmail Trigger1",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        -960,
        416
      ],
      "parameters": {},
      "typeVersion": 1.2
    }
  ],
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "Markdown",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Gmail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If1": {
      "main": [
        [
          {
            "node": "Get Dynamic Prompt1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If2": {
      "main": [
        [
          {
            "node": "Get Dynamic Prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Google Sheets1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Supabase Vector Store1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Markdown": {
      "main": [
        [
          {
            "node": "Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Markdown1": {
      "main": [
        [
          {
            "node": "Gmail1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gmail Trigger1": {
      "main": [
        [
          {
            "node": "If2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Original Reply": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI": {
      "ai_embedding": [
        [
          {
            "node": "Supabase Vector Store",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI1": {
      "ai_embedding": [
        [
          {
            "node": "Supabase Vector Store1",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Get Dynamic Prompt": {
      "main": [
        [
          {
            "node": "Original Reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "Auto-fixing Output Parser",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model2": {
      "ai_languageModel": [
        [
          {
            "node": "Information Extractor",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Default Data Loader": {
      "ai_document": [
        [
          {
            "node": "Supabase Vector Store1",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Get Dynamic Prompt1": {
      "main": [
        [
          {
            "node": "Information Extractor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets Trigger": {
      "main": [
        [
          {
            "node": "If1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Information Extractor": {
      "main": [
        [
          {
            "node": "Markdown1",
            "type": "main",
            "index": 0
          },
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Supabase Vector Store": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Auto-fixing Output Parser",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Auto-fixing Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "AI Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Recursive Character Text Splitter": {
      "ai_textSplitter": [
        [
          {
            "node": "Default Data Loader",
            "type": "ai_textSplitter",
            "index": 0
          }
        ]
      ]
    }
  }
}
Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this 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.…

Source: https://n8n.io/workflows/8802/ — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

A lightweight, self-hosted AI assistant built entirely in n8n. Multi-channel messaging (Telegram, WhatsApp, Gmail), persistent memory, task management, and autonomous work — all in a single visual wor

Telegram Trigger, OpenRouter Chat, Data Table +20
AI & RAG

Your AI workforce is ready. Are you?

Google Sheets Tool, Mcp Trigger, Google Drive +29
AI & RAG

This intelligent chatbot leverages cutting-edge financial APIs and AI-driven analysis to deliver comprehensive stock research reports. Get instant access to professional-grade investment analysis that

Tool Think, Supabase Vector Store, OpenAI Embeddings +15
AI & RAG

This advanced n8n workflow automates the full lead enrichment, qualification, and personalized outreach process tailored specifically for the B2B real estate sector. Integrating top platforms like Api

N8N Nodes Fillout, OpenAI Chat, Pinecone Vector Store +11
AI & RAG

This n8n template automatically classifies incoming emails (Sales, Support, Internal, Finance, Promotions) and routes them to a dedicated OpenAI LLM Agent for processing. Depending on the category, th

OpenAI, Gmail, Text Classifier +16