This workflow follows the Chainllm → Execute Workflow 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 →
{
"name": "Agente_RAG_final",
"nodes": [
{
"parameters": {
"inputSource": "passthrough"
},
"id": "c055762a-8fe7-4141-a639-df2372f30060",
"typeVersion": 1.1,
"name": "When_Executed_by_Main_Workflow",
"type": "n8n-nodes-base.executeWorkflowTrigger",
"position": [
272,
352
]
},
{
"parameters": {
"method": "POST",
"url": "https://openrouter.ai/api/v1/embeddings",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "Authorization",
"value": "Bearer YOUR_API_KEY"
},
{
"name": "Content-Type",
"value": "application/json"
}
]
},
"sendBody": true,
"bodyParameters": {
"parameters": [
{
"name": "model",
"value": "text-embedding-3-small"
},
{
"name": "input",
"value": "={{ $json.mensaje_actual }}"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.4,
"position": [
496,
352
],
"id": "9cab4f9b-a774-42b9-ae51-82928d5bdf1f",
"name": "Embeddings_Openrouter"
},
{
"parameters": {
"jsCode": "const embedding = $input.first().json.data[0].embedding;\nconst datos = $('When_Executed_by_Main_Workflow').first().json;\n\nreturn [{\n json: {\n ...datos,\n embedding: JSON.stringify(embedding)\n }\n}];"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
704,
352
],
"id": "9c24bbe8-af20-48f3-a980-85f197c646db",
"name": "Parsear_embedding_mensaje"
},
{
"parameters": {
"operation": "executeQuery",
"query": "SELECT contenido, metadata, similarity\nFROM buscar_documentos(\n '{{ $json.embedding }}'::vector,\n 5,\n 0.5\n);",
"options": {}
},
"type": "n8n-nodes-base.postgres",
"typeVersion": 2.6,
"position": [
912,
352
],
"id": "b1588b8f-bd22-42a4-aff6-9f7983021728",
"name": "Buscar_documentos",
"alwaysOutputData": true,
"credentials": {
"postgres": {
"name": "<your credential>"
}
}
},
{
"parameters": {
"jsCode": "const docs = $input.all();\nconst datos = $('When_Executed_by_Main_Workflow').first().json;\n\nlet contexto = '';\nif (docs.length === 0 || !docs[0].json.contenido) {\n contexto = 'No se encontr\u00f3 informaci\u00f3n relevante en los documentos.';\n} else {\n contexto = docs.map((d, i) => \n `[Fuente ${i+1}] (similitud: ${(d.json.similarity * 100).toFixed(1)}%):\\n${d.json.contenido}`\n ).join('\\n\\n');\n}\n\nreturn [{\n json: {\n ...datos,\n contexto\n }\n}];"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1120,
352
],
"id": "490bc121-3126-4b3a-8693-1ff6eba3484b",
"name": "Formatear_contexto"
},
{
"parameters": {
"promptType": "define",
"text": "={{ $json.mensaje_actual }}",
"needsFallback": true,
"messages": {
"messageValues": [
{
"type": "HumanMessagePromptTemplate",
"message": "=Historial previo:\n{{ $json.historial_texto }}\n\nInformaci\u00f3n disponible:\n{{ $json.contexto }}\n\nPregunta del cliente: {{ $json.mensaje_actual }}"
},
{
"message": "Eres un asistente virtual de Inmobiliaria CBBA, Cochabamba, Bolivia. Respondes preguntas de clientes usando \u00daNICAMENTE la informaci\u00f3n del contexto proporcionado. Reglas importantes: - Responde SOLO con informaci\u00f3n del contexto - Si el contexto no tiene la informaci\u00f3n, di: \"No tengo esa informaci\u00f3n disponible, te recomiendo contactarnos directamente\" - Menciona siempre la fuente (Fuente 1, Fuente 2, etc.) - S\u00e9 amable, conciso y profesional - Responde en espa\u00f1ol - No inventes precios, direcciones ni datos que no est\u00e9n en el contexto"
}
]
},
"batching": {}
},
"type": "@n8n/n8n-nodes-langchain.chainLlm",
"typeVersion": 1.9,
"position": [
1344,
352
],
"id": "ea966399-33e7-440b-94cd-e84eb04e581f",
"name": "Basic LLM Chain"
},
{
"parameters": {
"model": "llama-3.1-8b-instant",
"options": {
"temperature": 0.2
}
},
"type": "@n8n/n8n-nodes-langchain.lmChatGroq",
"typeVersion": 1,
"position": [
1296,
624
],
"id": "38b63ac0-d402-4498-97fa-853b6fcc7925",
"name": "Groq Chat Model",
"credentials": {
"groqApi": {
"name": "<your credential>"
}
}
},
{
"parameters": {
"options": {
"temperature": 0.2
}
},
"type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
"typeVersion": 1,
"position": [
1488,
624
],
"id": "f8829f3f-8685-40e0-8e02-7201ebf7b23d",
"name": "Google Gemini Chat Model",
"credentials": {
"googlePalmApi": {
"name": "<your credential>"
}
}
},
{
"parameters": {
"jsCode": "const respuesta = $input.first().json.text;\nconst datos = $('When_Executed_by_Main_Workflow').first().json;\n\nreturn [{\n json: {\n ...datos,\n respuesta: respuesta,\n agente_usado: 'RAG'\n }\n}];"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1696,
352
],
"id": "32ecf915-da2b-464a-be7b-a61dbf1f5b58",
"name": "Formatear_respuesta_RAG"
}
],
"connections": {
"When_Executed_by_Main_Workflow": {
"main": [
[
{
"node": "Embeddings_Openrouter",
"type": "main",
"index": 0
}
]
]
},
"Embeddings_Openrouter": {
"main": [
[
{
"node": "Parsear_embedding_mensaje",
"type": "main",
"index": 0
}
]
]
},
"Parsear_embedding_mensaje": {
"main": [
[
{
"node": "Buscar_documentos",
"type": "main",
"index": 0
}
]
]
},
"Buscar_documentos": {
"main": [
[
{
"node": "Formatear_contexto",
"type": "main",
"index": 0
}
]
]
},
"Groq Chat Model": {
"ai_languageModel": [
[
{
"node": "Basic LLM Chain",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Google Gemini Chat Model": {
"ai_languageModel": [
[
{
"node": "Basic LLM Chain",
"type": "ai_languageModel",
"index": 1
}
]
]
},
"Formatear_contexto": {
"main": [
[
{
"node": "Basic LLM Chain",
"type": "main",
"index": 0
}
]
]
},
"Basic LLM Chain": {
"main": [
[
{
"node": "Formatear_respuesta_RAG",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1",
"availableInMCP": false,
"timeSavedMode": "fixed",
"errorWorkflow": "Lg4ma3dxwZeqgxOJDE0ew",
"callerPolicy": "workflowsFromSameOwner",
"binaryMode": "separate"
},
"versionId": "77f0058a-6210-411d-896e-4b947678bbf1",
"meta": {
"templateCredsSetupCompleted": true
},
"id": "6UBqCSPwybMxiOQ0",
"tags": []
}
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.
googlePalmApigroqApipostgres
For the full experience including quality scoring and batch install features for each workflow upgrade to Pro
About this workflow
Agente_RAG_final. Uses executeWorkflowTrigger, httpRequest, postgres, chainLlm. Event-driven trigger; 9 nodes.
Source: https://github.com/sergioRancibia/n8n-automation-ai-agents-portfolio/blob/main/n8n-ai-automation-system/workflows/agente-rag.json — 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.
Bitlab-Chatbot. Uses telegramTrigger, telegram, snowflake, httpRequest. Event-driven trigger; 87 nodes.
Any-File2Json-Converter. Uses chainLlm, lmChatGroq, outputParserStructured, executeWorkflowTrigger. Event-driven trigger; 30 nodes.
Episode 11: AI shorts factory app. Uses httpRequest, googleSheets, lmChatOpenAi, lmChatOllama. Event-driven trigger; 96 nodes.
Content - Newsletter Agent. Uses formTrigger, chainLlm, outputParserStructured, httpRequest. Event-driven trigger; 91 nodes.
This template attempts to replicate OpenAI's DeepResearch feature which, at time of writing, is only available to their pro subscribers.