Skip to main content

🤖 Self Improving Email AI Support with Human-in-the-Loop

Workflow preview

Workflow preview
100%
🤖 Self Improving Email AI Support with Human-in-the-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

How it works This workflow creates a sophisticated, self improving customer support system that automatically handles incoming emails. It's designed to answer common questions using an AI powered k...

Best for

  • Support Chatbot automation workflows
  • AI Chatbot automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

n8n-nodes-base.if, @n8n/n8n-nodes-langchain.textclassifier, n8n-nodes-base.aggregate, @n8n/n8n-nodes-langchain.chainllm, n8n-nodes-base.gmailtrigger, n8n-nodes-base.gmail, n8n-nodes-base.googlesheets, n8n-nodes-base.stickynote

Source and attribution

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

Original n8n.io source

1.1 Workflow description

Title
🤖 Self Improving Email AI Support with Human-in-the-Loop
Workflow name
🤖 Self Improving Email AI Support with Human-in-the-Loop

How it works

This workflow creates a sophisticated, self-improving customer support system that automatically handles incoming emails. It's designed to answer common questions using an AI-powered knowledge base and, crucially, to learn from human experts when new or complex questions arise, continuously expanding its capabilities.

Think of it like having an AI assistant with a smart memory and a human mentor. Here's the step-by-step process:

  1. New Email Received: The workflow is triggered whenever a new email arrives in your designated support inbox (via Gmail).
  2. Classify Request: An AI model (Google Gemini 2.5 Flash Lite) first classifies the incoming email to ensure it's a genuine support request, filtering out irrelevant messages.
  3. Retrieve Knowledge Base: The workflow fetches all existing Question and Answer pairs from your dedicated Google Sheet knowledge base.
  4. AI Answer Attempt: A powerful AI model (Google Gemini 2.5 Pro) analyzes the customer's email against the entire knowledge base. It attempts to find a highly relevant answer and drafts a complete HTML email response if successful.
  5. Decision Point: An IF node checks if the AI found a confident answer.
    • If Answer Found: The AI-generated HTML response is immediately sent back to the customer via Gmail.
    • If No Answer Found (Human-in-the-Loop):
      • Escalate to Human: The customer's summarized question and original email are forwarded to a human expert (you or your team) via Gmail, requesting their assistance.
      • Human Reply & AI Learning: The workflow waits for the human expert's reply. Once received, another AI model (Google Gemini 2.5 Flash) processes both the original customer question and the expert's reply to distill them into a new, generic, and reusable Question/Answer pair.
      • Update Knowledge Base: This newly created Q&A pair is then automatically added as a new row to your Google Sheet knowledge base, ensuring the system can answer similar questions automatically in the future.

Set up steps

Setup time: ~10-15 minutes

This workflow requires connecting your Gmail and Google Sheets accounts, and obtaining a Google AI API key. Follow these steps carefully:

  1. Connect Your Gmail Account:

    • Select the On New Email Received node.
    • Click the Credential dropdown and select + Create New Credential to connect your Gmail account. Grant the necessary permissions.
    • Repeat this for the Send AI Answer and Ask Human for Help nodes, selecting the credential you just created.
  2. Connect Your Google Sheets Account:

    • Select the Get Knowledge Base node.
    • Click the Credential dropdown and select + Create New Credential to connect your Google account. Grant the necessary permissions.
    • Repeat this for the Add to Knowledge Base node, selecting the credential you just created.
  3. Set up Your Google Sheet Knowledge Base:

    • Create a new Google Sheet in your Google Drive.
    • Rename the first sheet (tab) to QA Database.
    • In the first row of QA Database, add two column headers: Question (in cell A1) and Answer (in cell B1).
    • Go back to the Get Knowledge Base node in n8n. In the Document ID field, select your newly created Google Sheet. Do the same for the Add to Knowledge Base node.
  4. Get Your Google AI API Key (for Gemini Models):

    • Visit Google AI Studio at aistudio.google.com/app/apikey.
    • Click "Create API key in new project" and copy the key.
    • In the workflow, go to the Google Gemini 2.5 Pro node, click the Credential dropdown, and select + Create New Credential.
    • Paste your key into the API Key field and Save.
    • Repeat this for the Google Gemini 2.5 Flash Lite and Google Gemini 2.5 Flash nodes, selecting the credential you just created.
  5. Configure Human Expert Email:

    • Select the Ask Human for Help node.
    • In the Send To field, replace the placeholder email address with the actual email address of your human expert (e.g., your own email or a team support email).
  6. Activate the Workflow:

    • Once all credentials and configurations are set, activate the workflow using the toggle switch at the top right of your n8n canvas.

Start Learning! Send a test email to the Gmail account connected to the On New Email Received node. Observe how the AI responds, or how it escalates to your expert email and then learns from the reply. Check your Google Sheet to see new Q&A pairs being added!

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 - Support Answer Found

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

Block 2 - Is it a Support Request?

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

Block 3 - Combine into Knowledge Context

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

Block 4 - AI: Create Reusable Q&A

Type / Role
@n8n/n8n-nodes-langchain.chainLlm - chainLlm
Config choices
Version 1.7

Block 5 - On New Email Received

Type / Role
n8n-nodes-base.gmailTrigger - gmailTrigger
Config choices
Version 1.3

Block 6 - Send AI Answer

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

Block 7 - Ask Human for Help

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

Block 8 - Add to Knowledge Base

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

Block 9 - Get Knowledge Base

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

Block 10 - Sticky Note1

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

Block 11 - Find Answer with AI

Type / Role
@n8n/n8n-nodes-langchain.chainLlm - chainLlm
Config choices
Version 1.7

Block 12 - Sticky Note (0)

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

Block 13 - Sticky Note (3)

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

Block 14 - Sticky Note (4)

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

Block 15 - Sticky Note (5)

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

Block 16 - Sticky Note (6)

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

Block 17 - Sticky Note (7)

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

Block 18 - Sticky Note (9)

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

Block 19 - Sticky Note (10)

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

Block 20 - Sticky Note (11)

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

Block 21 - Parsed AI Response

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

Block 22 - Structured Output Parser

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

Block 23 - Gemini Flash Lite Latest

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

Block 24 - Gemini Flash Latest

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

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

3. Summary Table

Workflow 🤖 Self Improving Email AI Support with Human-in-the-Loop
Complexity advanced
Nodes 27
Categories Support Chatbot, AI Chatbot
Author Lucas Peyrin
Published 20 Sept 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/8779/8779.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 🤖 Self Improving Email AI Support with Human-in-the-Loop do?

How it works This workflow creates a sophisticated, self improving customer support system that automatically handles incoming emails. It's designed to answer common questions using an AI powered k...

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 Support Chatbot, AI Chatbot use case.