{
  "name": "07 - RCA Agent",
  "nodes": [
    {
      "parameters": {
        "content": "## 07 RCA Agent\nWe have: 1 failed test (order total is missing tax).\nWe get: root cause, suspect commit, confidence and fix, backed by evidence.\n\nAdd your OpenAI credential, then click Execute workflow.\nOpen the agent's logs to see both tool calls.",
        "height": 200,
        "width": 460
      },
      "id": "07000000-0000-4000-8000-000000000000",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -60,
        -260
      ]
    },
    {
      "parameters": {},
      "id": "07000000-0000-4000-8000-000000000001",
      "name": "Start",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "52b23152-f00d-517f-8a6b-355bbfa5c681",
              "name": "test",
              "value": "checkout › order total includes tax",
              "type": "string"
            },
            {
              "id": "45400c6e-fc1f-5cba-85df-e214d6b35602",
              "name": "error",
              "value": "Expected \"Total: $43.18\", received \"Total: $39.98\"",
              "type": "string"
            },
            {
              "id": "8c0daef5-2132-5587-8006-5788de563334",
              "name": "failedAt",
              "value": "10:42 on staging",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "07000000-0000-4000-8000-000000000002",
      "name": "Failed Test",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        220,
        0
      ]
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Test: {{ $json.test }}\nFailed at: {{ $json.failedAt }}\nError: {{ $json.error }}",
        "options": {
          "systemMessage": "You find the root cause of a failed Playwright test on TTACart.\n1. Always call get_recent_commits and get_app_logs first.\n2. Every claim needs evidence: a commit sha or a log line.\n3. Weak evidence = confidence \"low\". Do not guess.\n\nReply with JSON only:\n{\"rootCause\":\"\",\"evidence\":[\"\"],\"suspectCommit\":\"\",\"confidence\":\"high|medium|low\",\"fix\":\"\"}"
        }
      },
      "id": "07000000-0000-4000-8000-000000000003",
      "name": "RCA 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": "07000000-0000-4000-8000-000000000004",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        340,
        220
      ]
    },
    {
      "parameters": {
        "name": "get_recent_commits",
        "description": "Returns commits merged to main in the last 24 hours: sha, author, message and files.",
        "jsCode": "// Sample commits. Going live: call the GitHub commits API here.\nreturn JSON.stringify([\n  { sha: '9f2c1ab', author: 'Ravi', message: 'Move tax calculation behind ENABLE_TAX_V2 flag', files: ['src/checkout/totals.ts'] },\n  { sha: '4b7d0e3', author: 'Meena', message: 'Add retry around add-to-cart request', files: ['src/inventory/cart.ts'] },\n  { sha: 'c81e5a2', author: 'Asha', message: 'Update footer links', files: ['src/ui/footer.tsx'] },\n]);"
      },
      "id": "07000000-0000-4000-8000-000000000005",
      "name": "get_recent_commits",
      "type": "@n8n/n8n-nodes-langchain.toolCode",
      "typeVersion": 1.1,
      "position": [
        500,
        220
      ]
    },
    {
      "parameters": {
        "name": "get_app_logs",
        "description": "Returns staging log lines from around the time of the failure.",
        "jsCode": "// Sample staging logs. Going live: query Loki, Datadog or ELK here.\nreturn [\n  '10:42:01 INFO checkout subtotal=39.98',\n  '10:42:01 WARN flags ENABLE_TAX_V2 not set in staging, defaulting to false',\n  '10:42:01 INFO checkout tax skipped, total=39.98',\n].join('\\n');"
      },
      "id": "07000000-0000-4000-8000-000000000006",
      "name": "get_app_logs",
      "type": "@n8n/n8n-nodes-langchain.toolCode",
      "typeVersion": 1.1,
      "position": [
        660,
        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": "07000000-0000-4000-8000-000000000007",
      "name": "Parse Result",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        760,
        0
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Failed Test",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Failed Test": {
      "main": [
        [
          {
            "node": "RCA Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "RCA Agent": {
      "main": [
        [
          {
            "node": "Parse Result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "RCA Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "get_recent_commits": {
      "ai_tool": [
        [
          {
            "node": "RCA Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "get_app_logs": {
      "ai_tool": [
        [
          {
            "node": "RCA Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "active": false
}
