Created
May 28, 2025 19:38
-
-
Save paoloanzn/69a73432ebbfa857b376fadf4a26f244 to your computer and use it in GitHub Desktop.
AI Research Agent n8n Workflow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "AI research Agent", | |
"nodes": [ | |
{ | |
"parameters": { | |
"httpMethod": "POST", | |
"path": "3b9a89f9-44f5-4759-8e46-eeb418eec7a1", | |
"options": {} | |
}, | |
"type": "n8n-nodes-base.webhook", | |
"typeVersion": 2, | |
"position": [ | |
-20, | |
-300 | |
], | |
"id": "1220c91c-ab27-418f-8cc8-9a2f000e6030", | |
"name": "Webhook", | |
"webhookId": "3b9a89f9-44f5-4759-8e46-eeb418eec7a1" | |
}, | |
{ | |
"parameters": { | |
"options": {} | |
}, | |
"type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi", | |
"typeVersion": 1.2, | |
"position": [ | |
1768, | |
140 | |
], | |
"id": "8a878ba3-37f0-4676-b2fc-feeca6464d09", | |
"name": "Embeddings OpenAI", | |
"credentials": { | |
"openAiApi": { | |
"id": "Z3R8Ji2VnI8qLeU1", | |
"name": "OpenAi account" | |
} | |
} | |
}, | |
{ | |
"parameters": { | |
"mode": "insert", | |
"tableName": { | |
"__rl": true, | |
"value": "documents", | |
"mode": "list", | |
"cachedResultName": "documents" | |
}, | |
"options": {} | |
}, | |
"type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase", | |
"typeVersion": 1.1, | |
"position": [ | |
1784, | |
-80 | |
], | |
"id": "ab45325b-8f7f-482d-8818-c718cdc0d314", | |
"name": "Supabase Vector Store", | |
"credentials": { | |
"supabaseApi": { | |
"id": "6rCvzKWRmCqAynOD", | |
"name": "Supabase account" | |
} | |
} | |
}, | |
{ | |
"parameters": { | |
"jsonMode": "expressionData", | |
"jsonData": "=", | |
"options": {} | |
}, | |
"type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader", | |
"typeVersion": 1, | |
"position": [ | |
1888, | |
142.5 | |
], | |
"id": "7e1df73e-b102-4bd8-b5b1-5cbd0548d99f", | |
"name": "Default Data Loader" | |
}, | |
{ | |
"parameters": { | |
"separator": "={{ \"\\n\" }}" | |
}, | |
"type": "@n8n/n8n-nodes-langchain.textSplitterCharacterTextSplitter", | |
"typeVersion": 1, | |
"position": [ | |
1976, | |
340 | |
], | |
"id": "d8d89ef5-d4ef-46d6-a40c-f393fa3d0ece", | |
"name": "Character Text Splitter" | |
}, | |
{ | |
"parameters": { | |
"mode": "load", | |
"tableName": { | |
"__rl": true, | |
"value": "documents", | |
"mode": "list", | |
"cachedResultName": "documents" | |
}, | |
"prompt": "={{ $json.choices[0].message.content }}", | |
"topK": 5, | |
"options": {} | |
}, | |
"type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase", | |
"typeVersion": 1.1, | |
"position": [ | |
576, | |
-5 | |
], | |
"id": "580d7567-0f08-4e0f-b599-f726603fe762", | |
"name": "Supabase Vector Store Retriever", | |
"credentials": { | |
"supabaseApi": { | |
"id": "6rCvzKWRmCqAynOD", | |
"name": "Supabase account" | |
} | |
} | |
}, | |
{ | |
"parameters": { | |
"options": {} | |
}, | |
"type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi", | |
"typeVersion": 1.2, | |
"position": [ | |
664, | |
215 | |
], | |
"id": "2a115d36-191e-4da1-8ac3-9a2ab55d02f5", | |
"name": "Embeddings OpenAI1", | |
"credentials": { | |
"openAiApi": { | |
"id": "Z3R8Ji2VnI8qLeU1", | |
"name": "OpenAi account" | |
} | |
} | |
}, | |
{ | |
"parameters": { | |
"modelId": { | |
"__rl": true, | |
"value": "gpt-4.1", | |
"mode": "list", | |
"cachedResultName": "GPT-4.1" | |
}, | |
"messages": { | |
"values": [ | |
{ | |
"content": "=Using the following research data: \n```txt\n{{ $json['Expert Analysis'][0].json.choices[0].message.content }}\n```\n\nact as a team of 3 different experts: [Innovation Consultant], [Financial Analyst], and [Consumer Behavior Expert].\n\nProvide new angles and insights on [{{ $json.Webhook[0].json.body.topic }}] to complement the initial research. Suggest additional business ideas and refine existing ones.\n\nThese are documents retrived using vector similarity search to collect corralet content from previous researches (can be empty):\n{{ $json.formattedDocuments }}" | |
} | |
] | |
}, | |
"options": {} | |
}, | |
"type": "@n8n/n8n-nodes-langchain.openAi", | |
"typeVersion": 1.8, | |
"position": [ | |
1172, | |
-5 | |
], | |
"id": "dca7e629-34b4-45aa-9822-d83b4eeaaa05", | |
"name": "Experts Review", | |
"credentials": { | |
"openAiApi": { | |
"id": "Z3R8Ji2VnI8qLeU1", | |
"name": "OpenAi account" | |
} | |
} | |
}, | |
{ | |
"parameters": { | |
"jsCode": "const documents = $('Supabase Vector Store Retriever').all()\nlet formattedDocuments = \"\"\nfor (let document of documents) {\n const content = document.json.document.pageContent\n formattedDocuments += `Document:\\n\\`\\`\\`txt\\n${JSON.stringify(content)}\\n\\`\\`\\`\\n\\n`\n}\nreturn { formattedDocuments, 'Expert Analysis': $('Expert Analysis').all(), 'Webhook': $('Webhook').all() }" | |
}, | |
"type": "n8n-nodes-base.code", | |
"typeVersion": 2, | |
"position": [ | |
952, | |
-5 | |
], | |
"id": "b3a7a116-d3f3-469b-acde-8894597688dd", | |
"name": "RAG Formatter", | |
"alwaysOutputData": true | |
}, | |
{ | |
"parameters": { | |
"modelId": { | |
"__rl": true, | |
"value": "gpt-4.1", | |
"mode": "list", | |
"cachedResultName": "GPT-4.1" | |
}, | |
"messages": { | |
"values": [ | |
{ | |
"content": "=Respond as if you're a team of 3 experts: [Market Researcher], [Business Strategist], and [Industry Veteran]. Each expert should contribute their unique perspective on [{{ $json.body.topic }}], then collaborate on the final answer. Provide a detailed analysis including market trends, strategic recommendations, and industry insights for generating 10+ business ideas." | |
} | |
] | |
}, | |
"simplify": false, | |
"options": {} | |
}, | |
"type": "@n8n/n8n-nodes-langchain.openAi", | |
"typeVersion": 1.8, | |
"position": [ | |
180, | |
-160 | |
], | |
"id": "4d402c53-f3dd-4c9e-9b37-ddbb793897cc", | |
"name": "Expert Analysis", | |
"credentials": { | |
"openAiApi": { | |
"id": "Z3R8Ji2VnI8qLeU1", | |
"name": "OpenAi account" | |
} | |
} | |
}, | |
{ | |
"parameters": { | |
"jsCode": "const expertAnalysisOutput = (() => {\n try {\n const input = $input.first().json.choices[0].message.content \n return input\n } catch (error) {\n return null\n }\n})();\n\nconst expertReviewOutput = (() => {\n try {\n const input = $input.first().json.message.content\n return input\n } catch (error) {\n return null\n }\n\n})();\n\nreturn {\n data: expertReviewOutput ?? expertAnalysisOutput\n}" | |
}, | |
"type": "n8n-nodes-base.code", | |
"typeVersion": 2, | |
"position": [ | |
1580, | |
-160 | |
], | |
"id": "40fb337f-ac3a-4858-9c36-23cf75a32513", | |
"name": "Data Parser", | |
"alwaysOutputData": true | |
}, | |
{ | |
"parameters": { | |
"modelId": { | |
"__rl": true, | |
"value": "gpt-4.1", | |
"mode": "list", | |
"cachedResultName": "GPT-4.1" | |
}, | |
"messages": { | |
"values": [ | |
{ | |
"content": "=Using the initial research: \n```txt\n{{ $('Expert Analysis').last().json.choices[0].message.content }}\n```\nand additional perspectives:\n```txt\n{{ $json.message.content }}\n``` \n\ngenerate a final report for [{{ $('Webhook').last().json.body.topic }}]. Include 10+ business ideas with detailed descriptions, market analysis (trends, opportunities), competitive landscape, and step-by-step execution plans for each idea. Format the output as a structured markdown document. Output only the report, nothing else.\n\n" | |
} | |
] | |
}, | |
"options": {} | |
}, | |
"type": "@n8n/n8n-nodes-langchain.openAi", | |
"typeVersion": 1.8, | |
"position": [ | |
1820, | |
-320 | |
], | |
"id": "991a6142-4b06-47b7-ae16-14be63fb4cd2", | |
"name": "OpenAI", | |
"executeOnce": false, | |
"credentials": { | |
"openAiApi": { | |
"id": "Z3R8Ji2VnI8qLeU1", | |
"name": "OpenAi account" | |
} | |
} | |
}, | |
{ | |
"parameters": { | |
"content": "## How to run the workflow\n\nThe workflow can be triggered via remote POST request, making it flexible for any kind of integration/remote action\n\nYou need to send a POST request over the webhook with body containing the following data:\n```json\n{\"topic\": \"research topic\"}\n```\n", | |
"height": 260, | |
"width": 420 | |
}, | |
"type": "n8n-nodes-base.stickyNote", | |
"typeVersion": 1, | |
"position": [ | |
120, | |
-540 | |
], | |
"id": "cc7529c4-fff7-4625-b865-49ca6b038a16", | |
"name": "Sticky Note" | |
}, | |
{ | |
"parameters": { | |
"operation": "sendDocument", | |
"binaryData": true, | |
"binaryPropertyName": "binary", | |
"additionalFields": {} | |
}, | |
"type": "n8n-nodes-base.telegram", | |
"typeVersion": 1.2, | |
"position": [ | |
2420, | |
-320 | |
], | |
"id": "a4875070-d904-4f62-b9ab-86e7f6249e3b", | |
"name": "Telegram", | |
"webhookId": "cdb4ca6a-a9b6-4239-a37c-5695b6b26dba", | |
"credentials": { | |
"telegramApi": { | |
"id": "GkIBeM0cQICtGE13", | |
"name": "Telegram account" | |
} | |
} | |
}, | |
{ | |
"parameters": { | |
"content": "## Self-Learning feature\n\nThe workflow stores embeddings of previous researches to improve the learning process each time by implement a RAG system to retrieve contextual data", | |
"height": 260, | |
"width": 420, | |
"color": 4 | |
}, | |
"type": "n8n-nodes-base.stickyNote", | |
"typeVersion": 1, | |
"position": [ | |
2160, | |
-120 | |
], | |
"id": "a9fc90f5-46b3-406a-8d7a-ea1247627795", | |
"name": "Sticky Note1" | |
}, | |
{ | |
"parameters": { | |
"content": "## How to setup supabase vector storage\n\nThe setup is very simple, just create a standard free supabase project and in sql editor run this query to create the vector storage table:\n\n```sql\n-- Enable the pgvector extension to work with embedding vectors\ncreate extension vector;\n\n-- Create a table to store your documents\ncreate table documents (\n id bigserial primary key,\n content text, -- corresponds to Document.pageContent\n metadata jsonb, -- corresponds to Document.metadata\n embedding vector(1536) -- 1536 works for OpenAI embeddings, change if needed\n);\n\n-- Create a function to search for documents\ncreate function match_documents (\n query_embedding vector(1536),\n match_count int default null,\n filter jsonb DEFAULT '{}'\n) returns table (\n id bigint,\n content text,\n metadata jsonb,\n similarity float\n)\nlanguage plpgsql\nas $$\n#variable_conflict use_column\nbegin\n return query\n select\n id,\n content,\n metadata,\n 1 - (documents.embedding <=> query_embedding) as similarity\n from documents\n where metadata @> filter\n order by documents.embedding <=> query_embedding\n limit match_count;\nend;\n$$;\n```\n\n", | |
"height": 780, | |
"width": 880, | |
"color": 5 | |
}, | |
"type": "n8n-nodes-base.stickyNote", | |
"typeVersion": 1, | |
"position": [ | |
840, | |
220 | |
], | |
"id": "5c2cb9a3-6d4f-4063-afd9-2de3b77acc8b", | |
"name": "Sticky Note2" | |
}, | |
{ | |
"parameters": { | |
"conditions": { | |
"options": { | |
"caseSensitive": true, | |
"leftValue": "", | |
"typeValidation": "strict", | |
"version": 2 | |
}, | |
"conditions": [ | |
{ | |
"id": "b29f5208-7031-425b-b12c-e4cd69776054", | |
"leftValue": "={{ $json.body.topic }}", | |
"rightValue": "", | |
"operator": { | |
"type": "string", | |
"operation": "exists", | |
"singleValue": true | |
} | |
}, | |
{ | |
"id": "bcac2f6e-e9f6-4f49-bf18-fa1b12bded75", | |
"leftValue": "={{ $json.message.content }}", | |
"rightValue": "", | |
"operator": { | |
"type": "string", | |
"operation": "exists", | |
"singleValue": true | |
} | |
}, | |
{ | |
"id": "fdef2cb8-1f49-4846-9a66-b0782e6f8b04", | |
"leftValue": "={{ $json.choices[0].message.content }}", | |
"rightValue": "", | |
"operator": { | |
"type": "string", | |
"operation": "exists", | |
"singleValue": true | |
} | |
} | |
], | |
"combinator": "and" | |
}, | |
"options": {} | |
}, | |
"type": "n8n-nodes-base.if", | |
"typeVersion": 2.2, | |
"position": [ | |
1460, | |
-340 | |
], | |
"id": "51f0c298-daf2-4ba7-b14d-939d81295747", | |
"name": "If" | |
}, | |
{ | |
"parameters": { | |
"operation": "toText", | |
"sourceProperty": "message.content", | |
"binaryPropertyName": "=binary", | |
"options": { | |
"encoding": "utf8", | |
"fileName": "={{ `report.md` }}" | |
} | |
}, | |
"type": "n8n-nodes-base.convertToFile", | |
"typeVersion": 1.1, | |
"position": [ | |
2180, | |
-320 | |
], | |
"id": "a0fefee2-e859-45af-8637-ef45953a834e", | |
"name": "Convert to File" | |
}, | |
{ | |
"parameters": { | |
"content": "Message @get_id_bot to get your chat ID", | |
"height": 80, | |
"width": 300 | |
}, | |
"type": "n8n-nodes-base.stickyNote", | |
"typeVersion": 1, | |
"position": [ | |
2320, | |
-380 | |
], | |
"id": "1354b9d1-bf51-4638-8939-5133c5357a19", | |
"name": "Sticky Note3" | |
} | |
], | |
"pinData": {}, | |
"connections": { | |
"Webhook": { | |
"main": [ | |
[ | |
{ | |
"node": "Expert Analysis", | |
"type": "main", | |
"index": 0 | |
}, | |
{ | |
"node": "If", | |
"type": "main", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"Embeddings OpenAI": { | |
"ai_embedding": [ | |
[ | |
{ | |
"node": "Supabase Vector Store", | |
"type": "ai_embedding", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"Default Data Loader": { | |
"ai_document": [ | |
[ | |
{ | |
"node": "Supabase Vector Store", | |
"type": "ai_document", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"Character Text Splitter": { | |
"ai_textSplitter": [ | |
[ | |
{ | |
"node": "Default Data Loader", | |
"type": "ai_textSplitter", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"Embeddings OpenAI1": { | |
"ai_embedding": [ | |
[ | |
{ | |
"node": "Supabase Vector Store Retriever", | |
"type": "ai_embedding", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"Supabase Vector Store Retriever": { | |
"main": [ | |
[ | |
{ | |
"node": "RAG Formatter", | |
"type": "main", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"Experts Review": { | |
"main": [ | |
[ | |
{ | |
"node": "Data Parser", | |
"type": "main", | |
"index": 0 | |
}, | |
{ | |
"node": "OpenAI", | |
"type": "main", | |
"index": 0 | |
}, | |
{ | |
"node": "If", | |
"type": "main", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"Expert Analysis": { | |
"main": [ | |
[ | |
{ | |
"node": "Supabase Vector Store Retriever", | |
"type": "main", | |
"index": 0 | |
}, | |
{ | |
"node": "Data Parser", | |
"type": "main", | |
"index": 0 | |
}, | |
{ | |
"node": "If", | |
"type": "main", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"RAG Formatter": { | |
"main": [ | |
[ | |
{ | |
"node": "Experts Review", | |
"type": "main", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"Data Parser": { | |
"main": [ | |
[ | |
{ | |
"node": "Supabase Vector Store", | |
"type": "main", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"OpenAI": { | |
"main": [ | |
[ | |
{ | |
"node": "Convert to File", | |
"type": "main", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"If": { | |
"main": [ | |
[ | |
{ | |
"node": "OpenAI", | |
"type": "main", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"Convert to File": { | |
"main": [ | |
[ | |
{ | |
"node": "Telegram", | |
"type": "main", | |
"index": 0 | |
} | |
] | |
] | |
}, | |
"Telegram": { | |
"main": [ | |
[] | |
] | |
} | |
}, | |
"active": false, | |
"settings": { | |
"executionOrder": "v1" | |
}, | |
"versionId": "a65aa255-e7d2-47fb-b560-5059cb72b797", | |
"meta": { | |
"templateCredsSetupCompleted": true, | |
"instanceId": "db3c2d3698a1d65c9632c318b0f8874c99c3c8ec38f9fa1684001dc1e7ae08d8" | |
}, | |
"id": "q8FgZjvRFs5C77ZP", | |
"tags": [] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment