{
  "nodes": [
    {
      "id": "4110189b-d37c-4040-8c5b-12df0e049c0b",
      "name": "Workflow Configuration",
      "type": "n8n-nodes-base.set",
      "position": [
        -944,
        400
      ],
      "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": "97813aa7-54cc-41ab-a1ae-76e1e5f3d11c",
      "name": "Supervisor Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -720,
        400
      ],
      "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": "ec13c899-9b19-4750-895e-8115b3855839",
      "name": "Routing Decision Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        -576,
        624
      ],
      "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": "e4813bd0-c750-4197-9c0c-2b22c1eb9b9f",
      "name": "OpenAI Model - Supervisor",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -704,
        624
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "typeVersion": 1.3
    },
    {
      "id": "c9aaadea-65a9-4fef-b418-2d4959289115",
      "name": "Check Confidence Score",
      "type": "n8n-nodes-base.if",
      "position": [
        -352,
        400
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "id-1",
              "operator": {
                "type": "number",
                "operation": "gte"
              },
              "leftValue": "={{ $json.confidence }}",
              "rightValue": "={{ $('Workflow Configuration').first().json.confidenceThreshold }}"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "0b8bb7f5-ddde-48de-afec-e36e300a146a",
      "name": "OpenAI Model - Simple Agent",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        32,
        416
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "typeVersion": 1.3
    },
    {
      "id": "1da98644-06c5-4fad-9a9e-046bca69c79a",
      "name": "Execute Selected Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        192,
        -176
      ],
      "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": "f577a529-76af-48c5-a293-599f6afcc1fe",
      "name": "OpenAI Model - Executor",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        64,
        -32
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "typeVersion": 1.3
    },
    {
      "id": "cc11ac92-7751-40c8-92a9-4632d0b8379d",
      "name": "Send Fallback Alert",
      "type": "n8n-nodes-base.emailSend",
      "position": [
        208,
        768
      ],
      "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": "f142cee8-b073-4ae1-a547-c58b0c0229be",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -800,
        224
      ],
      "parameters": {
        "color": 7,
        "width": 384,
        "height": 528,
        "content": "## Task Classification\n\nThe Supervisor Agent analyzes the user request and determines whether the task is simple or complex."
      },
      "typeVersion": 1
    },
    {
      "id": "8366aa47-d487-4198-ab9b-bfdc565ce017",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        64,
        592
      ],
      "parameters": {
        "color": 7,
        "width": 400,
        "height": 304,
        "content": "##  Alert\n\nIf the confidence is below the configured threshold, an email alert is sent to an administrator requesting manual review to prevent incorrect automated responses."
      },
      "typeVersion": 1
    },
    {
      "id": "3c844f95-4189-40c8-a33c-448baf675ad3",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -32,
        -336
      ],
      "parameters": {
        "color": 7,
        "width": 576,
        "height": 416,
        "content": "## Agent Orchestration\n\nAn orchestrator AI agent decides which specialized tool to call based on the supervisor\u2019s classification.\nThe request is  either the Simple Task Agent or the Complex Task Agent"
      },
      "typeVersion": 1
    },
    {
      "id": "c0390db3-93f3-43d0-b41d-63361c249aa7",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        112
      ],
      "parameters": {
        "color": 7,
        "width": 720,
        "height": 432,
        "content": "## Two specialized agents handle task execution:\n\nSimple Task Agent for straightforward questions and quick responses.\n\nComplex Task Agent for multi-step reasoning, deeper analysis, and detailed explanations.\n\nThis separation improves response quality and efficiency."
      },
      "typeVersion": 1
    },
    {
      "id": "51daaa69-4904-4d84-afe2-e7604f6f29ad",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1280,
        288
      ],
      "parameters": {
        "color": 7,
        "width": 288,
        "height": 288,
        "content": "## Workflow Start\n\n\nA WEBHOOK trigger starts the execution "
      },
      "typeVersion": 1
    },
    {
      "id": "3c1fa43d-b198-419e-8e40-d3a7d2b7fce4",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -1200,
        400
      ],
      "parameters": {
        "path": "b62c065b-ab0a-41f5-81f8-c5207fbcd892",
        "options": {},
        "responseMode": "responseNode"
      },
      "typeVersion": 2.1
    },
    {
      "id": "82002223-7e98-411b-8cc2-3d214089376d",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -384,
        288
      ],
      "parameters": {
        "color": 7,
        "height": 256,
        "content": "## Check Confidence Score"
      },
      "typeVersion": 1
    },
    {
      "id": "038ed7d0-2abf-4d91-b4fa-23bd579a5b77",
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        544,
        -176
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.5
    },
    {
      "id": "33e2c29b-21d5-43d9-9d40-2cf4d4b40764",
      "name": "OpenAI Model - Complex Agent GPT 5.3",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        368,
        416
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "typeVersion": 1.3
    },
    {
      "id": "89a00fe3-2673-4c0d-b62e-d07d31041373",
      "name": "Complex Task Agent Tool (5.4)",
      "type": "@n8n/n8n-nodes-langchain.agentTool",
      "position": [
        448,
        304
      ],
      "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": "e00c5a1f-4c35-490c-9770-7ae1d62f2c66",
      "name": "Simple Task Agent Tool(5 MINI)",
      "type": "@n8n/n8n-nodes-langchain.agentTool",
      "position": [
        112,
        320
      ],
      "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": "fe5032bb-736b-4614-9b2b-b4898cfb621f",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1872,
        192
      ],
      "parameters": {
        "width": 512,
        "height": 480,
        "content": "## AI Task Routing with Supervisor Agent\n\nThis workflow intelligently analyzes incoming user requests and routes them to the most appropriate AI agent based on task complexity. When a request is received through the webhook, it is first stored in the configuration step along with a confidence threshold.\n\nA Supervisor Agent then evaluates the request and classifies it as either simple or complex, returning a confidence score and reasoning for its decision. The workflow checks whether this confidence score meets the defined threshold.\n\nIf the confidence is sufficient, an orchestrator agent delegates the task to a specialized AI tool. Simple requests are handled by a Simple Task Agent, while more advanced requests are processed by a Complex Task Agent capable of deeper reasoning.\n\nIf the confidence score is too low, the workflow sends an email alert for human review, ensuring reliable and controlled AI automation."
      },
      "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
          }
        ]
      ]
    },
    "Execute Selected Agent": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Workflow Configuration": {
      "main": [
        [
          {
            "node": "Supervisor Agent",
            "type": "main",
            "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 - Simple Agent": {
      "ai_languageModel": [
        [
          {
            "node": "Simple Task Agent Tool(5 MINI)",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Complex Task Agent Tool (5.4)": {
      "ai_tool": [
        [
          {
            "node": "Execute Selected Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Simple Task Agent Tool(5 MINI)": {
      "ai_tool": [
        [
          {
            "node": "Execute Selected Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Model - Complex Agent GPT 5.3": {
      "ai_languageModel": [
        [
          {
            "node": "Complex Task Agent Tool (5.4)",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  }
}