Skip to the content.

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:

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:

  1. Identity – who the agent is
  2. Capabilities – what tools it has access to
  3. Constraints – what it should NOT do
  4. 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:

  1. Webhook node – receives POST requests with {query, context}
  2. Set node – formats the prompt (system prompt + user query)
  3. HTTP Request node – calls the LLM API (Claude, OpenAI, etc.)
  4. 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:

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:

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:

  1. Write a focused system prompt (200-500 lines)
  2. Create a brain workflow (webhook -> LLM -> response)
  3. Create satellite workflows (single-purpose automations)
  4. Register the agent in the orchestrator routing table
  5. Test with 10 sample queries before going live

The Pattern That Fails

Production Lessons (6 Months, 57 Agents)

  1. HTTP timeouts: Set 120s minimum for any LLM API call. Default 30s kills most requests.
  2. Webhook security: Add Bearer token validation to every webhook on day 1.
  3. Separate brain from satellites: Brain = LLM logic. Satellite = pure automation. Debug time drops 10x.
  4. Cost control: Route simple tasks to cheaper models (GPT-4o-mini, DeepSeek). Save Claude/GPT-4 for complex work.
  5. Memory: Without context, agents repeat mistakes. Add a knowledge graph or database for persistent memory.

Free Resources

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.