n8n AI Agent Orchestrator: Route Tasks Between AI Agents
How we use n8n to orchestrate 57 AI agents with 65 workflows. Free templates included.
Why n8n for Agent Orchestration
Most agent frameworks handle orchestration in code. We use n8n instead because:
- Visual debugging – see exactly where a task is in the pipeline
- No-code routing changes – add a new agent route without touching code
- Built-in retry and error handling – n8n handles webhook timeouts, retries, and error branches natively
- Credential management – API keys stored securely in n8n, not in agent prompts
- Execution history – every task routed, every response logged, searchable
Architecture Overview
User Request
|
v
[Webhook Trigger] --> [AI Classifier] --> [Switch Node]
|
+-------------------------+-------------------------+
| | | | |
v v v v v
[Code Agent] [Security] [Trading] [Business] [General]
| | | | |
v v v v v
[Response Formatter] --> [Output Webhook / Slack / Chat]
Key Components
1. Webhook Trigger Every task enters through a single webhook endpoint. The payload includes the task description, priority, and optional agent preference.
{
"query": "Review this Python script for security issues",
"priority": "high",
"source": "slack",
"preferred_agent": "security"
}
2. AI Classifier (Brain Node) An AI node (we use DeepSeek for cost efficiency) analyzes the query and returns the target agent:
You are a task router. Analyze the query and return ONE agent name:
- codex: code, bugs, scripts, testing
- security: vulnerabilities, audits, hardening
- trading: market analysis, signals, risk
- business: revenue, outreach, products
- general: everything else
Query:
Return ONLY the agent name, nothing else.
3. Switch Node Routes to the correct agent workflow based on the classifier output. Each agent has its own sub-workflow with specialized system prompts.
4. Response Formatter Standardizes output across all agents into a consistent format before sending back to the user.
The 7 Free Workflow Templates
We provide 7 production-tested n8n workflows as JSON files, ready to import:
1. AI Agent Orchestrator
The main routing workflow. Receives tasks via webhook, classifies them, and routes to specialized agents.
- Trigger: Webhook
- Nodes: AI Classifier, Switch (7 routes), Sub-workflow calls, Response merger
- Use case: Central task routing
2. Agent Health Monitor
Checks all agent endpoints every 5 minutes. Posts alerts to Slack when an agent is down.
- Trigger: Cron (5 min)
- Nodes: HTTP Request (per agent), IF (status check), Slack notification
- Use case: Production monitoring
3. Webhook AI Responder
A standalone webhook that accepts questions and returns AI-generated answers. Good starting point for a single-agent setup.
- Trigger: Webhook
- Nodes: AI node, Response formatter
- Use case: Quick AI endpoint
4. Task Registry Sync
Syncs task claims between agents using a SQLite database. Prevents duplicate work.
- Trigger: Webhook (called by agents)
- Nodes: SQLite query, Duplicate check, Claim/Release logic
- Use case: Multi-agent coordination
5. Slack Command Router
Turns Slack messages into agent tasks. Supports /agent codex review this PR syntax.
- Trigger: Slack webhook
- Nodes: Command parser, Agent router, Response poster
- Use case: Chat-based agent interaction
6. Error Recovery Pipeline
Catches failed agent tasks, retries once, and escalates to human if retry fails.
- Trigger: Error webhook
- Nodes: Retry logic, Timeout handler, Human escalation (Slack/email)
- Use case: Production resilience
7. Daily Report Generator
Aggregates metrics from all agents and generates a daily summary.
- Trigger: Cron (daily)
- Nodes: Metric collectors, AI summarizer, Report formatter, Slack post
- Use case: Operational visibility
Setting Up Your First Orchestrator
Step 1: Import the Template
- Download
ai-agent-orchestrator.jsonfrom the GitHub repo - In n8n: Settings > Import Workflow > paste the JSON
- Configure credentials (AI provider API key)
- Activate the workflow
Step 2: Test with a Simple Query
curl -X POST "https://your-n8n.example.com/webhook/orchestrator" \
-H "Content-Type: application/json" \
-d '{"query": "What time is it in Tokyo?", "source": "test"}'
Step 3: Add Your First Specialized Agent
- Create a new workflow for your agent
- Add a Webhook trigger
- Add an AI node with your agent’s system prompt
- In the orchestrator, add a new Switch route pointing to this webhook
- Update the classifier prompt to include the new agent
Step 4: Scale
Repeat Step 3 for each new agent. The orchestrator handles routing automatically.
Production Patterns We Use
Pattern 1: Timeout Cascading
Agent timeout (60s) --> Retry with simpler prompt (30s) --> Fallback to general agent --> Human alert
Pattern 2: Cost-Based Routing
Simple query --> DeepSeek ($0.001/query)
Complex query --> Claude Sonnet ($0.01/query)
Critical query --> Claude Opus ($0.05/query)
Pattern 3: Agent Memory via Sub-Workflows
Each agent call includes a “memory fetch” sub-workflow that retrieves relevant context from a knowledge graph before processing.
Pattern 4: Parallel Agent Consultation
For complex decisions, route to multiple agents simultaneously, then merge their outputs:
Query --> [Code Agent] ----+
--> [Security Agent] +--> [Merge Node] --> [AI Synthesizer] --> Response
--> [Business Agent] +
Common Mistakes
-
Routing everything through AI – Use keyword matching for obvious routes (e.g., “security scan” always goes to security agent). Reserve AI classification for ambiguous queries.
-
No timeout handling – Agent calls can hang. Always set HTTP Request timeouts (we use 60-120 seconds) with error branches.
-
Flat routing – With 10+ agents, a single Switch node becomes unwieldy. Use sub-workflow groups (e.g., “code-agents” group routes to specific code sub-agents).
-
No execution history cleanup – n8n stores every execution. Set retention to 30 days or your database will grow indefinitely.
-
Hardcoded prompts in n8n – Keep long system prompts in external files (AGENT.md). n8n nodes should only contain the routing logic, not the full agent prompt.
Resources
- 7 Free n8n Workflow Templates (JSON) – ready to import
- Multi-Agent System Tutorial – build from scratch
- Framework Comparison – n8n vs CrewAI vs LangGraph
- 5 Production Patterns – patterns that survived 10,000+ tasks
Full collection: 49 Production Agent Prompts + All Templates ($29) – use code LAUNCH49 for $10 off
Questions about n8n orchestration? Start a Discussion