{
  "name": "Agent, production version",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "agent",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "1b969981-1157-495f-b121-ed1cd8ce70a6",
      "name": "Request in",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        300
      ],
      "webhookId": "45426f45-eaf0-4eb9-80fd-7e309da582ee"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "201b976c-fee9-4fb7-a154-bb6ae7107313",
              "leftValue": "={{ $json.body.text }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "24bfd33a-717b-4c15-9ef8-9e238f7e12f4",
      "name": "Valid input?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        220,
        300
      ]
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.body.text }}",
        "hasOutputParser": true,
        "options": {
          "maxIterations": 5
        }
      },
      "id": "3c879cd2-1305-4f09-abfc-2768d62ece8f",
      "name": "Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.7,
      "position": [
        460,
        220
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 2000,
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4.1-mini",
          "mode": "list",
          "cachedResultName": "gpt-4.1-mini"
        },
        "options": {
          "maxTokens": 800,
          "timeout": 30000
        }
      },
      "id": "f90b941c-b2e3-4316-9dab-f07575714f0f",
      "name": "Chat model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        380,
        460
      ]
    },
    {
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"action\": { \"type\": \"string\" },\n    \"payload\": { \"type\": \"object\" },\n    \"needs_review\": { \"type\": \"boolean\" }\n  },\n  \"required\": [\"action\", \"needs_review\"]\n}"
      },
      "id": "e05a6727-ad10-4387-ab91-91fbac4893fb",
      "name": "Output schema",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.2,
      "position": [
        540,
        460
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "a5dd3769-3923-4850-945c-34128c07a047",
              "leftValue": "={{ $json.output.needs_review }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "d083083b-691e-41f1-b2c7-ea4f46edefda",
      "name": "Needs review?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        760,
        160
      ]
    },
    {
      "parameters": {
        "operation": "sendAndWait",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "value": "#agent-review",
          "mode": "name"
        },
        "message": "={{ JSON.stringify($json.output) }}",
        "approvalOptions": {
          "values": {
            "approvalType": "double"
          }
        },
        "options": {}
      },
      "id": "18a92051-e388-4352-91aa-33db1756ed1b",
      "name": "Human approval",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.3,
      "position": [
        1000,
        60
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.example.com/actions",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify($('Agent').item.json.output.payload) }}",
        "options": {
          "timeout": 15000
        }
      },
      "id": "c2c2eba5-3ace-4b9b-8de5-4c0d7bf025db",
      "name": "Do the action",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1240,
        180
      ],
      "retryOnFail": true,
      "maxTries": 3
    },
    {
      "parameters": {
        "schema": {
          "__rl": true,
          "value": "public",
          "mode": "list"
        },
        "table": {
          "__rl": true,
          "value": "agent_runs",
          "mode": "list"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {}
        },
        "options": {}
      },
      "id": "7ed83ed8-8711-4ece-9f49-e3dc8b77c169",
      "name": "Log run",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        1480,
        180
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={ \"status\": \"done\" }",
        "options": {}
      },
      "id": "398b6fe0-6042-4c60-9b34-99ed4f23f3ae",
      "name": "Respond OK",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        1720,
        180
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={ \"status\": \"queued_for_human\" }",
        "options": {
          "responseCode": 202
        }
      },
      "id": "12b5b3a5-9eb0-4c79-8028-bdef3b12fb24",
      "name": "Fallback reply",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        760,
        420
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={ \"error\": \"text is required\" }",
        "options": {
          "responseCode": 400
        }
      },
      "id": "bd148235-2070-4fa2-8631-2d649e22c0b6",
      "name": "Reject bad input",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        460,
        620
      ]
    }
  ],
  "connections": {
    "Request in": {
      "main": [
        [
          {
            "node": "Valid input?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Valid input?": {
      "main": [
        [
          {
            "node": "Agent",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Reject bad input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Chat model": {
      "ai_languageModel": [
        [
          {
            "node": "Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Output schema": {
      "ai_outputParser": [
        [
          {
            "node": "Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Agent": {
      "main": [
        [
          {
            "node": "Needs review?",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Fallback reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Needs review?": {
      "main": [
        [
          {
            "node": "Human approval",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Do the action",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Human approval": {
      "main": [
        [
          {
            "node": "Do the action",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Do the action": {
      "main": [
        [
          {
            "node": "Log run",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log run": {
      "main": [
        [
          {
            "node": "Respond OK",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {}
}