This workflow corresponds to n8n.io template #12440 — we link there as the canonical source.
This workflow follows the Chainllm → Gmail 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 →
{
"nodes": [
{
"id": "3a2ecd35-aded-4d69-be94-9c606113fe87",
"name": "Lookio API call",
"type": "n8n-nodes-base.httpRequest",
"position": [
512,
0
],
"parameters": {
"url": "=https://api.lookio.app/webhook/query",
"method": "POST",
"options": {},
"sendBody": true,
"sendHeaders": true,
"bodyParameters": {
"parameters": [
{
"name": "query",
"value": "={{ $json.text }}"
},
{
"name": "assistant_id",
"value": "YOUR-ASSISTANT-ID"
},
{
"name": "query_mode",
"value": "flash"
}
]
},
"headerParameters": {
"parameters": [
{
"name": "api_key",
"value": "YOUR-API-KEY"
}
]
}
},
"typeVersion": 4.2
},
{
"id": "b3fa823e-79ac-474a-8e73-d63d70196fa2",
"name": "OpenAI Chat Model",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
304,
288
],
"parameters": {
"model": {
"__rl": true,
"mode": "list",
"value": "gpt-4.1-mini"
},
"options": {
"responseFormat": "text"
},
"responsesApiEnabled": false
},
"credentials": {
"openAiApi": {
"name": "<your credential>"
}
},
"typeVersion": 1.3
},
{
"id": "f8a219e0-b919-4484-8770-f76fdfb53409",
"name": "Formulate question for knowledge base",
"type": "@n8n/n8n-nodes-langchain.chainLlm",
"position": [
48,
0
],
"parameters": {
"text": "=Subject: {{ $json.subject }}\n\nBody:\n{{ $json.text }}",
"batching": {},
"messages": {
"messageValues": [
{
"message": "=Based on the user message that's the full content of an email, return a clean formatted question that should be asked to the knowledge base so we get enough context to prepare a response to this email.\n\nYour output is strictly the question (e.g. \"When is the meeting XYZ\" or \"What is the process to ....\")."
}
]
},
"promptType": "define"
},
"typeVersion": 1.8
},
{
"id": "a1761abb-e43e-4df8-8603-0ba825d3857f",
"name": "New email incoming",
"type": "n8n-nodes-base.gmailTrigger",
"position": [
-240,
0
],
"parameters": {
"simple": false,
"filters": {},
"options": {},
"pollTimes": {
"item": [
{
"mode": "everyMinute"
}
]
}
},
"credentials": {
"gmailOAuth2": {
"name": "<your credential>"
}
},
"typeVersion": 1.3
},
{
"id": "dbb4b322-232a-4c0a-b74b-c92dbfd4f42e",
"name": "Structured Output Parser",
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"position": [
1008,
208
],
"parameters": {
"jsonSchemaExample": "{\n \"Email body\": \"Dear ..., \\nLorem ipsum...\\nBest regards\",\n \"Email subject\": \"Lorem ipsum\"\n}"
},
"typeVersion": 1.3
},
{
"id": "c45272bf-dac3-4244-9b46-f1dfd84f2384",
"name": "Write email draft",
"type": "@n8n/n8n-nodes-langchain.chainLlm",
"position": [
848,
0
],
"parameters": {
"text": "=Subject: \n{{ $('New email incoming').item.json.subject }}\n\nBody:\n\n{{ $('New email incoming').item.json.text }}",
"batching": {},
"messages": {
"messageValues": [
{
"message": "=## Role\n\nYour role is to write an email to respond to the email provided by the user message and base your answer on the research that had been done.\nReturn email subject and body.\n\n## Research\n\nResearch question:\n{{ $('Formulate question for knowledge base').item.json.text }}\n\nRetrieved research context:\n\n{{ $json.Output }}"
}
]
},
"promptType": "define",
"hasOutputParser": true
},
"typeVersion": 1.8
},
{
"id": "35ae860f-2e9e-435f-a230-02e735e08a14",
"name": "Create email draft",
"type": "n8n-nodes-base.gmail",
"position": [
1296,
0
],
"parameters": {
"message": "={{ $json.output['Email body'] }}",
"options": {
"sendTo": "={{ $('New email incoming').item.json.from.value[0].address }}",
"threadId": "={{ $('New email incoming').item.json.threadId }}"
},
"subject": "={{ $json.output['Email subject'] }}",
"resource": "draft"
},
"credentials": {
"gmailOAuth2": {
"name": "<your credential>"
}
},
"typeVersion": 2.2
},
{
"id": "23aa3ef7-392d-431f-866c-2ee50951c5be",
"name": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"position": [
384,
-144
],
"parameters": {
"color": 3,
"width": 352,
"height": 320,
"content": "## Retrieving content from your knowledge base (Lookio)\nAction required: Make sure to set your Lookio API key and workspace ID in here."
},
"typeVersion": 1
},
{
"id": "f43d9217-6a16-44fb-b072-4a86d5f63b6f",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"position": [
-912,
-384
],
"parameters": {
"width": 544,
"height": 960,
"content": "# Auto-create Lookio-backed Gmail drafts\n\nQuick summary: When a new email arrives, this workflow extracts a clear question, queries your **Lookio** assistant for sourced context, then drafts a reply (subject + body) and saves it as a **Gmail draft** for human review.\n\nHow it works (short):\n1. **New email incoming** \u2192 2. **Formulate question for knowledge base** (LLM) \u2192 3. **Lookio API call** \u2192 4. **Write email draft** (LLM) \u2192 5. **Create email draft** (Gmail)\n\nHow to set up (do these first):\n1. Create a Lookio assistant at https://lookio.app/ and upload your docs. Copy **API Key** and **Assistant ID**.\n2. Add **Gmail OAuth2** credentials to n8n and connect your Gmail account.\n3. Add **OpenAI** (or other LLM) credentials for the LLM nodes.\n4. In **Lookio API call** node replace `<YOUR-API-KEY>` and `<YOUR-ASSISTANT-ID>` and choose **query_mode** (`eco`/`flash`/`deep`).\n5. Optionally restrict the **New email incoming** trigger with labels or filters.\n\nTips: Drafts are not sent automatically\u2014agents can edit and send. Replace Gmail with other channels if needed.\n\n*A template created by Guillaume Duvernay*\n\n\n## [Video Tutorial](https://youtu.be)\n@[youtube](VLz3pCXDGd4)\n"
},
"typeVersion": 1
},
{
"id": "27536573-deb2-4f53-a0aa-f14f1be86cdc",
"name": "Sticky Note2",
"type": "n8n-nodes-base.stickyNote",
"position": [
-320,
-144
],
"parameters": {
"color": 7,
"width": 272,
"height": 320,
"content": "## When you receive new emails"
},
"typeVersion": 1
},
{
"id": "e4e31836-7e35-4695-b3c3-277bdf2e79aa",
"name": "Sticky Note3",
"type": "n8n-nodes-base.stickyNote",
"position": [
0,
-144
],
"parameters": {
"color": 7,
"width": 336,
"height": 320,
"content": "## AI formulates a question from your knowledge base"
},
"typeVersion": 1
},
{
"id": "34e25432-4b22-4ddb-9940-c932d348ac7c",
"name": "Sticky Note4",
"type": "n8n-nodes-base.stickyNote",
"position": [
784,
-144
],
"parameters": {
"color": 7,
"width": 336,
"height": 320,
"content": "## AI writes the email and subject\nBased on the content we've just retrieved & the original email."
},
"typeVersion": 1
},
{
"id": "7585213d-5d5b-4406-9758-7d2f2771c309",
"name": "Sticky Note5",
"type": "n8n-nodes-base.stickyNote",
"position": [
1168,
-144
],
"parameters": {
"color": 7,
"width": 336,
"height": 320,
"content": "## Creating the draft in Gmail"
},
"typeVersion": 1
}
],
"connections": {
"Lookio API call": {
"main": [
[
{
"node": "Write email draft",
"type": "main",
"index": 0
}
]
]
},
"OpenAI Chat Model": {
"ai_languageModel": [
[
{
"node": "Formulate question for knowledge base",
"type": "ai_languageModel",
"index": 0
},
{
"node": "Write email draft",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Write email draft": {
"main": [
[
{
"node": "Create email draft",
"type": "main",
"index": 0
}
]
]
},
"New email incoming": {
"main": [
[
{
"node": "Formulate question for knowledge base",
"type": "main",
"index": 0
}
]
]
},
"Structured Output Parser": {
"ai_outputParser": [
[
{
"node": "Write email draft",
"type": "ai_outputParser",
"index": 0
}
]
]
},
"Formulate question for knowledge base": {
"main": [
[
{
"node": "Lookio API call",
"type": "main",
"index": 0
}
]
]
}
}
}
Credentials you'll need
Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.
gmailOAuth2openAiApi
For the full experience including quality scoring and batch install features for each workflow upgrade to Pro
About this workflow
This n8n template automatically generates knowledge-backed draft email replies when a new message arrives in a connected Gmail account. The workflow extracts a clean question from the incoming email using an LLM, queries a Lookio assistant (your RAG knowledge base) for verified…
Source: https://n8n.io/workflows/12440/ — original creator credit. Request a take-down →
Related workflows
Workflows that share integrations, category, or trigger type with this one. All free to copy and import.
[](https://www.youtube.com/watch?v=rfu4MSvtpAw)
Typeform IA - YT. Uses typeformTrigger, agent, lmChatOpenAi, toolWorkflow. Event-driven trigger; 75 nodes.
My workflow 14. Uses lmChatOpenAi, outputParserStructured, rssFeedRead, httpRequest. Event-driven trigger; 63 nodes.
This workflow is perfect for: Agile development teams and project managers who need to quickly set up Jira projects Product managers who want to convert feature ideas into structured user stories and
True Multi-Offer Campaigns Promote any mix of products, services or solutions in one run; no separate workflows needed. SMTP Load Balancing A Switch node rotates sends across five Gmail/SMTP accounts