This workflow corresponds to n8n.io template #13791 — we link there as the canonical source.
This workflow follows the Agent → Error Trigger recipe pattern — see all workflows that pair these two integrations.
The workflow JSON
Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →
{
"id": "boirfDk13BMD1axn",
"meta": {
"templateCredsSetupCompleted": true
},
"name": "AI Self-Healing Engine & Auto-Patching System",
"tags": [],
"nodes": [
{
"id": "793dfa7b-0834-4390-9928-fa0c49fae284",
"name": "Azure OpenAI Chat Model1",
"type": "@n8n/n8n-nodes-langchain.lmChatAzureOpenAi",
"position": [
-368,
1472
],
"parameters": {
"model": "gpt-4o",
"options": {}
},
"credentials": {
"azureOpenAiApi": {
"name": "<your credential>"
}
},
"typeVersion": 1
},
{
"id": "7b31c623-aa39-440a-b6af-3415be6be14d",
"name": "On Workflow Error",
"type": "n8n-nodes-base.errorTrigger",
"position": [
-992,
1248
],
"parameters": {},
"typeVersion": 1
},
{
"id": "7b79e4ff-71bb-4564-83eb-839efb915f3c",
"name": "Filter: Ignore Self",
"type": "n8n-nodes-base.filter",
"position": [
-752,
1248
],
"parameters": {
"conditions": {
"string": [
{
"value1": "={{ $json.workflow.id }}",
"value2": "={{ $workflow.id }}",
"operation": "notEqual"
}
]
}
},
"typeVersion": 1
},
{
"id": "fd852042-fee2-4fcc-aebe-a9b28976b15d",
"name": "Get Workflow JSON",
"type": "n8n-nodes-base.httpRequest",
"position": [
-528,
1248
],
"parameters": {
"url": "=https://n8n.tdwebsites.in/api/v1/workflows/{{$json.workflow.id}}",
"options": {},
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "X-N8N-API-KEY",
"value": "your_api_key"
},
{
"name": "Accept",
"value": "application/json"
}
]
}
},
"typeVersion": 4.1
},
{
"id": "51495c09-3b5e-4558-b592-27e5b422683d",
"name": "Diagnose Error",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
-304,
1248
],
"parameters": {
"text": "=\"You are an n8n Senior Engineer.\n\nCONTEXT:\n\nFailed Node: {{ $node[\"On Workflow Error\"].json.workflow.name }}\n\nError: {{ $node[\"On Workflow Error\"].json.execution.error.message }}\n\nWorkflow JSON: {{ JSON.stringify($node[\"Get Workflow JSON\"].json) }}\n\nTASK:\n\nDecide if this is a 'RETRY' (network/timeout) or a 'FIX' (logic/wrong param).\n\nIf 'FIX', identify the specific parameter name in the failed node that caused the error.\n\nProvide the corrected value for that parameter.\n\nReturn the result in the structured format.\"",
"options": {},
"promptType": "define",
"hasOutputParser": true
},
"typeVersion": 2
},
{
"id": "09a3eac9-e134-4b98-95f3-afb086371ede",
"name": "Decision Schema",
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"position": [
-160,
1456
],
"parameters": {
"jsonSchema": "{\n \"type\": \"object\",\n \"properties\": {\n \"state\": { \"type\": \"string\", \"enum\": [\"RETRY\", \"FIX\"] },\n \"diagnosis\": { \"type\": \"string\" },\n \"patch\": {\n \"type\": \"object\",\n \"properties\": {\n \"parameterName\": { \"type\": \"string\" },\n \"newValue\": { \"type\": \"string\" }\n }\n }\n }\n}"
},
"typeVersion": 1.1
},
{
"id": "906b3411-7672-480b-a17e-0b2d3842e5ea",
"name": "Determine Action",
"type": "n8n-nodes-base.switch",
"position": [
80,
1232
],
"parameters": {
"rules": {
"values": [
{
"conditions": {
"options": {
"version": 3,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "62c120fd-2211-45aa-885d-ba90ddadabbd",
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.output.state }}",
"rightValue": "RETRY"
}
]
}
},
{
"conditions": {
"options": {
"version": 3,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "f012633d-d102-4286-a595-6699bb09ee8b",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.output.state }}",
"rightValue": "FIX"
}
]
}
},
{
"conditions": {
"options": {
"version": 3,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "3d411619-4d35-41af-980c-c36c15de839a",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "",
"rightValue": ""
}
]
}
}
]
},
"options": {}
},
"typeVersion": 3.4
},
{
"id": "5cb32bf9-95ab-41ed-9cc4-8a1c86d1ea96",
"name": "Cool Down",
"type": "n8n-nodes-base.wait",
"position": [
320,
1216
],
"parameters": {
"unit": "minutes"
},
"typeVersion": 1.1
},
{
"id": "5e74b4be-630d-4df0-b700-8ddfaea758d8",
"name": "Generate Patch JSON",
"type": "n8n-nodes-base.code",
"position": [
976,
1392
],
"parameters": {
"jsCode": "// 1. Get the data from previous nodes using to avoid undefined errors\nconst workflowData = $node[\"Get Workflow JSON\"].json;\nconst aiResponse = $node[\"Diagnose Error\"].json.output;\nconst errorData = $node[\"On Workflow Error\"].json;\n\n// 2. Clone the workflow to avoid mutating original data unexpectedly\nlet updatedWorkflow = JSON.parse(JSON.stringify(workflowData));\n\n// 3. Safety Check: Ensure the AI actually provided a patch\nif (aiResponse && aiResponse.patch && aiResponse.patch.parameterName) {\n const targetNodeName = errorData.execution.lastNodeExecuted;\n const paramToFix = aiResponse.patch.parameterName;\n const newValue = aiResponse.patch.newValue;\n\n // 4. Loop through nodes and apply the fix\n let found = false;\n for (let node of updatedWorkflow.nodes) {\n if (node.name === targetNodeName) {\n // Initialize parameters if for some reason they don't exist\n node.parameters = node.parameters || {};\n node.parameters[paramToFix] = newValue;\n \n // Add a note so you can see the fix in the UI\n node.notes = `\ud83d\udee0 AI AUTO-FIX: Changed ${paramToFix} to ${newValue}`;\n found = true;\n break;\n }\n }\n}\n\n// 5. Return the result in the standard n8n format\nreturn {\n json: {\n workflowJSON: updatedWorkflow, // This will be used in the PUT body\n diagnosis: aiResponse.diagnosis,\n fixedParam: aiResponse.patch ? aiResponse.patch.parameterName : 'none',\n success: true\n }\n};"
},
"typeVersion": 2
},
{
"id": "95c7ba49-dbd9-43c3-aa7f-33b9c55ff011",
"name": "Retry Execution",
"type": "n8n-nodes-base.httpRequest",
"position": [
544,
1216
],
"parameters": {
"url": "=https://n8n.tdwebsites.in/api/v1/executions/{{$node[\"On Workflow Error\"].json.execution.id}}/retry",
"method": "POST",
"options": {},
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "X-N8N-API-KEY",
"value": "your_api_key"
},
{
"name": "Accept",
"value": "application/json"
}
]
}
},
"typeVersion": 4.1
},
{
"id": "9367f82e-8469-4970-8af4-53a8c87e42c7",
"name": "Update Workflow",
"type": "n8n-nodes-base.httpRequest",
"position": [
1200,
1392
],
"parameters": {
"url": "=https://n8n.tdwebsites.in/api/v1/workflows/{{ $node[\"On Workflow Error\"].json.workflow.id}}",
"method": "PUT",
"options": {},
"jsonBody": "={\n \"name\": \"{{ $json.workflowJSON.name }}\",\n \"nodes\": {{ JSON.stringify($json.workflowJSON.nodes) }},\n \"connections\": {{ JSON.stringify($json.workflowJSON.connections) }},\n \"settings\": {{ JSON.stringify($json.workflowJSON.settings || {}) }},\n \"staticData\": {{ JSON.stringify($json.workflowJSON.staticData || null) }}\n}",
"sendBody": true,
"sendHeaders": true,
"specifyBody": "json",
"headerParameters": {
"parameters": [
{
"name": "X-N8N-API-KEY",
"value": "your_api_key"
},
{
"name": "Accept",
"value": "application/json"
}
]
}
},
"typeVersion": 4.1
},
{
"id": "6eab371c-f9de-4ef8-8f90-efa4c2151592",
"name": "Notify Success",
"type": "n8n-nodes-base.slack",
"position": [
1440,
1392
],
"parameters": {
"text": "=\u2705 I successfully patched the workflow! Diagnosis: {{ $node[\"Generate Patch JSON\"].json.diagnosis }}",
"select": "channel",
"channelId": {
"__rl": true,
"mode": "list",
"value": "C09L70CVDL3",
"cachedResultName": "alerting-channel"
},
"otherOptions": {},
"authentication": "oAuth2"
},
"credentials": {
"slackOAuth2Api": {
"name": "<your credential>"
}
},
"typeVersion": 2.1
},
{
"id": "2a6ccfb9-e39e-4cf0-9c54-6ad6542fcf27",
"name": "Notify Manual Fix",
"type": "n8n-nodes-base.slack",
"position": [
336,
1472
],
"parameters": {
"text": "=\u26a0\ufe0f Manual Action Required\nWorkflow: {{ $node[\"On Workflow Error\"].json.workflow.name }}\nFailed Node: {{ $node[\"On Workflow Error\"].json.execution.lastNodeExecuted }}\nAI Diagnosis: {{ $node[\"Diagnose Error\"].json.output.diagnosis }}\nLink: https://n8n.tdwebsites.in/workflow/{{ $node[\"On Workflow Error\"].json.workflow.id}}/execution/{{ $node[\"On Workflow Error\"].json.execution.id }})",
"select": "channel",
"channelId": {
"__rl": true,
"mode": "list",
"value": "C09L70CVDL3",
"cachedResultName": "alerting-channel"
},
"otherOptions": {},
"authentication": "oAuth2"
},
"credentials": {
"slackOAuth2Api": {
"name": "<your credential>"
}
},
"typeVersion": 2.1
},
{
"id": "b93bd359-1f04-463e-94b2-23cd4afa8e2d",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1072,
1104
],
"parameters": {
"color": 7,
"width": 1040,
"height": 528,
"content": "The error trigger responds with failure in any workflow, then AI analyzes the failure context against the workflow's structure. It determines if the error is a temporary timeout (Retry) or a logic error requiring a parameter change (Fix)"
},
"typeVersion": 1
},
{
"id": "51ca98b8-4cca-4421-a411-50f95bfe0d5a",
"name": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"position": [
16,
1072
],
"parameters": {
"color": 7,
"width": 752,
"height": 336,
"content": "The Switch node directs traffic based on the AI's verdict. If a retry is needed, the Wait node pauses execution to allow the external service time to recover. And it automatically retries the workflow"
},
"typeVersion": 1
},
{
"id": "507f3d24-1b03-42e6-9eae-4763355a17c2",
"name": "Sticky Note2",
"type": "n8n-nodes-base.stickyNote",
"position": [
896,
1264
],
"parameters": {
"color": 7,
"width": 816,
"height": 336,
"content": "The JavaScript node injects the AI's corrected value into the workflow JSON. The n8n API then updates the workflow live and notifies Slack of the successful repair."
},
"typeVersion": 1
},
{
"id": "453800c4-bf94-40fd-9427-ca8f6110927f",
"name": "Sticky Note3",
"type": "n8n-nodes-base.stickyNote",
"position": [
256,
1424
],
"parameters": {
"color": 7,
"width": 272,
"height": 352,
"content": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nIf the AI cannot determine a fix or the error is marked as \"MANUAL,\" the system skips auto-correction and sends a detailed diagnostic report to Slack for human review."
},
"typeVersion": 1
},
{
"id": "87339878-8d67-407f-a3fa-a4b23731ee51",
"name": "Sticky Note4",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1808,
688
],
"parameters": {
"width": 528,
"height": 496,
"content": "## Workflow Overview\n\n### How it Works:\n\nThis workflow acts as a global error handler for your n8n instance. When a node fails in any connected workflow, the Error Trigger captures the event. It filters out self-loops to prevent recursion. The system then fetches the original workflow\u2019s JSON and passes it to an AI Agent. The AI diagnoses if the failure was a transient network error (RETRY) or a configuration mistake (FIX). Based on this, it either waits and retries the execution or uses a Code Node to dynamically patch the JSON and update the workflow via the n8n API.\n\n### Setup Required:\n\nGlobal Error Workflow: Set this workflow as the \"Error Workflow\" in your other workflows' settings.\n\nn8n API Credentials: Create an API Key in n8n and link it to the HTTP Request nodes.\n\nAzure OpenAI: Configure the Azure Open AI credentials.\n\nSlack: Connect your Slack account and update the Channel IDs to receive real-time repair notifications."
},
"typeVersion": 1
}
],
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "5a9039fb-ccb5-4ba5-a6cb-30b2b40657c0",
"connections": {
"Cool Down": {
"main": [
[
{
"node": "Retry Execution",
"type": "main",
"index": 0
}
]
]
},
"Diagnose Error": {
"main": [
[
{
"node": "Determine Action",
"type": "main",
"index": 0
}
]
]
},
"Decision Schema": {
"ai_outputParser": [
[
{
"node": "Diagnose Error",
"type": "ai_outputParser",
"index": 0
}
]
]
},
"Update Workflow": {
"main": [
[
{
"node": "Notify Success",
"type": "main",
"index": 0
}
]
]
},
"Determine Action": {
"main": [
[
{
"node": "Cool Down",
"type": "main",
"index": 0
}
],
[
{
"node": "Generate Patch JSON",
"type": "main",
"index": 0
}
],
[
{
"node": "Notify Manual Fix",
"type": "main",
"index": 0
}
]
]
},
"Get Workflow JSON": {
"main": [
[
{
"node": "Diagnose Error",
"type": "main",
"index": 0
}
]
]
},
"On Workflow Error": {
"main": [
[
{
"node": "Filter: Ignore Self",
"type": "main",
"index": 0
}
]
]
},
"Filter: Ignore Self": {
"main": [
[
{
"node": "Get Workflow JSON",
"type": "main",
"index": 0
}
]
]
},
"Generate Patch JSON": {
"main": [
[
{
"node": "Update Workflow",
"type": "main",
"index": 0
}
]
]
},
"Azure OpenAI Chat Model1": {
"ai_languageModel": [
[
{
"node": "Diagnose Error",
"type": "ai_languageModel",
"index": 0
}
]
]
}
}
}
Credentials you'll need
Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.
azureOpenAiApislackOAuth2Api
For the full experience including quality scoring and batch install features for each workflow upgrade to Pro
About this workflow
Eliminate manual troubleshooting with an AI-powered autonomous recovery engine for n8n 🤖. This system monitors your entire n8n instance for failures, analyzes the root cause using Azure OpenAI, and automatically repairs broken workflows in real-time. By distinguishing between…
Source: https://n8n.io/workflows/13791/ — original creator credit. Request a take-down →
Related workflows
Workflows that share integrations, category, or trigger type with this one. All free to copy and import.
This workflow is an AI-powered virtual cinematography and previs generation pipeline designed for film and VFX production. It transforms a director’s shot description into multiple camera choreography
Automate your entire content-to-audio workflow by converting new blog articles into fully produced podcast episodes using AI scriptwriting and ElevenLabs narration. 🎙🤖 This automation monitors an RSS
Agent Nodes. Uses lmChatOpenAi, slack, stopAndError, errorTrigger. Event-driven trigger; 72 nodes.
Who is this for? Agencies, consultants, and service providers who conduct discovery calls and need to quickly turn conversations into professional proposals.
My workflow 30. Uses lmChatOpenAi, httpRequest, agent, lmChatOllama. Event-driven trigger; 52 nodes.