AutomationFlowsAI & RAG › AI Tutor Chatbot with RAG and GPT-4o-mini

AI Tutor Chatbot with RAG and GPT-4o-mini

Original n8n title: Guide Students with an AI Tutor Chatbot Using Rag, Intent Classification and Gpt-4o-mini

ByisaWOW @isawow on n8n.io

Automatically guide students through personalized learning sessions using AI-powered intent classification, book-based knowledge retrieval (RAG), and full session logging — all without writing a single line of code.

Chat trigger trigger★★★★☆ complexityAI-powered19 nodesLm Chat Deep SeekAgentOpenAI EmbeddingsOpenAI ChatMemory Buffer WindowChat TriggerGoogle SheetsPinecone Vector Store
AI & RAG Trigger: Chat trigger Nodes: 19 Complexity: ★★★★☆ AI nodes: yes Added:

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

This workflow follows the Agent → Chat Trigger 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": "bfecf1c3-4941-4ce3-b2be-a6af427a8a0f",
      "name": "Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        464,
        336
      ],
      "parameters": {
        "width": 460,
        "height": 904,
        "content": "### AI Tutor \u2013 Nathan (Interactive Learning Chatbot)\n\nThis workflow powers **Nathan**, an AI-driven educational tutor chatbot that guides users through personalised, topic-based learning sessions using Retrieval-Augmented Generation (RAG).\n\n### How it works\n1. A user sends a message via the public chat interface.\n2. A **DeepSeek-powered Intent Classifier** categorises the message as: *greeting*, *topic*, *answer*, *question*, or *random*.\n3. The classified intent fetches the matching **system prompt** from a Google Sheets prompt library (`pmt` tab).\n4. The fetched prompt and original user input are merged and forwarded to the **GPT-4o-mini AI Teacher Agent**, which also retrieves relevant chunks from a **Pinecone book vector store** (RAG).\n5. Every exchange (session ID, user message, AI response) is **logged to a Preservation sheet** in Google Sheets for auditing and review.\n\n### Setup\n- Add **DeepSeek** API credentials to the *DeepSeek LLM* node.\n- Add **OpenAI** API credentials to the *GPT-4o-mini LLM* and *OpenAI Embeddings* nodes.\n- Connect **Google Sheets** credentials to the *Fetch System Prompt* and *Log Q&A to Sheets* nodes.\n- Connect **Pinecone** credentials to the *Book Knowledge Base* node.\n- Replace `YOUR_GOOGLE_SHEET_ID` placeholders with your actual Google Sheets document ID.\n- Ensure your sheet has a `pmt` tab (prompt library with an `Output` column) and a `Preservation` tab (Q&A log).\n\n### Customisation\n- Swap DeepSeek with any classifier-capable LLM.\n- Extend the prompt library with new intent categories.\n- Adjust `topK` on the Pinecone node to control how many book chunks are retrieved per query."
      },
      "typeVersion": 1
    },
    {
      "id": "45ea014a-1614-436d-a7fd-225c398d0ab4",
      "name": "Section \u2013 Receive & Classify Intent",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        960,
        464
      ],
      "parameters": {
        "color": 7,
        "width": 580,
        "height": 740,
        "content": "## 1. Receive & Classify Intent\nThe chat trigger receives the user message. **DeepSeek** classifies it into one of five intents \u2014 *greeting, topic, answer, question, or random* \u2014 using a sliding-window memory for conversational context."
      },
      "typeVersion": 1
    },
    {
      "id": "ad0c4fae-0b32-4437-bc04-4cab37259de1",
      "name": "Section \u2013 Fetch & Merge Prompt",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1824,
        464
      ],
      "parameters": {
        "color": 7,
        "width": 760,
        "height": 380,
        "content": "## 2. Fetch & Merge System Prompt\nThe classified intent looks up the matching system prompt from the Google Sheets prompt library. The prompt and the original chat input are then merged and aggregated before being forwarded to the AI Teacher."
      },
      "typeVersion": 1
    },
    {
      "id": "125205f3-a73f-4110-af3e-c24996a22f1c",
      "name": "Section \u2013 AI Teacher Agent",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2624,
        464
      ],
      "parameters": {
        "color": 7,
        "width": 520,
        "height": 840,
        "content": "## 3. AI Teacher Agent (RAG)\n**GPT-4o-mini** generates a pedagogically appropriate response using the fetched system prompt, full session memory, and relevant content retrieved from the Pinecone book vector store."
      },
      "typeVersion": 1
    },
    {
      "id": "c696b2f2-0a3a-4e87-aa91-d6c2eb3ddfdc",
      "name": "Section \u2013 Log & Return Response",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3120,
        464
      ],
      "parameters": {
        "color": 7,
        "width": 540,
        "height": 380,
        "content": "## 4. Log & Return Response\nAppends the session ID, user message, and AI response to the **Preservation** sheet in Google Sheets. The final output is then formatted and returned to the chat interface."
      },
      "typeVersion": 1
    },
    {
      "id": "308eea9c-51c3-4934-92bb-ca9e1dc7fe1d",
      "name": "DeepSeek LLM",
      "type": "@n8n/n8n-nodes-langchain.lmChatDeepSeek",
      "position": [
        1296,
        1152
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "b9b7afa7-4a54-49df-8647-bf6f00dadeeb",
      "name": "Intent Classifier",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1296,
        784
      ],
      "parameters": {
        "text": "={{ $json.chatInput }}",
        "options": {
          "systemMessage": "=You will receive a user message. Classify the input into exactly one of the following five categories based on its content and context:\n\ngreeting \u2013 The user simply greets (e.g., \"hi\", \"hello\", \"hey\") without mentioning a topic or asking a question.\n\ntopic \u2013 The user greets and also introduces a subject they want to learn or discuss (e.g., \"Hi, I want to learn about gravity\").\n\nanswer \u2013 The user is replying to a previous question. This includes:\nDirect answers (correct or incorrect).\nReplies with discourse markers or conversation fillers (e.g., \"I think it's...\", \"Umm...\", \"Maybe it's...\").\n\nIf there is memory of an ongoing conversation, assume it is most likely a question.\n\nquestion \u2013 The user is asking something (e.g., \"What is Newton's second law?\").\n\nrandom \u2013 The input is off-topic, nonsensical, or irrelevant to the educational context (e.g., \"Are you food?\", \"I'm hungry\", \"ajsdnkfjas\").\n\nOutput Format:\nRespond with only one word from this list:\ngreeting, topic, answer, question, or random.\n(it cannot be anything else)\n\nDo not include any explanation, punctuation, or extra text."
        },
        "promptType": "define"
      },
      "typeVersion": 1.9
    },
    {
      "id": "6c78f721-2f4f-4a08-8b9f-7c0b45d07615",
      "name": "OpenAI Embeddings",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        2944,
        1264
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "300621f3-15e7-4f23-9507-965ee0dfa1b5",
      "name": "GPT-4o-mini LLM",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        2672,
        1088
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "d5ce0842-aed3-4193-95b2-211bd30a3c75",
      "name": "Teacher Session Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        2784,
        1280
      ],
      "parameters": {
        "sessionKey": "={{ $('Chat Trigger').item.json.sessionId }}",
        "sessionIdType": "customKey",
        "contextWindowLength": 10
      },
      "typeVersion": 1.3
    },
    {
      "id": "0308dc90-cb35-4b86-89c9-0b8458cd6159",
      "name": "Format Response Output",
      "type": "n8n-nodes-base.set",
      "position": [
        3504,
        832
      ],
      "parameters": {
        "mode": "raw",
        "options": {},
        "jsonOutput": "={\n  \"output\": {{ JSON.stringify($json[\"AI Response\"]) }}\n}"
      },
      "typeVersion": 3.4
    },
    {
      "id": "a761107b-727b-4aff-835d-317c25f69171",
      "name": "AI Teacher Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        2672,
        832
      ],
      "parameters": {
        "text": "={{ $('Chat Trigger').item.json.chatInput }}",
        "options": {
          "systemMessage": "={{ $json.Prompt[0] }}"
        },
        "promptType": "define"
      },
      "typeVersion": 1.9
    },
    {
      "id": "4cb84446-5217-481b-817f-ea04cb169c75",
      "name": "Chat Trigger",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        1008,
        624
      ],
      "parameters": {
        "public": true,
        "options": {},
        "initialMessages": "Hi there! \ud83d\udc4b\nMy name is Nathan. Please share the topic you want to learn today!"
      },
      "typeVersion": 1.1
    },
    {
      "id": "f0e90733-8e14-4406-98ec-e04a7fb94bcf",
      "name": "Aggregate Fields",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        2448,
        640
      ],
      "parameters": {
        "options": {},
        "fieldsToAggregate": {
          "fieldToAggregate": [
            {
              "fieldToAggregate": "Prompt"
            },
            {
              "fieldToAggregate": "chatInput"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "78a9bcc5-fbad-4033-a09f-ff2d7582707d",
      "name": "Merge Input and Prompt",
      "type": "n8n-nodes-base.merge",
      "position": [
        2160,
        640
      ],
      "parameters": {},
      "typeVersion": 3.1
    },
    {
      "id": "0a896dec-5ed3-4108-85ba-0b91e79c5e42",
      "name": "Classifier Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        1392,
        1024
      ],
      "parameters": {},
      "typeVersion": 1.3
    },
    {
      "id": "6b044d02-ed89-4e5a-ae23-f3df1bf1e82e",
      "name": "Fetch System Prompt",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1872,
        784
      ],
      "parameters": {
        "options": {},
        "filtersUI": {
          "values": [
            {
              "lookupValue": "={{ $json.output }}",
              "lookupColumn": "Output"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/YOUR_GOOGLE_SHEET_ID/edit#gid=0",
          "cachedResultName": "pmt"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_GOOGLE_SHEET_ID",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/YOUR_GOOGLE_SHEET_ID/edit",
          "cachedResultName": "AI teacher Sheet"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "2eedf477-8e24-4346-9f37-6083f91c0be0",
      "name": "Log Q&A to Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        3168,
        832
      ],
      "parameters": {
        "columns": {
          "value": {
            "Session": "={{ $('Chat Trigger').item.json.sessionId }}",
            "User Msg": "={{ $('Chat Trigger').item.json.chatInput }}",
            "AI Response": "={{ $json.output }}"
          },
          "schema": [
            {
              "id": "Session",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Session",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "User Msg",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "User Msg",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "AI Response",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "AI Response",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_PRESERVATION_SHEET_GID",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/YOUR_GOOGLE_SHEET_ID/edit#gid=YOUR_PRESERVATION_SHEET_GID",
          "cachedResultName": "Preservation"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_GOOGLE_SHEET_ID",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/YOUR_GOOGLE_SHEET_ID/edit",
          "cachedResultName": "AI teacher Sheet"
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "232a6427-0b3b-40a9-bd91-5f138bf49c1b",
      "name": "Book Knowledge Base",
      "type": "@n8n/n8n-nodes-langchain.vectorStorePinecone",
      "position": [
        2944,
        1056
      ],
      "parameters": {
        "mode": "retrieve-as-tool",
        "topK": 3,
        "options": {},
        "toolName": "Pinecone_Vector_Store_Book",
        "pineconeIndex": {
          "__rl": true,
          "mode": "list",
          "value": "rag-vector-db-book-quiz",
          "cachedResultName": "rag-vector-db-book-quiz"
        },
        "toolDescription": "Retrieve relevant educational content from the book vector store in Pinecone."
      },
      "typeVersion": 1.1
    }
  ],
  "connections": {
    "Chat Trigger": {
      "main": [
        [
          {
            "node": "Merge Input and Prompt",
            "type": "main",
            "index": 0
          },
          {
            "node": "Intent Classifier",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "DeepSeek LLM": {
      "ai_languageModel": [
        [
          {
            "node": "Intent Classifier",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "GPT-4o-mini LLM": {
      "ai_languageModel": [
        [
          {
            "node": "AI Teacher Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "AI Teacher Agent": {
      "main": [
        [
          {
            "node": "Log Q&A to Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate Fields": {
      "main": [
        [
          {
            "node": "AI Teacher Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Classifier Memory": {
      "ai_memory": [
        [
          {
            "node": "Intent Classifier",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Intent Classifier": {
      "main": [
        [
          {
            "node": "Fetch System Prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log Q&A to Sheets": {
      "main": [
        [
          {
            "node": "Format Response Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Embeddings": {
      "ai_embedding": [
        [
          {
            "node": "Book Knowledge Base",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Book Knowledge Base": {
      "ai_tool": [
        [
          {
            "node": "AI Teacher Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Fetch System Prompt": {
      "main": [
        [
          {
            "node": "Merge Input and Prompt",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Merge Input and Prompt": {
      "main": [
        [
          {
            "node": "Aggregate Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Teacher Session Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Teacher Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    }
  }
}
Pro

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

About this workflow

Automatically guide students through personalized learning sessions using AI-powered intent classification, book-based knowledge retrieval (RAG), and full session logging — all without writing a single line of code.

Source: https://n8n.io/workflows/14291/ — 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

Advanced Ai Demo Presented At Ai Developers 14 Meetup. Uses slack, stickyNote, textSplitterRecursiveCharacterTextSplitter, embeddingsOpenAi. Chat trigger; 39 nodes.

Slack, Text Splitter Recursive Character Text Splitter, OpenAI Embeddings +14
AI & RAG

Advanced Ai Demo (Presented At Ai Developers #14 Meetup). Uses slack, stickyNote, textSplitterRecursiveCharacterTextSplitter, embeddingsOpenAi. Chat trigger; 39 nodes.

Slack, Text Splitter Recursive Character Text Splitter, OpenAI Embeddings +14
AI & RAG

Workflow 2358. Uses slack, textSplitterRecursiveCharacterTextSplitter, embeddingsOpenAi, documentDefaultDataLoader. Chat trigger; 39 nodes.

Slack, Text Splitter Recursive Character Text Splitter, OpenAI Embeddings +14
AI & RAG

2358. Uses slack, textSplitterRecursiveCharacterTextSplitter, embeddingsOpenAi, documentDefaultDataLoader. Chat trigger; 39 nodes.

Slack, Text Splitter Recursive Character Text Splitter, OpenAI Embeddings +14
AI & RAG

This workflow was presented at the AI Developers meet up in San Fransico on 24 July, 2024. Categorize incoming Gmail emails and assign custom Gmail labels. This example uses the Text Classifier node,

Slack, Text Splitter Recursive Character Text Splitter, OpenAI Embeddings +14