{
  "nodes": [
    {
      "id": "1f86ecbb-5537-4f51-9308-8467de6e3086",
      "name": "Workflow Configuration",
      "type": "n8n-nodes-base.set",
      "position": [
        -1024,
        416
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "id-1",
              "name": "userRequest",
              "type": "string",
              "value": "<__PLACEHOLDER_VALUE__User task request__>"
            },
            {
              "id": "id-2",
              "name": "confidenceThreshold",
              "type": "number",
              "value": 0.7
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "3c733f0d-9593-4cb2-9bf2-e2b150ad6d96",
      "name": "Supervisor Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -704,
        416
      ],
      "parameters": {
        "text": "={{ $json.userRequest }}",
        "options": {
          "systemMessage": "You are a supervisor agent that analyzes incoming task requests and determines the appropriate complexity level.\n\nYour task is to:\n1. Analyze the user request for complexity indicators (multi-step reasoning, domain expertise, data analysis needs)\n2. Assign a complexity level: \"simple\" or \"complex\"\n3. Provide a confidence score (0.0 to 1.0) indicating how certain you are about the classification\n4. Provide a brief reasoning for your decision\n\nClassification guidelines:\n- Simple tasks: Basic questions, single-step operations, straightforward information retrieval\n- Complex tasks: Multi-step reasoning, domain expertise required, data analysis, creative problem-solving\n\nReturn your analysis in the structured JSON format."
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 3
    },
    {
      "id": "87b3f378-e254-4b5f-b9ce-550a237386f6",
      "name": "Routing Decision Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        -496,
        688
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n\t\"type\": \"object\",\n\t\"properties\": {\n\t\t\"complexity\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"enum\": [\"simple\", \"complex\"],\n\t\t\t\"description\": \"Task complexity level\"\n\t\t},\n\t\t\"confidence\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"minimum\": 0,\n\t\t\t\"maximum\": 1,\n\t\t\t\"description\": \"Confidence score for the classification\"\n\t\t},\n\t\t\"reasoning\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"description\": \"Brief explanation of the classification decision\"\n\t\t}\n\t},\n\t\"required\": [\"complexity\", \"confidence\", \"reasoning\"]\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "5a7aee06-bc64-469a-83eb-4d778266d519",
      "name": "OpenAI Model - Supervisor",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -720,
        688
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "typeVersion": 1.3
    },
    {
      "id": "2ba932b7-7cc1-4641-8ace-3bb12fb8a9c1",
      "name": "Check Confidence Score",
      "type": "n8n-nodes-base.if",
      "position": [
        -256,
        416
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "id-1",
              "operator": {
                "type": "number",
                "operation": "gte"
              },
              "leftValue": "={{ $json.confidence }}",
              "rightValue": "={{ $('Workflow Configuration').first().json.confidenceThreshold }}"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "2680d576-5f06-4270-843d-9ad09e95cfb4",
      "name": "Simple Task Agent Tool",
      "type": "@n8n/n8n-nodes-langchain.agentTool",
      "position": [
        400,
        400
      ],
      "parameters": {
        "text": "={{ $fromAI(\"task\", \"The task to process\") }}",
        "options": {
          "systemMessage": "You are a simple task agent specialized in handling straightforward requests.\n\nYour capabilities:\n- Answer basic questions\n- Provide simple information\n- Perform single-step operations\n- Give quick, concise responses\n\nProvide clear, direct answers without unnecessary complexity."
        },
        "toolDescription": "Handles straightforward tasks like basic questions and simple information retrieval"
      },
      "typeVersion": 2.2
    },
    {
      "id": "11689a4f-09bd-4405-9913-a4a89922a6ea",
      "name": "Complex Task Agent Tool",
      "type": "@n8n/n8n-nodes-langchain.agentTool",
      "position": [
        864,
        272
      ],
      "parameters": {
        "text": "={{ $fromAI(\"task\", \"The task to process\") }}",
        "options": {
          "systemMessage": "You are a complex task agent specialized in handling sophisticated requests.\n\nYour capabilities:\n- Multi-step reasoning and problem-solving\n- In-depth analysis and research\n- Domain expertise application\n- Creative problem-solving\n- Detailed explanations and comprehensive responses\n\nProvide thorough, well-reasoned answers with supporting details and step-by-step explanations when appropriate."
        },
        "toolDescription": "Handles complex tasks requiring multi-step reasoning, analysis, or domain expertise"
      },
      "typeVersion": 2.2
    },
    {
      "id": "93cd8ec4-628b-4a0c-b76f-49a95fbd7e44",
      "name": "OpenAI Model - Complex Agent",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        848,
        480
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "typeVersion": 1.3
    },
    {
      "id": "399805b8-c387-43ec-bcc1-f8b89327af2c",
      "name": "Execute Selected Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        160,
        -64
      ],
      "parameters": {
        "text": "={{ $('Workflow Configuration').first().json.userRequest }}",
        "options": {
          "systemMessage": "=You are an orchestrator agent that executes tasks by delegating to specialized agents.\n\nYour task is to:\n1. Analyze the user request\n2. Determine which specialized agent tool to call based on the task complexity from the supervisor\n3. Call the Simple Task Agent Tool for simple requests\n4. Call the Complex Task Agent Tool for complex requests\n5. Return the final result from the selected agent\n\nTask complexity classification: {{ $json.complexity }}\nReasoning: {{ $json.reasoning }}"
        },
        "promptType": "define"
      },
      "typeVersion": 3
    },
    {
      "id": "dc06e31a-1c0a-4844-94ba-b5a95659bc8e",
      "name": "OpenAI Model - Executor",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        160,
        336
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "typeVersion": 1.3
    },
    {
      "id": "3d20e481-bc02-4035-9956-30df4bc8725a",
      "name": "Send Fallback Alert",
      "type": "n8n-nodes-base.emailSend",
      "position": [
        96,
        832
      ],
      "parameters": {
        "text": "=A task was classified with low confidence and requires human review.\n\nUser Request: {{ $('Workflow Configuration').first().json.userRequest }}\n\nClassification: {{ $json.complexity }}\nConfidence Score: {{ $json.confidence }}\nReasoning: {{ $json.reasoning }}\n\nThreshold: {{ $('Workflow Configuration').first().json.confidenceThreshold }}\n\nPlease review this task manually.",
        "options": {},
        "subject": "Low Confidence Alert: Task Classification Uncertain",
        "toEmail": "<__PLACEHOLDER_VALUE__Admin email address__>",
        "fromEmail": "<__PLACEHOLDER_VALUE__Sender email address__>",
        "emailFormat": "text"
      },
      "typeVersion": 2.1
    },
    {
      "id": "f1cd0989-b5a2-4b1f-9f0e-26e883fe4ec0",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -1344,
        416
      ],
      "parameters": {
        "path": "3b249fb4-729e-4b50-b120-c5619d12c9a8",
        "options": {},
        "responseMode": "lastNode"
      },
      "typeVersion": 2.1
    },
    {
      "id": "c36337f8-3614-4247-bcff-0ce3a7e9a362",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2016,
        176
      ],
      "parameters": {
        "width": 432,
        "height": 512,
        "content": "## How it works\nThis workflow receives a user request via webhook and analyzes it using a supervisor AI agent. The agent classifies the request as either simple or complex and assigns a confidence score.\n\nIf the confidence meets the threshold, the workflow routes the task to the appropriate agent (simple or complex) using an orchestrator agent. Each agent processes the request using an LLM and returns a response.\n\nIf the confidence is too low, the workflow sends an email alert for manual review instead of executing the task.\n\n## Setup steps\n- Add OpenAI credentials for all AI nodes\n- Configure the webhook endpoint\n- Set sender and recipient email in alert node\n- Adjust confidence threshold if needed\n- Customize system prompts for agents"
      },
      "typeVersion": 1
    },
    {
      "id": "6fe73538-4911-48a8-a7ee-da109ffe497e",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1440,
        288
      ],
      "parameters": {
        "color": 7,
        "width": 592,
        "height": 304,
        "content": "## Input Layer\nWebhook trigger + initial workflow configuration"
      },
      "typeVersion": 1
    },
    {
      "id": "fb415b2a-1c69-47c2-b619-3e48a9a3848c",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -784,
        224
      ],
      "parameters": {
        "color": 7,
        "width": 400,
        "height": 384,
        "content": "## Task Classification\nSupervisor agent analyzes and scores complexity"
      },
      "typeVersion": 1
    },
    {
      "id": "5b159947-392f-45f3-8939-71d7f282e64b",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -336,
        256
      ],
      "parameters": {
        "color": 7,
        "width": 288,
        "height": 336,
        "content": "## Confidence Check\nValidate if classification meets threshold"
      },
      "typeVersion": 1
    },
    {
      "id": "774ad184-1500-49b1-810c-8d207a19b935",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        16,
        720
      ],
      "parameters": {
        "color": 7,
        "width": 288,
        "height": 304,
        "content": "## Fallback Handling\nSend email alert when confidence is low"
      },
      "typeVersion": 1
    },
    {
      "id": "014cc263-1021-4a81-b09a-925cef93c0af",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        48,
        -176
      ],
      "parameters": {
        "color": 7,
        "width": 528,
        "height": 272,
        "content": "## Execution Router\nOrchestrator selects correct agent tool"
      },
      "typeVersion": 1
    },
    {
      "id": "3c10d872-9409-441d-9c57-916df17dd084",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        368,
        272
      ],
      "parameters": {
        "color": 7,
        "width": 336,
        "height": 272,
        "content": "## Simple Task Flow\nHandles quick, single-step user requests"
      },
      "typeVersion": 1
    },
    {
      "id": "e059039c-f4eb-4180-8075-1ed5dd473be6",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        832,
        160
      ],
      "parameters": {
        "color": 7,
        "width": 336,
        "height": 304,
        "content": "## Complex Task Flow\nHandles multi-step reasoning and analysis"
      },
      "typeVersion": 1
    },
    {
      "id": "bcba6b09-059d-4f3c-8980-f6c3b6835a0c",
      "name": "OpenAI Model - Simple Agent(mini-model)",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        400,
        592
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "typeVersion": 1.3
    },
    {
      "id": "45ec0a62-1bfd-4a2a-afef-6f3d815b834d",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        64,
        224
      ],
      "parameters": {
        "color": 7,
        "width": 272,
        "height": 288,
        "content": "## AI Processing Core\nAll LLM models powering agents and routing"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Workflow Configuration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Supervisor Agent": {
      "main": [
        [
          {
            "node": "Check Confidence Score",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Confidence Score": {
      "main": [
        [
          {
            "node": "Execute Selected Agent",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send Fallback Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Task Agent Tool": {
      "ai_tool": [
        [
          {
            "node": "Execute Selected Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Workflow Configuration": {
      "main": [
        [
          {
            "node": "Supervisor Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Complex Task Agent Tool": {
      "ai_tool": [
        [
          {
            "node": "Execute Selected Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Model - Executor": {
      "ai_languageModel": [
        [
          {
            "node": "Execute Selected Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Routing Decision Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Supervisor Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Model - Supervisor": {
      "ai_languageModel": [
        [
          {
            "node": "Supervisor Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Model - Complex Agent": {
      "ai_languageModel": [
        [
          {
            "node": "Complex Task Agent Tool",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Model - Simple Agent(mini-model)": {
      "ai_languageModel": [
        [
          {
            "node": "Simple Task Agent Tool",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  }
}