This workflow corresponds to n8n.io template #4799 — we link there as the canonical source.
This workflow follows the Agent → Chainllm 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 →
{
"meta": {
"templateCredsSetupCompleted": true
},
"nodes": [
{
"id": "ab11aca6-163b-4995-a2c1-89146aca4d13",
"name": "OpenAI Chat Model",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
3100,
460
],
"parameters": {},
"typeVersion": 1
},
{
"id": "5397732c-4b72-4d67-bc83-d131d6fe6a6a",
"name": "Default Data Loader",
"type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
"position": [
2160,
1000
],
"parameters": {},
"typeVersion": 1
},
{
"id": "15b136fe-d236-4016-82e5-2cd45188cfc3",
"name": "Embeddings OpenAI1",
"type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
"position": [
2040,
1000
],
"parameters": {},
"typeVersion": 1
},
{
"id": "67f63eac-3d80-4453-8378-31c245e40158",
"name": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"position": [
-380,
160
],
"parameters": {
"content": ""
},
"typeVersion": 1
},
{
"id": "96577cfc-9c82-48da-a8bb-6b3c1bafc232",
"name": "Download File",
"type": "n8n-nodes-base.googleDrive",
"position": [
560,
660
],
"parameters": {},
"executeOnce": true,
"typeVersion": 3
},
{
"id": "b3805cd6-52e7-462c-9239-a573c8484bf9",
"name": "File Created",
"type": "n8n-nodes-base.googleDriveTrigger",
"position": [
-320,
660
],
"parameters": {},
"typeVersion": 1
},
{
"id": "b6a8743b-1e69-41a4-b410-410943583512",
"name": "File Updated",
"type": "n8n-nodes-base.googleDriveTrigger",
"position": [
-320,
840
],
"parameters": {},
"typeVersion": 1
},
{
"id": "36af5de3-7bfc-473a-a14d-f671a38c8212",
"name": "Extract Document Text",
"type": "n8n-nodes-base.extractFromFile",
"position": [
780,
660
],
"parameters": {},
"typeVersion": 1,
"alwaysOutputData": true
},
{
"id": "cb6f5d94-033e-4dd0-a09c-4d92fe07ecb6",
"name": "Set File ID",
"type": "n8n-nodes-base.set",
"position": [
120,
660
],
"parameters": {},
"typeVersion": 3.4
},
{
"id": "23f43960-5c13-43be-9450-af9c82c5f4d2",
"name": "RAG AI Agent",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
3140,
240
],
"parameters": {},
"typeVersion": 1.6
},
{
"id": "a2a4faee-8109-4f55-b30b-6e6294845088",
"name": "Loop Over Items",
"type": "n8n-nodes-base.splitInBatches",
"position": [
-100,
660
],
"parameters": {},
"typeVersion": 3
},
{
"id": "ceef932c-f667-4ed8-8014-b650a3546fb0",
"name": "Recursive Character Text Splitter",
"type": "@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter",
"position": [
2160,
1160
],
"parameters": {},
"typeVersion": 1
},
{
"id": "f59122eb-4e34-4765-90be-86f3507e9a65",
"name": "When chat message received",
"type": "@n8n/n8n-nodes-langchain.chatTrigger",
"disabled": true,
"position": [
2600,
240
],
"parameters": {},
"typeVersion": 1.1
},
{
"id": "61852ba7-292a-4b8c-b774-6df4d2d4d7c5",
"name": "Create Chunks From Doc",
"type": "n8n-nodes-base.code",
"position": [
1000,
660
],
"parameters": {},
"typeVersion": 2
},
{
"id": "5231cf12-4061-4793-b918-f02bd021c333",
"name": "Chunks To List",
"type": "n8n-nodes-base.splitOut",
"position": [
1220,
660
],
"parameters": {},
"typeVersion": 1
},
{
"id": "a37aa716-8d50-4ecd-a8de-44ca198386c3",
"name": "Generate Contextual Text",
"type": "@n8n/n8n-nodes-langchain.chainLlm",
"position": [
1440,
660
],
"parameters": {},
"typeVersion": 1.4
},
{
"id": "b053ea08-d6a9-4718-a86b-3d44aa8e19b9",
"name": "OpenAI Chat Model3",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
1460,
820
],
"parameters": {},
"typeVersion": 1.2
},
{
"id": "6cf0dbc3-835f-4c99-b3b0-c5db7c379394",
"name": "Get Values",
"type": "n8n-nodes-base.set",
"position": [
1820,
660
],
"parameters": {},
"typeVersion": 3.4
},
{
"id": "05270c8c-a1de-4be9-80ff-84fbf84e8578",
"name": "Postgres PGVector Store",
"type": "@n8n/n8n-nodes-langchain.vectorStorePGVector",
"position": [
2060,
780
],
"parameters": {},
"typeVersion": 1.1
},
{
"id": "71b60f18-4e1c-45bd-840c-5f3f113675f7",
"name": "Delete Old Doc Records",
"type": "n8n-nodes-base.postgres",
"position": [
340,
660
],
"parameters": {},
"typeVersion": 2.5
},
{
"id": "3ff8d9fb-f420-4939-b925-03e8fa7506d7",
"name": "When Executed by Another Workflow",
"type": "n8n-nodes-base.executeWorkflowTrigger",
"position": [
2600,
400
],
"parameters": {},
"typeVersion": 1.1
},
{
"id": "b1d273cb-1730-40eb-93e7-95305e6ce091",
"name": "Docs RAG Tool",
"type": "@n8n/n8n-nodes-langchain.vectorStorePGVector",
"position": [
3520,
380
],
"parameters": {},
"typeVersion": 1.1
},
{
"id": "9609e4cc-6d65-4364-97f8-0e79c0b36a2d",
"name": "Embeddings",
"type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
"position": [
3520,
520
],
"parameters": {},
"typeVersion": 1.2
},
{
"id": "df6ee67c-f983-4428-b0b8-cd0522d45298",
"name": "Chat Memory",
"type": "@n8n/n8n-nodes-langchain.memoryPostgresChat",
"position": [
3260,
460
],
"parameters": {},
"notesInFlow": false,
"typeVersion": 1
},
{
"id": "6e33fb90-9dd1-4ef8-a5e6-9081aca23ec5",
"name": "Sticky Note2",
"type": "n8n-nodes-base.stickyNote",
"position": [
2540,
160
],
"parameters": {
"content": ""
},
"typeVersion": 1
},
{
"id": "0b6cd331-8202-413f-a721-43290d9e51d0",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"position": [
-380,
-1180
],
"parameters": {
"content": ""
},
"typeVersion": 1
},
{
"id": "e2d556be-1c64-4834-b6f6-ed469753ce09",
"name": "Sticky Note5",
"type": "n8n-nodes-base.stickyNote",
"position": [
2540,
-740
],
"parameters": {
"content": ""
},
"typeVersion": 1
},
{
"id": "e54d26de-fb3e-491d-a23d-3986dfd36a2e",
"name": "Sticky Note3",
"type": "n8n-nodes-base.stickyNote",
"position": [
-380,
1380
],
"parameters": {
"content": ""
},
"typeVersion": 1
},
{
"id": "5d1a8354-a538-44d8-8d30-fd74084e2ea3",
"name": "TestData",
"type": "n8n-nodes-base.set",
"notes": "You can use it for test workflow without trigger",
"disabled": true,
"position": [
2820,
400
],
"parameters": {},
"notesInFlow": true,
"typeVersion": 3.4
}
],
"connections": {
"TestData": {
"main": [
[
{
"node": "RAG AI Agent",
"type": "main",
"index": 0
}
]
]
},
"Embeddings": {
"ai_embedding": [
[
{
"node": "Docs RAG Tool",
"type": "ai_embedding",
"index": 0
}
]
]
},
"Get Values": {
"main": [
[
{
"node": "Postgres PGVector Store",
"type": "main",
"index": 0
}
]
]
},
"Chat Memory": {
"ai_memory": [
[
{
"node": "RAG AI Agent",
"type": "ai_memory",
"index": 0
}
]
]
},
"Set File ID": {
"main": [
[
{
"node": "Delete Old Doc Records",
"type": "main",
"index": 0
}
]
]
},
"File Created": {
"main": [
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"File Updated": {
"main": [
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"Docs RAG Tool": {
"ai_tool": [
[
{
"node": "RAG AI Agent",
"type": "ai_tool",
"index": 0
}
]
]
},
"Download File": {
"main": [
[
{
"node": "Extract Document Text",
"type": "main",
"index": 0
}
]
]
},
"Chunks To List": {
"main": [
[
{
"node": "Generate Contextual Text",
"type": "main",
"index": 0
}
]
]
},
"Loop Over Items": {
"main": [
[],
[
{
"node": "Set File ID",
"type": "main",
"index": 0
}
]
]
},
"OpenAI Chat Model": {
"ai_languageModel": [
[
{
"node": "RAG AI Agent",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Embeddings OpenAI1": {
"ai_embedding": [
[
{
"node": "Postgres PGVector Store",
"type": "ai_embedding",
"index": 0
}
]
]
},
"OpenAI Chat Model3": {
"ai_languageModel": [
[
{
"node": "Generate Contextual Text",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Default Data Loader": {
"ai_document": [
[
{
"node": "Postgres PGVector Store",
"type": "ai_document",
"index": 0
}
]
]
},
"Extract Document Text": {
"main": [
[
{
"node": "Create Chunks From Doc",
"type": "main",
"index": 0
}
]
]
},
"Create Chunks From Doc": {
"main": [
[
{
"node": "Chunks To List",
"type": "main",
"index": 0
}
]
]
},
"Delete Old Doc Records": {
"main": [
[
{
"node": "Download File",
"type": "main",
"index": 0
}
]
]
},
"Postgres PGVector Store": {
"main": [
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"Generate Contextual Text": {
"main": [
[
{
"node": "Get Values",
"type": "main",
"index": 0
}
]
]
},
"When chat message received": {
"main": [
[]
]
},
"Recursive Character Text Splitter": {
"ai_textSplitter": [
[
{
"node": "Default Data Loader",
"type": "ai_textSplitter",
"index": 0
}
]
]
},
"When Executed by Another Workflow": {
"main": [
[
{
"node": "TestData",
"type": "main",
"index": 0
}
]
]
}
}
}
For the full experience including quality scoring and batch install features for each workflow upgrade to Pro
About this workflow
This powerful AI automation add-on upgrades your Telegram Bot Starter Template by integrating a fully functional AI chatbot and a context-aware AI agent that answers user questions using your internal documents.
Source: https://n8n.io/workflows/4799/ — 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.
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
Your AI workforce is ready. Are you?
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
Automate Outreach Prospect automates finding, enriching, and messaging potential partners (like restaurants, malls, and bars) using Apify Google Maps scraping, Perplexity enrichment, OpenAI LLMs, Goog
Chat with docs - 5minAI New version. Uses httpRequest, documentDefaultDataLoader, textSplitterRecursiveCharacterTextSplitter, embeddingsOpenAi. Event-driven trigger; 62 nodes.