工作流json,复制下方的json代码,打开n8n,创建一个新的工作流。粘贴进去即可。 记得把http request地址改成你自己的数据接口。
2026 自动化新高度:让你的 n8n 流程拥有“自我进化”能力,像数字员工一样思考!
{
"nodes": [
{
"parameters": {
"promptType": "define",
"text": "=## Role\n你是一个专为 n8n 开发的自愈代理 (Self-Healing Agent)。\n\n## Context\n报错信息:{{ $json.error }}\n\n## Source Data (Array)\n这是主流程获取到的原始数组数据:\n{{ JSON.stringify($(\"GetList\").all().map(item => item.json)) }}\n\n## Task\n1. 原始数据是一个对象数组。请检查数组中每一项是否缺少 'title' 字段。\n2. 如果字段名不匹配(例如原始数据用的是 'heading' 或 'name'),请将其统一映射为 'title'。\n3. 请修复整个数组,确保输出的每一项都包含 'title'、'description' 和 'link'。\n4. 'title'、'description' 和 'link'如果是映射修复的,则统一在对应值后边追加【AI修复】字样。\n\n## Constraints\n- 必须返回如下格式的纯 JSON,不要包含任何 Markdown 代码块:\n{\n \"action\": \"retry\",\n \"fixed_payload\": [\n {\n \"title\": \"修复后的标题1\",\n \"description\": \"描述1\",\n \"link\": \"链接1\"\n },\n ...\n ],\n \"diagnosis\": \"简短说明为什么报错(例如:API返回的字段名是 heading 而不是 title)\"\n}",
"options": {}
},
"type": "@n8n/n8n-nodes-langchain.agent",
"typeVersion": 3.1,
"position": [
-976,
-496
],
"id": "734eeb75-0b59-4262-9a9a-fe028f2018e3",
"name": "AI Agent",
"retryOnFail": true,
"onError": "continueErrorOutput"
},
{
"parameters": {
"options": {}
},
"type": "@n8n/n8n-nodes-langchain.lmChatDeepSeek",
"typeVersion": 1,
"position": [
-976,
-320
],
"id": "2f27548a-9b59-4472-9faa-eef92fec692d",
"name": "DeepSeek Chat Model",
"credentials": {
"deepSeekApi": {
"id": "cANiQxozklHiXRQv",
"name": "DeepSeek account"
}
}
},
{
"parameters": {
"url": "https://www.xxxx.com/demoer.json",
"options": {}
},
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.3,
"position": [
-1488,
-912
],
"id": "745b25cb-c5bc-480b-beb1-5a388ad72ba2",
"name": "GetList"
},
{
"parameters": {
"jsCode": "// 获取所有输入数据\nconst items = $input.all();\n\n// 定义 HTML 头部样式\nlet htmlContent = `\n<div style=\"font-family: sans-serif; width: 100%; min-height: 100vh;background-color:#000;padding:0\">\n <h2 style=\"color: #ccc;text-align:center\">AI 自动生成的文档列表</h2>\n <hr>\n`;\n\n// 循环处理每一条 JSON 数据\nfor (const item of items) {\n const data = item.json;\n if (!data.title) {\n // 抛出错误,触发 Error Workflow\n throw new Error(`字段 title 缺失`);\n }\n // 处理标题字段\n const title = data.title;\n \n // 处理描述字段\n const description = data.description;\n \n // 处理链接\n const link = data.link || \"#\";\n\n // 拼接 HTML 片段\n htmlContent += `\n <div style=\"margin-bottom: 20px; border-bottom: 1px dashed #ccc; padding-bottom: 10px;\">\n <a href=\"${link}\" style=\"font-size: 18px; color: #007bff; text-decoration: none; font-weight: bold;\">\n ${title}\n </a>\n <p style=\"color: #ccc; font-size: 14px; margin-top: 5px;\">\n ${description}\n </p>\n </div>\n `;\n}\n\nhtmlContent += `</div>`;\n\n// 输出结果\nreturn { html: htmlContent };"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
-1264,
-912
],
"id": "51c8b70f-9f05-4530-98e5-37573788fb88",
"name": "MakeData",
"onError": "continueErrorOutput"
},
{
"parameters": {
"jsCode": "// 获取所有输入数据\nconst rawString = JSON.parse($input.first().json.output);\n\nconst items = rawString.fixed_payload;\n// 定义 HTML 头部样式\nlet htmlContent = `\n<div style=\"font-family: sans-serif; width: 100%; min-height: 100vh;background-color:#000;margin:0\">\n <h2 style=\"color: #ccc;text-align:center\">AI 自动生成的文档列表</h2>\n <hr>\n`;\n\n// 循环处理每一条 JSON 数据\nfor (const item of items) {\n const data = item;\n if (!data.title) {\n data.title='AI 无法修复!'\n }\n // 处理标题字段\n const title = data.title;\n \n // 处理描述字段\n const description = data.description;\n \n // 处理链接\n const link = data.link || \"#\";\n\n // 拼接 HTML 片段\n htmlContent += `\n<div style=\"font-family: sans-serif; max-width: 600px; margin: auto;\">\n <a href=\"${link}\" style=\"font-size: 18px; color: #007bff; text-decoration: none; font-weight: bold;\">\n ${title}\n </a>\n <p style=\"color: #ccc; font-size: 14px; margin-top: 5px;\">\n ${description}\n </p>\n </div>\n `;\n}\n\nhtmlContent += `</div>`;\n\n// 输出结果\nreturn { html: htmlContent };"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
-656,
-512
],
"id": "5188e68c-f7a3-4fd7-bd65-a4260ef4fe26",
"name": "fMakeData"
},
{
"parameters": {
"respondWith": "text",
"responseBody": "={{ $json.html }}",
"options": {
"responseHeaders": {
"entries": [
{
"name": "Content-Type",
"value": "text/html; charset=utf-8"
}
]
}
}
},
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1.5,
"position": [
-368,
-928
],
"id": "24110294-5fb7-43bb-a88b-00c37ee9fc6b",
"name": "返回网页HTML"
},
{
"parameters": {
"content": "## 触发邮件警告并尝试自动修复",
"height": 512,
"width": 544
},
"type": "n8n-nodes-base.stickyNote",
"position": [
-1008,
-688
],
"typeVersion": 1,
"id": "e86e2644-468f-40a2-9607-2de5eb2bdead",
"name": "Sticky Note"
},
{
"parameters": {
"content": "## 主工作流\n**文章列表** 获取文章列表显示一个静态的web页面",
"height": 240,
"width": 1584,
"color": 4
},
"type": "n8n-nodes-base.stickyNote",
"position": [
-1744,
-992
],
"typeVersion": 1,
"id": "61a621ce-d8a8-48fe-a70b-a05a4f99d686",
"name": "Sticky Note1"
},
{
"parameters": {
"path": "autodebug",
"responseMode": "responseNode",
"options": {}
},
"type": "n8n-nodes-base.webhook",
"typeVersion": 2.1,
"position": [
-1712,
-704
],
"id": "34609bf0-d70a-4bd2-a6c0-c160d149c78b",
"name": "Webhook",
"webhookId": "a2851492-fbcd-4f54-9c13-ed7fa515cc50"
},
{
"parameters": {},
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [
-1712,
-912
],
"id": "59ef6fdb-2414-4468-bac5-a38354d9360b",
"name": "手工触发器"
},
{
"parameters": {
"fromEmail": "zhandi1952@163.com",
"toEmail": "zhandi1949@gmail.com",
"subject": "n8n智能体数据修复异常",
"html": "=工作流 {{ $workflow.name }} 智能体数据修复异常 请立即检查",
"options": {}
},
"type": "n8n-nodes-base.emailSend",
"typeVersion": 2.1,
"position": [
-656,
-368
],
"id": "b72242fc-b7a9-4624-9884-a2eb752ee4e8",
"name": "Send email1",
"webhookId": "97df2403-1274-45d5-8bd1-689c262b06a8",
"credentials": {
"smtp": {
"id": "MLWBqjaYEgvZI5s4",
"name": "163SMTP"
}
}
},
{
"parameters": {
"fromEmail": "zhandi1952@163.com",
"toEmail": "zhandi1949@gmail.com",
"subject": "【警告】数据接口异常,请立即检查",
"emailFormat": "text",
"text": "=来自n8n工作流: {{ $workflow.name }} 的告警信息。{{ $json.error }}",
"options": {}
},
"type": "n8n-nodes-base.emailSend",
"typeVersion": 2.1,
"position": [
-976,
-640
],
"id": "87dc96f7-1420-43f7-bfb8-ce59fc2e69ce",
"name": "Send email",
"webhookId": "b93abfaa-677e-449d-83fc-e4a8a2115f6d",
"credentials": {
"smtp": {
"id": "MLWBqjaYEgvZI5s4",
"name": "163SMTP"
}
}
}
],
"connections": {
"AI Agent": {
"main": [
[
{
"node": "fMakeData",
"type": "main",
"index": 0
}
],
[
{
"node": "Send email1",
"type": "main",
"index": 0
}
]
]
},
"DeepSeek Chat Model": {
"ai_languageModel": [
[
{
"node": "AI Agent",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"GetList": {
"main": [
[
{
"node": "MakeData",
"type": "main",
"index": 0
}
]
]
},
"MakeData": {
"main": [
[
{
"node": "返回网页HTML",
"type": "main",
"index": 0
}
],
[
{
"node": "Send email",
"type": "main",
"index": 0
},
{
"node": "AI Agent",
"type": "main",
"index": 0
}
]
]
},
"fMakeData": {
"main": [
[
{
"node": "返回网页HTML",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "GetList",
"type": "main",
"index": 0
}
]
]
},
"手工触发器": {
"main": [
[
{
"node": "GetList",
"type": "main",
"index": 0
}
]
]
}
},
"pinData": {},
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "4ec247777f7c8d8b1d025ed6d25b14832a6d542722506bcf7675e4b5b5efdee6"
}
}
示例json数据
//正常数据
[
{
"title": "n8n 错误自愈工作流:设计理念",
"description": "介绍如何通过 Error Trigger 和 AI Agent 构建具备自愈能力的自动化系统。",
"link": "https://example.com/n8n-self-healing-design"
},
{
"title": "为什么传统自动化总是半夜报警?",
"description": "分析自动化流程在字段变更、接口升级时常见的失败模式,以及如何提前设计容错机制。",
"link": "https://example.com/automation-failure-patterns"
},
{
"title": "AI Agent 在 n8n 中的正确使用方式",
"description": "讲解如何给 AI 明确角色、边界和输出格式,让它真正成为工作流里的工程师。",
"link": "https://example.com/n8n-ai-agent-best-practice"
},
{
"title": "Error Trigger 深度解析",
"description": "从工程角度讲清楚 Error Trigger 的触发机制、局限性以及设计误区。",
"link": "https://example.com/n8n-error-trigger-deep-dive"
}
]
//错误数据
[
{
"title": "n8n 错误自愈工作流:设计理念",
"description": "介绍如何通过 Error Trigger 和 AI Agent 构建具备自愈能力的自动化系统。",
"link": "https://example.com/n8n-self-healing-design"
},
{
"title": "为什么传统自动化总是半夜报警?",
"desc": "字段名被改成了 desc,用来模拟真实世界的数据变更。",
"link": "https://example.com/automation-failure-patterns"
},
{
"heading": "AI Agent 在 n8n 中的正确使用方式",
"description": "title 字段被改成 heading,用于触发解析错误。",
"link": "https://example.com/n8n-ai-agent-best-practice"
},
{
"title": "Error Trigger 深度解析",
"description": "这条数据是正常的,用于对比演示。",
"link": "https://example.com/n8n-error-trigger-deep-dive"
}
]