{
  "id": "goodaitriage0001",
  "name": "good-ai-triage",
  "nodes": [
    {
      "parameters": {},
      "id": "d0000000-0000-4000-8000-000000000001",
      "name": "Manual",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.ticket }}",
        "hasOutputParser": false,
        "needsFallback": false,
        "options": {
          "maxIterations": 3
        }
      },
      "id": "d0000000-0000-4000-8000-000000000002",
      "name": "Classify",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [
        220,
        0
      ],
      "retryOnFail": true,
      "maxTries": 2,
      "onError": "stopWorkflow"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "id",
          "value": "primary-model"
        },
        "responsesApiEnabled": false,
        "options": {
          "timeout": 20000,
          "temperature": 0
        }
      },
      "id": "d0000000-0000-4000-8000-000000000003",
      "name": "Primary Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        160,
        200
      ],
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const SCHEMA = { category: ['billing', 'technical'] };\nlet parsed = null;\nconst errors = [];\ntry { parsed = JSON.parse(String($json.output).replace(/```json|```/g, '').trim()); }\ncatch (e) { errors.push('not valid JSON'); }\nfunction validate(v) { return v && typeof v.category === 'string' && SCHEMA.category.includes(v.category); }\nreturn [{ json: { valid: errors.length === 0 && validate(parsed), triage: parsed, errors } }];"
      },
      "id": "d0000000-0000-4000-8000-000000000004",
      "name": "Validate",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        440,
        0
      ]
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.ticket }}",
        "needsFallback": false
      },
      "id": "d0000000-0000-4000-8000-000000000005",
      "name": "Fallback Chain",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.9,
      "position": [
        440,
        240
      ],
      "retryOnFail": true,
      "maxTries": 2,
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "model": "deepseek-chat",
        "options": {
          "timeout": 20000,
          "temperature": 0
        }
      },
      "id": "d0000000-0000-4000-8000-000000000006",
      "name": "Fallback Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatDeepSeek",
      "typeVersion": 1,
      "position": [
        380,
        440
      ],
      "credentials": {
        "deepSeekApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "INSERT INTO triage_result (ticket_id, execution_id, category, urgency, summary, requires_human, provider) VALUES ($1, $2, $3, $4, $5, $6::boolean, $7) RETURNING id;",
        "options": {
          "queryReplacement": "={{ [$json.id, $execution.id, $json.triage.category, 'normal', 'summary', false, 'primary'] }}"
        }
      },
      "id": "d0000000-0000-4000-8000-000000000007",
      "name": "Store",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.7,
      "position": [
        660,
        0
      ],
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Manual": {
      "main": [
        [
          {
            "node": "Classify",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Classify": {
      "main": [
        [
          {
            "node": "Validate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate": {
      "main": [
        [
          {
            "node": "Store",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Fallback Chain",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fallback Chain": {
      "main": [
        [
          {
            "node": "Validate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Primary Model": {
      "ai_languageModel": [
        [
          {
            "node": "Classify",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Fallback Model": {
      "ai_languageModel": [
        [
          {
            "node": "Fallback Chain",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "errorWorkflow": "errhandler0000001",
    "timezone": "Australia/Brisbane"
  },
  "active": false
}