Skip to the content.

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:

  1. Visual debugging – see exactly where a task is in the pipeline
  2. No-code routing changes – add a new agent route without touching code
  3. Built-in retry and error handling – n8n handles webhook timeouts, retries, and error branches natively
  4. Credential management – API keys stored securely in n8n, not in agent prompts
  5. 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.

2. Agent Health Monitor

Checks all agent endpoints every 5 minutes. Posts alerts to Slack when an agent is down.

3. Webhook AI Responder

A standalone webhook that accepts questions and returns AI-generated answers. Good starting point for a single-agent setup.

4. Task Registry Sync

Syncs task claims between agents using a SQLite database. Prevents duplicate work.

5. Slack Command Router

Turns Slack messages into agent tasks. Supports /agent codex review this PR syntax.

6. Error Recovery Pipeline

Catches failed agent tasks, retries once, and escalates to human if retry fails.

7. Daily Report Generator

Aggregates metrics from all agents and generates a daily summary.


Setting Up Your First Orchestrator

Step 1: Import the Template

  1. Download ai-agent-orchestrator.json from the GitHub repo
  2. In n8n: Settings > Import Workflow > paste the JSON
  3. Configure credentials (AI provider API key)
  4. 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

  1. Create a new workflow for your agent
  2. Add a Webhook trigger
  3. Add an AI node with your agent’s system prompt
  4. In the orchestrator, add a new Switch route pointing to this webhook
  5. 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

  1. 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.

  2. No timeout handling – Agent calls can hang. Always set HTTP Request timeouts (we use 60-120 seconds) with error branches.

  3. 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).

  4. No execution history cleanup – n8n stores every execution. Set retention to 30 days or your database will grow indefinitely.

  5. 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

Full collection: 49 Production Agent Prompts + All Templates ($29) – use code LAUNCH49 for $10 off


Questions about n8n orchestration? Start a Discussion