{
  "name": "06 - Bug Triage Agent",
  "nodes": [
    {
      "parameters": {
        "content": "## 06 Bug Triage Agent\nWe have: 3 failed TTACart tests.\nWe get: category, severity, duplicate and owner for each.\n\nAdd your OpenAI credential, then click Execute workflow.",
        "height": 180,
        "width": 440
      },
      "id": "06000000-0000-4000-8000-000000000000",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -60,
        -240
      ]
    },
    {
      "parameters": {},
      "id": "06000000-0000-4000-8000-000000000001",
      "name": "Start",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "// 3 failures from the TTACart Playwright suite (sample data)\nreturn [\n  { json: { test: 'checkout › order total includes tax', error: 'Expected \"Total: $43.18\", received \"Total: $39.98\"' } },\n  { json: { test: 'inventory › error_user can add backpack to cart', error: 'Expected cart badge \"1\", received \"\". Passed on retry #1' } },\n  { json: { test: 'login › performance_glitch_user logs in', error: 'TimeoutError: page.waitForURL: Timeout 3000ms exceeded' } },\n];"
      },
      "id": "06000000-0000-4000-8000-000000000002",
      "name": "Failed Tests",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        220,
        0
      ]
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Failed test: {{ $json.test }}\nError: {{ $json.error }}",
        "options": {
          "systemMessage": "You triage failed Playwright tests for TTACart.\n1. Call search_open_bugs with key words from the failure.\n2. category: product_bug, test_bug, flaky or environment. Passed on retry = flaky. A timeout shorter than a known slow step = test_bug.\n3. severity: P1 login or checkout down, P2 wrong result in a main flow, P3 intermittent or minor, P4 test code only.\n4. If an open bug matches, use its key and owner. Otherwise duplicateOf is \"\" and owner is \"QA\".\nKnown: performance_glitch_user takes about 4 seconds to log in, by design.\n\nReply with JSON only:\n{\"test\":\"\",\"category\":\"\",\"severity\":\"\",\"duplicateOf\":\"\",\"owner\":\"\",\"summary\":\"\"}"
        }
      },
      "id": "06000000-0000-4000-8000-000000000003",
      "name": "Triage Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.7,
      "position": [
        440,
        0
      ]
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "id": "06000000-0000-4000-8000-000000000004",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        380,
        220
      ]
    },
    {
      "parameters": {
        "name": "search_open_bugs",
        "description": "Searches open TTACart bugs. Input: key words from the failure. Returns matching bugs with key, title and owner.",
        "jsCode": "// Sample open bugs. Going live: replace this node with a Jira tool.\nconst openBugs = [\n  { key: 'CART-101', title: 'Order total missing tax on checkout', owner: 'Ravi' },\n  { key: 'CART-102', title: 'Add to cart randomly fails for error_user', owner: 'Meena' },\n  { key: 'CART-103', title: 'Cart badge misaligned for visual_user', owner: 'Asha' },\n];\nconst skip = ['the', 'and', 'for', 'with', 'test'];\nconst words = String(query).toLowerCase().split(/\\W+/).filter(w => w.length > 2 && !skip.includes(w));\nconst hits = openBugs\n  .map(b => ({ ...b, score: words.filter(w => b.title.toLowerCase().includes(w)).length }))\n  .filter(b => b.score > 0)\n  .sort((a, b) => b.score - a.score);\nreturn hits.length ? JSON.stringify(hits.slice(0, 2)) : 'No open bug matches.';"
      },
      "id": "06000000-0000-4000-8000-000000000005",
      "name": "search_open_bugs",
      "type": "@n8n/n8n-nodes-langchain.toolCode",
      "typeVersion": 1.1,
      "position": [
        540,
        220
      ]
    },
    {
      "parameters": {
        "jsCode": "// The agent replies with JSON text. Turn it into fields you can use.\nreturn $input.all().map(i => ({\n  json: JSON.parse(String(i.json.output).replace(/```(json)?/g, '').trim()),\n}));"
      },
      "id": "06000000-0000-4000-8000-000000000006",
      "name": "Parse Result",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        760,
        0
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Failed Tests",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Failed Tests": {
      "main": [
        [
          {
            "node": "Triage Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Triage Agent": {
      "main": [
        [
          {
            "node": "Parse Result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Triage Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "search_open_bugs": {
      "ai_tool": [
        [
          {
            "node": "Triage Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "active": false
}
