{
  "name": "Clara Answers \u2014 Demo \u2192 Agent Pipeline",
  "nodes": [
    {
      "parameters": {
        "path": "pipeline-a",
        "httpMethod": "POST",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "webhook-pipeline-a",
      "name": "Webhook: Pipeline A Trigger",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        250,
        300
      ],
      "notes": "POST /webhook/pipeline-a\nBody: { transcript_path, account_id (optional) }"
    },
    {
      "parameters": {
        "path": "pipeline-b",
        "httpMethod": "POST",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "webhook-pipeline-b",
      "name": "Webhook: Pipeline B Trigger",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        250,
        550
      ],
      "notes": "POST /webhook/pipeline-b\nBody: { account_id, onboarding_path }"
    },
    {
      "parameters": {
        "path": "batch-run",
        "httpMethod": "POST",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "webhook-batch",
      "name": "Webhook: Batch Runner Trigger",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        250,
        800
      ],
      "notes": "POST /webhook/batch-run\nBody: { dataset_dir (optional) }"
    },
    {
      "parameters": {
        "command": "cd /app && python3 scripts/pipeline_a.py --transcript {{ $json.transcript_path }} --account-id {{ $json.account_id || '' }} --output-root outputs/accounts 2>&1"
      },
      "id": "exec-pipeline-a",
      "name": "Execute: Pipeline A",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        550,
        300
      ],
      "notes": "Runs Pipeline A script in container.\nOutputs stdout log."
    },
    {
      "parameters": {
        "command": "cd /app && python3 scripts/pipeline_b.py --account-id {{ $json.account_id }} --onboarding {{ $json.onboarding_path }} --output-root outputs/accounts 2>&1"
      },
      "id": "exec-pipeline-b",
      "name": "Execute: Pipeline B",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        550,
        550
      ],
      "notes": "Runs Pipeline B script.\nRequires v1 to exist for account_id."
    },
    {
      "parameters": {
        "command": "cd /app && python3 scripts/batch_runner.py --dataset-dir {{ $json.dataset_dir || 'data' }} --output-root outputs/accounts 2>&1"
      },
      "id": "exec-batch",
      "name": "Execute: Batch Runner",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        550,
        800
      ],
      "notes": "Runs all 5 demo + 5 onboarding in sequence.\nOutputs batch_summary.json."
    },
    {
      "parameters": {
        "jsCode": "const output = $input.first().json;\nconst exitCode = output.exitCode || 0;\nconst stdout = output.stdout || '';\n\nconst success = exitCode === 0 && stdout.includes('\u2705');\n\n// Parse account info from stdout\nconst accountMatch = stdout.match(/Account:\\s+([^\\n]+)/);\nconst versionMatch = stdout.match(/Version:\\s+(v\\d+)/);\nconst outputMatch = stdout.match(/Output:\\s+([^\\n]+)/);\n\nreturn [{\n  json: {\n    success,\n    exit_code: exitCode,\n    account: accountMatch ? accountMatch[1].trim() : 'unknown',\n    version: versionMatch ? versionMatch[1].trim() : 'unknown',\n    output_path: outputMatch ? outputMatch[1].trim() : 'unknown',\n    log: stdout,\n    timestamp: new Date().toISOString()\n  }\n}];"
      },
      "id": "parse-a-result",
      "name": "Parse Pipeline A Result",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        800,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "const output = $input.first().json;\nconst exitCode = output.exitCode || 0;\nconst stdout = output.stdout || '';\n\nconst success = exitCode === 0 && stdout.includes('\u2705');\n\nconst changesMatch = stdout.match(/Changes:\\s+(\\d+)/);\nconst sectionsMatch = stdout.match(/Sections:\\s+([^\\n]+)/);\n\nreturn [{\n  json: {\n    success,\n    exit_code: exitCode,\n    total_changes: changesMatch ? parseInt(changesMatch[1]) : 0,\n    affected_sections: sectionsMatch ? sectionsMatch[1].trim() : '',\n    log: stdout,\n    timestamp: new Date().toISOString()\n  }\n}];"
      },
      "id": "parse-b-result",
      "name": "Parse Pipeline B Result",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        800,
        550
      ]
    },
    {
      "parameters": {
        "jsCode": "const output = $input.first().json;\nconst stdout = output.stdout || '';\n\n// Parse batch summary\nconst paMatch = stdout.match(/Pipeline A: (\\d+)\\/(\\d+)/);\nconst pbMatch = stdout.match(/Pipeline B: (\\d+) succeeded/);\n\nreturn [{\n  json: {\n    success: output.exitCode === 0,\n    pipeline_a_success: paMatch ? parseInt(paMatch[1]) : 0,\n    pipeline_a_total: paMatch ? parseInt(paMatch[2]) : 0,\n    pipeline_b_success: pbMatch ? parseInt(pbMatch[1]) : 0,\n    log: stdout,\n    timestamp: new Date().toISOString()\n  }\n}];"
      },
      "id": "parse-batch-result",
      "name": "Parse Batch Result",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        800,
        800
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ $json }}"
      },
      "id": "respond-a",
      "name": "Respond: Pipeline A",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        1050,
        300
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ $json }}"
      },
      "id": "respond-b",
      "name": "Respond: Pipeline B",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        1050,
        550
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ $json }}"
      },
      "id": "respond-batch",
      "name": "Respond: Batch",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        1050,
        800
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $json.success }}",
              "value2": true
            }
          ]
        }
      },
      "id": "check-a-success",
      "name": "Check A Success",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        900,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "// Log failed run to error log\nconst timestamp = new Date().toISOString();\nconst errorEntry = {\n  timestamp,\n  pipeline: 'A',\n  input: $input.first().json,\n  error: $input.first().json.log\n};\nconsole.error('Pipeline A failed:', JSON.stringify(errorEntry));\nreturn [{ json: { error: true, message: 'Pipeline A failed', details: errorEntry } }];"
      },
      "id": "handle-a-error",
      "name": "Handle Pipeline A Error",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1050,
        200
      ]
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 24
            }
          ]
        }
      },
      "id": "schedule-batch",
      "name": "Schedule: Daily Batch (Optional)",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1,
      "position": [
        250,
        1000
      ],
      "disabled": true,
      "notes": "Enable this to run batch automatically once per day.\nCurrently disabled \u2014 use webhook trigger instead."
    }
  ],
  "connections": {
    "Webhook: Pipeline A Trigger": {
      "main": [
        [
          {
            "node": "Execute: Pipeline A",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook: Pipeline B Trigger": {
      "main": [
        [
          {
            "node": "Execute: Pipeline B",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook: Batch Runner Trigger": {
      "main": [
        [
          {
            "node": "Execute: Batch Runner",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Execute: Pipeline A": {
      "main": [
        [
          {
            "node": "Parse Pipeline A Result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Execute: Pipeline B": {
      "main": [
        [
          {
            "node": "Parse Pipeline B Result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Execute: Batch Runner": {
      "main": [
        [
          {
            "node": "Parse Batch Result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Pipeline A Result": {
      "main": [
        [
          {
            "node": "Respond: Pipeline A",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Pipeline B Result": {
      "main": [
        [
          {
            "node": "Respond: Pipeline B",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Batch Result": {
      "main": [
        [
          {
            "node": "Respond: Batch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule: Daily Batch (Optional)": {
      "main": [
        [
          {
            "node": "Execute: Batch Runner",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "errorWorkflow": "",
    "saveManualExecutions": true,
    "callerPolicy": "workflowsFromSameOwner"
  },
  "tags": [
    "clara-answers",
    "voice-agent",
    "retell",
    "automation"
  ],
  "meta": {
    "description": "Clara Answers: Demo Call \u2192 v1 Agent | Onboarding \u2192 v2 Agent | Batch processing for all 10 accounts"
  }
}