{
  "name": "Route AI tasks between Anthropic Claude models with Postgres policies and SLA",
  "nodes": [
    {
      "id": "0becb529-f4bf-4033-b90f-f2f7caabae8a",
      "name": "Task Input Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -1616,
        80
      ]
    },
    {
      "id": "e46430e8-1081-4511-a38c-16d1fdbf54ae",
      "name": "Workflow Configuration",
      "type": "n8n-nodes-base.set",
      "position": [
        -1360,
        80
      ]
    },
    {
      "id": "a298d196-218a-4cd0-8c4c-fdc00ab4ee40",
      "name": "Task Classifier Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -1136,
        80
      ]
    },
    {
      "id": "6564841d-fb51-4a1d-8721-451ccf0fa77f",
      "name": "Load Policy Rules",
      "type": "n8n-nodes-base.postgres",
      "position": [
        -784,
        80
      ]
    },
    {
      "id": "d867f0a1-76e8-4df1-84c6-1f155b84bca5",
      "name": "Policy Engine Decision",
      "type": "n8n-nodes-base.code",
      "position": [
        -624,
        80
      ]
    },
    {
      "id": "5cbd74df-80e5-4389-88e8-eefebafe5084",
      "name": "Route by Model Selection",
      "type": "n8n-nodes-base.switch",
      "position": [
        -272,
        64
      ]
    },
    {
      "id": "5b78b42d-1d6e-4c7f-a496-cce92e0e6e01",
      "name": "Large Model Execution",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        48,
        656
      ]
    },
    {
      "id": "d40f3de4-3bce-448f-afc6-2a98801832f4",
      "name": "Store Telemetry",
      "type": "n8n-nodes-base.postgres",
      "position": [
        640,
        192
      ]
    },
    {
      "id": "a40d7801-17d7-4f74-b00b-d5202126a41d",
      "name": "Return Response",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        992,
        192
      ]
    },
    {
      "id": "527af998-2b05-4141-933e-1e8ffe960e44",
      "name": "Weekly Self-Tuning Schedule",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -1584,
        768
      ]
    },
    {
      "id": "14f9e6bb-1e94-4b89-81ff-5025b1aeddb1",
      "name": "Fetch Historical Data",
      "type": "n8n-nodes-base.postgres",
      "position": [
        -1312,
        768
      ]
    },
    {
      "id": "81d0b945-eb1d-4f6e-abaf-b4b37a2e0f98",
      "name": "Aggregate Success Metrics",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        -1040,
        768
      ]
    },
    {
      "id": "50e7ded2-aa27-42d8-b72a-e005c6511f24",
      "name": "Calculate Routing Adjustments",
      "type": "n8n-nodes-base.code",
      "position": [
        -848,
        768
      ]
    },
    {
      "id": "8186382f-38a1-4471-8433-bae6bff34298",
      "name": "Update Policy Rules",
      "type": "n8n-nodes-base.postgres",
      "position": [
        -512,
        768
      ]
    },
    {
      "id": "bf404937-2cab-4730-9d3f-23bec52b23c7",
      "name": "Anthropic Chat Model - Classifier",
      "type": "@n8n/n8n-nodes-langchain.lmChatAnthropic",
      "position": [
        -1168,
        288
      ]
    },
    {
      "id": "5b225513-a16e-44cb-b78c-d1e5e49246e5",
      "name": "Classification Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        -912,
        304
      ]
    },
    {
      "id": "5c540c6b-5829-4306-bd9d-d5d3d17d583a",
      "name": "Anthropic Chat Model - Small",
      "type": "@n8n/n8n-nodes-langchain.lmChatAnthropic",
      "position": [
        96,
        -192
      ]
    },
    {
      "id": "5163a1cc-433c-47f0-b7be-d38d92701f4a",
      "name": "Anthropic Chat Model - Large",
      "type": "@n8n/n8n-nodes-langchain.lmChatAnthropic",
      "position": [
        -112,
        784
      ]
    },
    {
      "id": "07413d00-5c68-415e-b92a-bde152e43f68",
      "name": "Prepare Telemetry Data",
      "type": "n8n-nodes-base.set",
      "position": [
        400,
        192
      ]
    },
    {
      "id": "b3e3e753-0909-40fb-b131-a3e39352fc5a",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1248,
        -176
      ],
      "parameters": {
        "width": 800,
        "height": 592,
        "content": "## Policy Engine\n\nLoads routing policies from the database and combines them with task classification results.\n\nThe policy engine determines:\n\n• model size (small or large)  \n• token limits  \n• latenc"
      }
    },
    {
      "id": "3050af39-dbed-4aa3-be9a-f5fd58e5c4df",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1728,
        608
      ],
      "parameters": {
        "width": 288,
        "height": 320,
        "content": "## Weekly Optimization Trigger\n\nThis scheduled trigger runs once per week to analyze LLM execution performance."
      }
    },
    {
      "id": "47a36f16-2712-4371-b065-cf785a833892",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1760,
        -112
      ],
      "parameters": {
        "width": 336,
        "height": 400,
        "content": "## Input\n\nEach request contains a task and optional priority metadata.  \nThis webhook acts as the API entry point for the LLM orchestration system."
      }
    },
    {
      "id": "258ba5db-8fb4-44b8-8e1f-0adb7318e2d0",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1088,
        608
      ],
      "parameters": {
        "width": 400,
        "height": 336,
        "content": "## Performance Aggregation\n\nTelemetry records are grouped by task type to calculate overall performance metrics.\n"
      }
    },
    {
      "id": "7640f65e-389b-404f-b9f4-fc10cb428942",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1424,
        608
      ],
      "parameters": {
        "width": 320,
        "height": 320,
        "content": "## Historical Telemetry Analysis\n\nExecution telemetry from the past 7 days is retrieved from the database."
      }
    },
    {
      "id": "adf0417d-65c1-4c5e-a2e5-ab82c2ba1169",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -672,
        608
      ],
      "parameters": {
        "width": 416,
        "height": 336,
        "content": "## Automatic Policy Optimization\n\nModel performance is analyzed to determine if routing policies should change.\nIf a smaller model performs well, it may replace a larger one."
      }
    },
    {
      "id": "3e307f55-1408-4d9c-8794-3f6b59e7c29d",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        224,
        -64
      ],
      "parameters": {
        "width": 624,
        "height": 448,
        "content": "## Telemetry Collection\n\nExecution metrics are captured after each task:\n\n• latency  \n• tokens used  \n• estimated cost  \n• model used  \n• success status\n\nThese metrics are stored for monitoring and op"
      }
    },
    {
      "id": "6854ce54-122a-496a-b142-baca4ad8b0e9",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        864,
        -48
      ],
      "parameters": {
        "width": 384,
        "height": 400,
        "content": " API Response\n\nThe workflow returns the AI response along with execution metadata including latency, model used, and estimated cost."
      }
    },
    {
      "id": "0c5dbc16-ab23-436f-a95e-897cf410b776",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -176,
        464
      ],
      "parameters": {
        "width": 544,
        "height": 448,
        "content": "## Large Model Execution\n\nProcesses complex tasks that require deeper reasoning or higher accuracy.\n\nUsed when the policy engine detects low confidence, high priority, or reasoning tasks."
      }
    },
    {
      "id": "bc9d56ff-ecae-40d0-ad6a-62525ae1cbff",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -432,
        -144
      ],
      "parameters": {
        "width": 336,
        "height": 528,
        "content": "## Model Routing\n\nTasks are routed to different model pipelines depending on policy decisions.\n"
      }
    },
    {
      "id": "1d11df13-0164-42b1-bdb5-c3147a097fbd",
      "name": "Sticky Note11",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -256,
        -624
      ],
      "parameters": {
        "width": 720,
        "height": 464,
        "content": "## Small Model Execution\n\nHandles lightweight tasks such as extraction or classification.\n\nOptimized for speed and cost efficiency while respecting token and latency limits."
      }
    },
    {
      "id": "03475ddc-9a8d-49ee-8284-2dbd4e86aeca",
      "name": "Small Model Execution",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        0,
        -400
      ]
    },
    {
      "id": "49f091e1-1b4d-41a9-9c34-5733482af0b9",
      "name": "Sticky Note12",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2576,
        -64
      ],
      "parameters": {
        "width": 688,
        "height": 736,
        "content": "## Policy-Driven LLM Orchestrator with Self-Tuning Model Routing\n\nThis workflow acts as an intelligent orchestration layer for large language models. Instead of sending every task to a single model, i"
      }
    }
  ],
  "connections": {
    "Store Telemetry": {
      "main": [
        [
          {
            "node": "Return Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Load Policy Rules": {
      "main": [
        [
          {
            "node": "Policy Engine Decision",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Task Input Webhook": {
      "main": [
        [
          {
            "node": "Workflow Configuration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Historical Data": {
      "main": [
        [
          {
            "node": "Aggregate Success Metrics",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Large Model Execution": {
      "main": [
        [
          {
            "node": "Prepare Telemetry Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Small Model Execution": {
      "main": [
        [
          {
            "node": "Prepare Telemetry Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Task Classifier Agent": {
      "main": [
        [
          {
            "node": "Load Policy Rules",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Policy Engine Decision": {
      "main": [
        [
          {
            "node": "Route by Model Selection",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Telemetry Data": {
      "main": [
        [
          {
            "node": "Store Telemetry",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Workflow Configuration": {
      "main": [
        [
          {
            "node": "Task Classifier Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route by Model Selection": {
      "main": [
        [
          {
            "node": "Small Model Execution",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Large Model Execution",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate Success Metrics": {
      "main": [
        [
          {
            "node": "Calculate Routing Adjustments",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Weekly Self-Tuning Schedule": {
      "main": [
        [
          {
            "node": "Fetch Historical Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Anthropic Chat Model - Large": {
      "ai_languageModel": [
        [
          {
            "node": "Large Model Execution",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Anthropic Chat Model - Small": {
      "ai_languageModel": [
        [
          {
            "node": "Small Model Execution",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Classification Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Task Classifier Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Routing Adjustments": {
      "main": [
        [
          {
            "node": "Update Policy Rules",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Anthropic Chat Model - Classifier": {
      "ai_languageModel": [
        [
          {
            "node": "Task Classifier Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  }
}