{
  "name": "Autonomous Agent - Document Processing - Approval and Continuation",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "autonomous-agent/document-processing/executions/approval",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "b854ae0a-6cd3-493f-a242-21b001921ea4",
      "name": "Approval Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        120,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "const body = $json.body ?? $json;\nfor (const field of ['execution_id','approval_id','decision','decided_by']) {\n  if (!body[field]) throw new Error(`Missing required field: ${field}`);\n}\nconst decision = String(body.decision).toLowerCase();\nif (!['approved','rejected'].includes(decision)) throw new Error('decision must be approved or rejected');\nreturn [{json:{\n  execution_id:String(body.execution_id), approval_id:String(body.approval_id), decision,\n  decided_by:String(body.decided_by), comment: body.comment == null ? '' : String(body.comment)\n}}];"
      },
      "id": "8583fff6-4bfc-4ff5-9a1b-9bfcb8a55ae4",
      "name": "Validate Approval Decision",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        350,
        300
      ]
    },
    {
      "parameters": {
        "operation": "decide",
        "executionId": "={{$json.execution_id}}",
        "approvalId": "={{$json.approval_id}}",
        "decision": "={{$json.decision}}",
        "decidedBy": "={{$json.decided_by}}",
        "commentMode": "text",
        "comment": "={{$json.comment}}"
      },
      "id": "98f4108c-eb1f-4cd9-9255-679d168488d2",
      "name": "Decide Approval",
      "type": "n8n-nodes-autonomous-agent.autonomousAgentApproval",
      "typeVersion": 1,
      "position": [
        590,
        300
      ],
      "credentials": {
        "autonomousAgentApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "get",
        "executionId": "={{$('Validate Approval Decision').item.json.execution_id}}"
      },
      "id": "038c49d5-ca56-4021-a23c-d5577a336f2d",
      "name": "Get Updated Execution",
      "type": "n8n-nodes-autonomous-agent.autonomousAgentExecution",
      "typeVersion": 1,
      "position": [
        830,
        300
      ],
      "credentials": {
        "autonomousAgentApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "list",
        "executionId": "={{$('Validate Approval Decision').item.json.execution_id}}",
        "splitIntoItems": false
      },
      "id": "90e93b96-9c2a-43d2-85ef-ca83ea31ad9d",
      "name": "List Result Artifacts",
      "type": "n8n-nodes-autonomous-agent.autonomousAgentArtifact",
      "typeVersion": 1,
      "position": [
        1060,
        220
      ],
      "credentials": {
        "autonomousAgentApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "list",
        "executionId": "={{$('Validate Approval Decision').item.json.execution_id}}",
        "splitIntoItems": false
      },
      "id": "fcb9a31d-7efe-4d9f-93ce-5ced3695ef56",
      "name": "List Post-Decision Events",
      "type": "n8n-nodes-autonomous-agent.autonomousAgentEvent",
      "typeVersion": 1,
      "position": [
        1060,
        380
      ],
      "credentials": {
        "autonomousAgentApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "mode": "combine",
        "combineBy": "position",
        "options": {}
      },
      "id": "aed44b14-c0f0-44c5-99b5-1f5962e2e15c",
      "name": "Merge Result Data",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3,
      "position": [
        1280,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "const execution = $('Get Updated Execution').item.json;\nconst artifactsNode = $('List Result Artifacts').item.json;\nconst eventsNode = $('List Post-Decision Events').item.json;\nreturn [{json:{\n  execution_id: execution.execution_id,\n  status: execution.status,\n  current_step: execution.current_step ?? null,\n  decision: $('Validate Approval Decision').item.json.decision,\n  output: execution.output ?? execution.result ?? null,\n  artifacts: artifactsNode.artifacts ?? artifactsNode.items ?? artifactsNode.data ?? artifactsNode,\n  events: eventsNode.events ?? eventsNode.items ?? eventsNode.data ?? eventsNode\n}}];\n// Domain: document-processing"
      },
      "id": "47e5d2b9-76c4-4d01-9526-8f8b23340218",
      "name": "Build Approval Response",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1500,
        300
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{$json}}",
        "options": {
          "responseCode": 200
        }
      },
      "id": "57ac78f6-28a9-4654-8954-33475dfc7cc3",
      "name": "Respond to Approval",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.4,
      "position": [
        1720,
        300
      ]
    }
  ],
  "connections": {
    "Approval Webhook": {
      "main": [
        [
          {
            "node": "Validate Approval Decision",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate Approval Decision": {
      "main": [
        [
          {
            "node": "Decide Approval",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Decide Approval": {
      "main": [
        [
          {
            "node": "Get Updated Execution",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Updated Execution": {
      "main": [
        [
          {
            "node": "List Result Artifacts",
            "type": "main",
            "index": 0
          },
          {
            "node": "List Post-Decision Events",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "List Result Artifacts": {
      "main": [
        [
          {
            "node": "Merge Result Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "List Post-Decision Events": {
      "main": [
        [
          {
            "node": "Merge Result Data",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Merge Result Data": {
      "main": [
        [
          {
            "node": "Build Approval Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Approval Response": {
      "main": [
        [
          {
            "node": "Respond to Approval",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "saveManualExecutions": true,
    "saveExecutionProgress": true
  },
  "versionId": "e9a7fd97-6379-49ba-9e34-380df310dd55",
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": []
}