How to Build a Multi-Agent AI System with n8n and Claude
A step-by-step guide from building one agent to coordinating 49. Based on 6 months of production experience.
Why Multi-Agent?
A single AI agent works great for simple tasks. But real-world automation requires specialization:
- A coding agent that understands your codebase
- A security agent that audits vulnerabilities
- A business agent that tracks leads and revenue
- An orchestrator that routes tasks to the right specialist
This guide shows you how to build this from scratch using n8n for automation and Claude (or any LLM) for intelligence.
Architecture Overview
User Request
|
v
+------------------+
| Orchestrator | <-- Routes tasks to specialists
| (Brain Agent) |
+--------+---------+
|
+----+----+----------+-----------+
v v v v v
Code Sec Biz Research Creative
Agent Agent Agent Agent Agent
Step 1: Build Your First Agent (30 minutes)
The System Prompt
Every agent needs a system prompt that defines:
- Identity – who the agent is
- Capabilities – what tools it has access to
- Constraints – what it should NOT do
- Output format – how it should respond
Here is a minimal example:
## Identity
You are a Code Review Agent. You analyze code for bugs, security issues, and best practices.
## Capabilities
- Read files from the repository
- Search code with grep/ripgrep
- Run tests with pytest/jest
- Access git history
## Constraints
- Never modify code directly -- suggest changes only
- Never expose credentials found in code
- Always cite file paths and line numbers
## Output Format
For each issue found:
- **File**: path/to/file.py
- **Line**: 42
- **Severity**: HIGH/MEDIUM/LOW
- **Issue**: Description
- **Fix**: Suggested change
The n8n Workflow
Create a webhook that accepts requests and returns AI responses:
- Webhook node – receives POST requests with
{query, context} - Set node – formats the prompt (system prompt + user query)
- HTTP Request node – calls the LLM API (Claude, OpenAI, etc.)
- Respond to Webhook – returns the AI response
Import our Webhook AI Responder template to get started in 3 minutes.
Step 2: Add a Second Agent (15 minutes)
Duplicate your first workflow and change:
- The webhook path (e.g.,
/webhook/security-agent) - The system prompt (now focused on security)
- The model parameters if needed
Now you have two specialists. But who decides which one handles what?
Step 3: Build the Orchestrator (45 minutes)
The orchestrator is the brain. It receives all requests and routes them to the right specialist.
Classification Logic
The simplest approach: keyword-based routing.
If query contains "code", "bug", "test", "function" -> Code Agent
If query contains "security", "vulnerability", "CVE" -> Security Agent
If query contains "revenue", "lead", "sales" -> Business Agent
Else -> General Agent (or ask the user to clarify)
For smarter routing, use an LLM to classify:
You are a task router. Given a user query, respond with exactly one word:
- CODE: for programming, debugging, testing tasks
- SECURITY: for vulnerability, audit, penetration testing tasks
- BUSINESS: for revenue, leads, sales, marketing tasks
- RESEARCH: for information gathering, analysis tasks
- GENERAL: for anything else
Query: {user_query}
Classification:
Anti-Duplication
The number 1 problem in multi-agent systems: duplicate work. Two agents processing the same task wastes compute and creates conflicts.
Solution: hash each incoming task and check against a recent task list.
// In n8n Code node
const taskHash = require('crypto')
.createHash('md5')
.update(items[0].json.query)
.digest('hex');
const recentTasks = $getWorkflowStaticData('global');
const taskList = recentTasks.tasks || [];
// Check for duplicates in last 30 minutes
const thirtyMinAgo = Date.now() - 30 * 60 * 1000;
const isDuplicate = taskList.some(t =>
t.hash === taskHash && t.timestamp > thirtyMinAgo
);
if (!isDuplicate) {
taskList.push({ hash: taskHash, timestamp: Date.now() });
// Keep only last 100 tasks
recentTasks.tasks = taskList.slice(-100);
}
return [{ json: { ...items[0].json, taskHash, isDuplicate } }];
Import our Multi-Agent Orchestrator with Dedup for the complete implementation.
Step 4: Add Communication (30 minutes)
Agents need to report back. Set up:
- Slack integration – agents post results to channels
- Error workflows – catch failures and alert immediately
- Health checks – periodic pings to verify all agents are responding
Our AI Health Monitor template handles the health check pattern.
Step 5: Scale to 5+ Agents (ongoing)
The Pattern That Works
For each new agent:
- Write a focused system prompt (200-500 lines)
- Create a brain workflow (webhook -> LLM -> response)
- Create satellite workflows (single-purpose automations)
- Register the agent in the orchestrator routing table
- Test with 10 sample queries before going live
The Pattern That Fails
- God agents – one agent that does everything. It becomes unreliable fast.
- No deduplication – 30-40% compute waste from duplicate tasks.
- No error handling – one failed API call cascades to all agents.
- No health monitoring – you find out agents are down from users, not alerts.
Production Lessons (6 Months, 57 Agents)
- HTTP timeouts: Set 120s minimum for any LLM API call. Default 30s kills most requests.
- Webhook security: Add Bearer token validation to every webhook on day 1.
- Separate brain from satellites: Brain = LLM logic. Satellite = pure automation. Debug time drops 10x.
- Cost control: Route simple tasks to cheaper models (GPT-4o-mini, DeepSeek). Save Claude/GPT-4 for complex work.
- Memory: Without context, agents repeat mistakes. Add a knowledge graph or database for persistent memory.
Free Resources
- Orchestrator system prompt – the complete production orchestrator, free and open-source
- 7 n8n workflow templates – import and customize
- CLI tools – generate agent prompts from command line
- Production patterns cheat sheet – 5 patterns that keep multi-agent systems alive
Full Agent Collection
The free orchestrator handles coordination. For the 48 specialist agents across 7 domains (security, trading, infrastructure, revenue, intelligence, creative, utility), see the full collection on Gumroad – $29, use code LAUNCH49 for $10 off.
Built by the Guardian AI team. Questions? Open a Discussion.