Spaces:
No application file

flowwise / SLAVES_Flowise_Workflow
SHIVANSHD's picture
Update SLAVES_Flowise_Workflow
0a22415 verified
Raw History Blame Contribute Delete
21.7 kB
{
"name": "SLAVES - Multi-Agent AI Router",
"nodes": [
{
"id": "webhook-entry",
"name": "Webhook Entry",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
250,
300
],
"webhookId": "slaves-chat",
"parameters": {
"httpMethod": "POST",
"path": "slaves-chat",
"responseMode": "responseNode",
"options": {}
}
},
{
"id": "extract-input",
"name": "Extract Input",
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
450,
300
],
"parameters": {
"mode": "manual",
"fields": {
"values": [
{
"name": "userMessage",
"type": "string",
"value": "={{ $json.body.message || $json.body.text || 'Hello' }}"
},
{
"name": "selectedAgent",
"type": "string",
"value": "={{ $json.body.agent || 'auto' }}"
},
{
"name": "selectedProvider",
"type": "string",
"value": "={{ $json.body.provider || 'auto' }}"
}
]
}
}
},
{
"id": "detect-agent",
"name": "Detect Agent",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
650,
300
],
"parameters": {
"jsCode": "\nconst msg = $input.first().json.userMessage.toLowerCase();\nconst selected = $input.first().json.selectedAgent;\n\nif (selected !== 'auto') {\n return [{ json: { agent: selected, userMessage: $input.first().json.userMessage } }];\n}\n\nconst keywords = {\n researcher: ['research', 'find', 'what is', 'tell me about', 'information', 'latest', 'study'],\n coder: ['code', 'program', 'debug', 'function', 'script', 'bug', 'error', 'python', 'javascript'],\n paper_writer: ['paper', 'abstract', 'methodology', 'thesis', 'academic', 'citation', 'report'],\n planner: ['plan', 'roadmap', 'timeline', 'steps', 'how to', 'break down', 'organize'],\n reviewer: ['review', 'critique', 'feedback', 'evaluate', 'check', 'assess'],\n optimizer: ['optimize', 'improve', 'efficient', 'reduce', 'better', 'faster']\n};\n\nlet detected = 'planner';\nfor (const [agent, words] of Object.entries(keywords)) {\n if (words.some(w => msg.includes(w))) {\n detected = agent;\n break;\n }\n}\n\nreturn [{ json: { agent: detected, userMessage: $input.first().json.userMessage, selectedProvider: $input.first().json.selectedProvider } }];\n"
}
},
{
"id": "agent-switch",
"name": "Agent Switch",
"type": "n8n-nodes-base.switch",
"typeVersion": 2.2,
"position": [
850,
300
],
"parameters": {
"rules": {
"rules": [
{
"value": "researcher",
"output": 0
},
{
"value": "coder",
"output": 1
},
{
"value": "paper_writer",
"output": 2
},
{
"value": "planner",
"output": 3
},
{
"value": "reviewer",
"output": 4
},
{
"value": "optimizer",
"output": 5
}
]
},
"dataType": "string",
"value1": "={{ $json.agent }}",
"fallbackOutput": 3
}
},
{
"id": "researcher-gemini",
"name": "Researcher (Gemini)",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
1100,
-200
],
"parameters": {
"method": "POST",
"url": "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent",
"sendQuery": true,
"queryParameters": {
"parameters": [
{
"name": "key",
"value": "={{ $env.GEMINI_API_KEY }}"
}
]
},
"sendBody": true,
"specifyBody": "json",
"jsonBody": {
"contents": [
{
"role": "user",
"parts": [
{
"text": "You are an expert researcher. Provide thorough, accurate, well-sourced information with key insights.\\n\\nTask: {{ $json.userMessage }}"
}
]
}
],
"generationConfig": {
"maxOutputTokens": 2000,
"temperature": 0.7
}
},
"options": {
"timeout": 40000
}
}
},
{
"id": "coder-groq",
"name": "Coder (Groq)",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
1100,
0
],
"parameters": {
"method": "POST",
"url": "https://api.groq.com/openai/v1/chat/completions",
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth",
"sendBody": true,
"specifyBody": "json",
"jsonBody": {
"model": "llama-3.3-70b-versatile",
"messages": [
{
"role": "system",
"content": "You are an expert programmer. Write clean, efficient, well-commented code with explanations."
},
{
"role": "user",
"content": "={{ $json.userMessage }}"
}
],
"temperature": 0.3,
"max_tokens": 2000
},
"options": {
"timeout": 30000
}
},
"credentials": {
"httpHeaderAuth": {
"id": "groq-cred",
"name": "Groq API"
}
}
},
{
"id": "paper-gemini",
"name": "Paper Writer (Gemini)",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
1100,
200
],
"parameters": {
"method": "POST",
"url": "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent",
"sendQuery": true,
"queryParameters": {
"parameters": [
{
"name": "key",
"value": "={{ $env.GEMINI_API_KEY }}"
}
]
},
"sendBody": true,
"specifyBody": "json",
"jsonBody": {
"contents": [
{
"role": "user",
"parts": [
{
"text": "You are a professional academic writer. Structure with Introduction, Methods, Results, Discussion, Conclusion.\\n\\nTask: {{ $json.userMessage }}"
}
]
}
],
"generationConfig": {
"maxOutputTokens": 2000,
"temperature": 0.5
}
},
"options": {
"timeout": 40000
}
}
},
{
"id": "planner-gemini",
"name": "Planner (Gemini)",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
1100,
400
],
"parameters": {
"method": "POST",
"url": "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent",
"sendQuery": true,
"queryParameters": {
"parameters": [
{
"name": "key",
"value": "={{ $env.GEMINI_API_KEY }}"
}
]
},
"sendBody": true,
"specifyBody": "json",
"jsonBody": {
"contents": [
{
"role": "user",
"parts": [
{
"text": "You are a strategic planner. Break down complex goals into clear, actionable steps with timelines.\\n\\nTask: {{ $json.userMessage }}"
}
]
}
],
"generationConfig": {
"maxOutputTokens": 2000,
"temperature": 0.7
}
},
"options": {
"timeout": 40000
}
}
},
{
"id": "reviewer-gemini",
"name": "Reviewer (Gemini)",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
1100,
600
],
"parameters": {
"method": "POST",
"url": "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent",
"sendQuery": true,
"queryParameters": {
"parameters": [
{
"name": "key",
"value": "={{ $env.GEMINI_API_KEY }}"
}
]
},
"sendBody": true,
"specifyBody": "json",
"jsonBody": {
"contents": [
{
"role": "user",
"parts": [
{
"text": "You are a critical reviewer. Identify strengths, weaknesses, and suggest improvements.\\n\\nTask: {{ $json.userMessage }}"
}
]
}
],
"generationConfig": {
"maxOutputTokens": 2000,
"temperature": 0.5
}
},
"options": {
"timeout": 40000
}
}
},
{
"id": "optimizer-groq",
"name": "Optimizer (Groq)",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
1100,
800
],
"parameters": {
"method": "POST",
"url": "https://api.groq.com/openai/v1/chat/completions",
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth",
"sendBody": true,
"specifyBody": "json",
"jsonBody": {
"model": "llama-3.3-70b-versatile",
"messages": [
{
"role": "system",
"content": "You are an efficiency optimizer. Analyze and suggest improvements for performance and clarity."
},
{
"role": "user",
"content": "={{ $json.userMessage }}"
}
],
"temperature": 0.3,
"max_tokens": 2000
},
"options": {
"timeout": 30000
}
},
"credentials": {
"httpHeaderAuth": {
"id": "groq-cred",
"name": "Groq API"
}
}
},
{
"id": "format-researcher",
"name": "Format Researcher",
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
1350,
-200
],
"parameters": {
"mode": "manual",
"fields": {
"values": [
{
"name": "response",
"type": "string",
"value": "={{ $json.candidates[0].content.parts[0].text }}"
},
{
"name": "agent",
"type": "string",
"value": "\ud83d\udd2c Researcher"
},
{
"name": "provider",
"type": "string",
"value": "\ud83d\udd2c Gemini"
},
{
"name": "model",
"type": "string",
"value": "gemini-2.5-flash"
}
]
}
}
},
{
"id": "format-coder",
"name": "Format Coder",
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
1350,
0
],
"parameters": {
"mode": "manual",
"fields": {
"values": [
{
"name": "response",
"type": "string",
"value": "={{ $json.choices[0].message.content }}"
},
{
"name": "agent",
"type": "string",
"value": "\ud83d\udcbb Coder"
},
{
"name": "provider",
"type": "string",
"value": "\ud83d\ude80 Groq"
},
{
"name": "model",
"type": "string",
"value": "llama-3.3-70b-versatile"
}
]
}
}
},
{
"id": "format-paper",
"name": "Format Paper",
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
1350,
200
],
"parameters": {
"mode": "manual",
"fields": {
"values": [
{
"name": "response",
"type": "string",
"value": "={{ $json.candidates[0].content.parts[0].text }}"
},
{
"name": "agent",
"type": "string",
"value": "\ud83d\udcdd Paper Writer"
},
{
"name": "provider",
"type": "string",
"value": "\ud83d\udd2c Gemini"
},
{
"name": "model",
"type": "string",
"value": "gemini-2.5-flash"
}
]
}
}
},
{
"id": "format-planner",
"name": "Format Planner",
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
1350,
400
],
"parameters": {
"mode": "manual",
"fields": {
"values": [
{
"name": "response",
"type": "string",
"value": "={{ $json.candidates[0].content.parts[0].text }}"
},
{
"name": "agent",
"type": "string",
"value": "\ud83d\udccb Planner"
},
{
"name": "provider",
"type": "string",
"value": "\ud83d\udd2c Gemini"
},
{
"name": "model",
"type": "string",
"value": "gemini-2.5-flash"
}
]
}
}
},
{
"id": "format-reviewer",
"name": "Format Reviewer",
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
1350,
600
],
"parameters": {
"mode": "manual",
"fields": {
"values": [
{
"name": "response",
"type": "string",
"value": "={{ $json.candidates[0].content.parts[0].text }}"
},
{
"name": "agent",
"type": "string",
"value": "\u2705 Reviewer"
},
{
"name": "provider",
"type": "string",
"value": "\ud83d\udd2c Gemini"
},
{
"name": "model",
"type": "string",
"value": "gemini-2.5-flash"
}
]
}
}
},
{
"id": "format-optimizer",
"name": "Format Optimizer",
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
1350,
800
],
"parameters": {
"mode": "manual",
"fields": {
"values": [
{
"name": "response",
"type": "string",
"value": "={{ $json.choices[0].message.content }}"
},
{
"name": "agent",
"type": "string",
"value": "\u26a1 Optimizer"
},
{
"name": "provider",
"type": "string",
"value": "\ud83d\ude80 Groq"
},
{
"name": "model",
"type": "string",
"value": "llama-3.3-70b-versatile"
}
]
}
}
},
{
"id": "merge-outputs",
"name": "Merge Outputs",
"type": "n8n-nodes-base.merge",
"typeVersion": 3,
"position": [
1600,
300
],
"parameters": {
"mode": "append"
}
},
{
"id": "final-format",
"name": "Final Format",
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
1800,
300
],
"parameters": {
"mode": "manual",
"fields": {
"values": [
{
"name": "response",
"type": "string",
"value": "={{ $json.response }}"
},
{
"name": "metadata",
"type": "string",
"value": "\ud83c\udfaf {{ $json.agent }} | \u2601\ufe0f {{ $json.provider }} | \ud83d\udd27 {{ $json.model }}"
},
{
"name": "fullResponse",
"type": "string",
"value": "={{ $json.response }}\\n\\n---\\n{{ $json.metadata }}"
}
]
}
}
},
{
"id": "respond-webhook",
"name": "Respond to Webhook",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1.1,
"position": [
2000,
300
],
"parameters": {
"respondWith": "json",
"jsonBody": {
"response": "={{ $json.fullResponse }}",
"agent": "={{ $json.agent }}",
"provider": "={{ $json.provider }}",
"model": "={{ $json.model }}"
},
"statusCode": 200
}
}
],
"connections": {
"Webhook Entry": {
"main": [
[
{
"node": "Extract Input",
"type": "main",
"index": 0
}
]
]
},
"Extract Input": {
"main": [
[
{
"node": "Detect Agent",
"type": "main",
"index": 0
}
]
]
},
"Detect Agent": {
"main": [
[
{
"node": "Agent Switch",
"type": "main",
"index": 0
}
]
]
},
"Agent Switch": {
"main": [
[
{
"node": "Researcher (Gemini)",
"type": "main",
"index": 0
}
],
[
{
"node": "Coder (Groq)",
"type": "main",
"index": 0
}
],
[
{
"node": "Paper Writer (Gemini)",
"type": "main",
"index": 0
}
],
[
{
"node": "Planner (Gemini)",
"type": "main",
"index": 0
}
],
[
{
"node": "Reviewer (Gemini)",
"type": "main",
"index": 0
}
],
[
{
"node": "Optimizer (Groq)",
"type": "main",
"index": 0
}
]
]
},
"Researcher (Gemini)": {
"main": [
[
{
"node": "Format Researcher",
"type": "main",
"index": 0
}
]
]
},
"Coder (Groq)": {
"main": [
[
{
"node": "Format Coder",
"type": "main",
"index": 0
}
]
]
},
"Paper Writer (Gemini)": {
"main": [
[
{
"node": "Format Paper",
"type": "main",
"index": 0
}
]
]
},
"Planner (Gemini)": {
"main": [
[
{
"node": "Format Planner",
"type": "main",
"index": 0
}
]
]
},
"Reviewer (Gemini)": {
"main": [
[
{
"node": "Format Reviewer",
"type": "main",
"index": 0
}
]
]
},
"Optimizer (Groq)": {
"main": [
[
{
"node": "Format Optimizer",
"type": "main",
"index": 0
}
]
]
},
"Format Researcher": {
"main": [
[
{
"node": "Merge Outputs",
"type": "main",
"index": 0
}
]
]
},
"Format Coder": {
"main": [
[
{
"node": "Merge Outputs",
"type": "main",
"index": 0
}
]
]
},
"Format Paper": {
"main": [
[
{
"node": "Merge Outputs",
"type": "main",
"index": 0
}
]
]
},
"Format Planner": {
"main": [
[
{
"node": "Merge Outputs",
"type": "main",
"index": 0
}
]
]
},
"Format Reviewer": {
"main": [
[
{
"node": "Merge Outputs",
"type": "main",
"index": 0
}
]
]
},
"Format Optimizer": {
"main": [
[
{
"node": "Merge Outputs",
"type": "main",
"index": 0
}
]
]
},
"Merge Outputs": {
"main": [
[
{
"node": "Final Format",
"type": "main",
"index": 0
}
]
]
},
"Final Format": {
"main": [
[
{
"node": "Respond to Webhook",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"tags": [
"SLAVES",
"AI",
"Router",
"Multi-Agent"
]
}