递归多代理模板
中级
这是一个AI, Marketing领域的自动化工作流,包含 11 个节点。主要使用 If, Set, Code, Agent, ChatTrigger 等节点,结合人工智能技术实现智能自动化。 使用GPT-4o递归写作和编辑代理生成书面内容
前置要求
- •OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"id": "UnFtEvTPouN6XIIH",
"meta": {
"instanceId": "ea11c547d31842d8c1ffb2f9490761ea576cf90dbdb1ce86a951bf99131d1a44",
"templateCredsSetupCompleted": true
},
"name": "递归多代理模板",
"tags": [],
"nodes": [
{
"id": "84b115d5-0c47-4bc9-8997-e45c16e3aa18",
"name": "当收到聊天消息时",
"type": "@n8n/n8n-nodes-langchain.chatTrigger",
"position": [
40,
0
],
"webhookId": "037b5b5d-7a59-4812-8327-42f9c7812d5d",
"parameters": {
"options": {}
},
"typeVersion": 1.1
},
{
"id": "085fd153-5564-4920-b278-e5fc93f32134",
"name": "窗口缓冲记忆",
"type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
"position": [
920,
280
],
"parameters": {
"sessionKey": "={{ $('When chat message received').item.json.sessionId }}",
"sessionIdType": "customKey",
"contextWindowLength": 10
},
"typeVersion": 1.3
},
{
"id": "0220fe2a-8e8e-4d11-803e-b942f1cf16c5",
"name": "设置变量",
"type": "n8n-nodes-base.set",
"position": [
1380,
0
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "25fcda79-c515-4e2e-bfc0-3b13259c33a0",
"name": "status",
"type": "string",
"value": "={{ $json.output.status }}"
},
{
"id": "26f212df-ed09-4372-ad2f-e069698ab33c",
"name": "edits",
"type": "string",
"value": "={{ $json.output.edits }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "0dc0e194-4129-42e3-aedd-6fbd6b875338",
"name": "聊天输入",
"type": "n8n-nodes-base.set",
"position": [
260,
0
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "709fb115-0654-48f6-bbdd-d0661b1135ba",
"name": "chatInput",
"type": "string",
"value": "={{ $json.chatInput }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "426831d6-2ddb-4ede-99a7-c0c504e6687f",
"name": "结构化输出解析器",
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"position": [
1200,
280
],
"parameters": {
"schemaType": "manual",
"inputSchema": "{\n\t\"type\": \"object\",\n\t\"properties\": {\n\t\t\"status\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\"edits\": {\n\t\t\t\"type\": \"string\"\n\t\t}\n\t}\n}"
},
"typeVersion": 1.2
},
{
"id": "4be8a98c-c01f-4e8c-bec7-c6ef4119c392",
"name": "OpenAI 聊天模型",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
680,
280
],
"parameters": {
"model": "gpt-4o",
"options": {}
},
"credentials": {
"openAiApi": {
"id": "93qOKf12nDGJSW30",
"name": "OpenAi account"
}
},
"typeVersion": 1.1
},
{
"id": "b22dd35c-5df2-4966-a7b6-4b146c5d9a09",
"name": "处理编辑",
"type": "n8n-nodes-base.code",
"position": [
460,
0
],
"parameters": {
"jsCode": "let edits = \"\";\ntry {\n\t// Try to retrieve the edits from the node named \"Edit Fields\"\n\tedits = $node[\"set variables\"].json[\"edits\"] || \"\";\n} catch (err) {\n\t// If the node hasn't executed or its data isn't available, default to empty string\n\tedits = \"\";\n}\nreturn { edits };"
},
"typeVersion": 2
},
{
"id": "85524870-798a-4561-a227-06c8f0aa3c26",
"name": "如果状态完成",
"type": "n8n-nodes-base.if",
"position": [
1600,
0
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "d2c4ff3a-1674-4edf-b0a0-153543f52900",
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $('Editing Agent').item.json.output.status }}",
"rightValue": "complete"
}
]
}
},
"typeVersion": 2.2
},
{
"id": "e28c4317-1e16-445f-8119-7d53937b651b",
"name": "写作代理",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
660,
0
],
"parameters": {
"text": "=Always review chat history.\n\nWrite a blurb based on my input topic:\n{{ $('chatInput').item.json.chatInput }}\n\nIf there are any suggested edits, make sure to incorporated them into the blurb:\n{{ $json.edits }}\n\nONLY OUTPUT THE BLURB, NO ADDITIONAL WORDS. ",
"options": {
"systemMessage": "=You are a writer. Write a short blurb about the topic given to you by the user. "
},
"promptType": "define"
},
"typeVersion": 1.7
},
{
"id": "fe9d9f32-8be3-49a7-8699-322192e16474",
"name": "编辑代理",
"type": "@n8n/n8n-nodes-langchain.agent",
"maxTries": 5,
"position": [
1020,
0
],
"parameters": {
"text": "=You are an editor. \n\nReview the input and recommend specific edits to improve the writing. \n\nYou are working with a writing agent that should implement your edits. \n\nHere are the variables that you output and what they mean:\n- status: this is either \"complete\" or \"incomplete\" output string. Once the writing agent implements your edits, you should set \"status\" = \"complete\". If this is the first time you've reviewed their work, status should be set to \"incomplete\". If the writing agent did not correctly implement your edits, you should set status to \"incomplete\".\n- edits: this is your specific suggested edits. The writing agent will be able to see these edits and update the text to incorporate the edits.\n\nUse the structured output parser and output clean JSON in this format (example):\n{\n\"status\": \"complete\",\n\"edits\": \"The writing agent has successfully implemented all the suggested edits. The text is now concise, informative, and focused on the main point while providing a brief introduction to AI. No further edits are necessary at this time.\"\n}\n\nDO NOT INCLUDE ANY OTHER TEXT BESIDES THE JSON OUTPUT.\n\nHere is the input text from the writing agent:\n{{ $json.output }}",
"options": {},
"promptType": "define",
"hasOutputParser": true
},
"retryOnFail": false,
"typeVersion": 1.7
},
{
"id": "e77541dd-0774-4545-a846-0106aa79fbf5",
"name": "聊天输出",
"type": "n8n-nodes-base.set",
"position": [
1820,
0
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "753c404e-fce4-4173-95d2-6fde9c543d5f",
"name": "output",
"type": "string",
"value": "={{ $('Writing Agent').first().json.output }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "549707c8-55db-4e8e-aecc-68615b6034ee",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
600,
-160
],
"parameters": {
"color": 4,
"width": 340,
"height": 320,
"content": "## 写作代理"
},
"typeVersion": 1
},
{
"id": "67c3ebb8-6d81-4add-a882-07fd0cc86f50",
"name": "便签 1",
"type": "n8n-nodes-base.stickyNote",
"position": [
980,
-160
],
"parameters": {
"color": 5,
"width": 340,
"height": 320,
"content": "## 编辑代理"
},
"typeVersion": 1
}
],
"active": false,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "8b9969b0-ae7b-45c0-9f41-72ea972d67cb",
"connections": {
"chatInput": {
"main": [
[
{
"node": "handle edits",
"type": "main",
"index": 0
}
]
]
},
"handle edits": {
"main": [
[
{
"node": "Writing Agent",
"type": "main",
"index": 0
}
]
]
},
"Editing Agent": {
"main": [
[
{
"node": "set variables",
"type": "main",
"index": 0
}
]
]
},
"Writing Agent": {
"main": [
[
{
"node": "Editing Agent",
"type": "main",
"index": 0
}
]
]
},
"set variables": {
"main": [
[
{
"node": "If Status Complete",
"type": "main",
"index": 0
}
]
]
},
"OpenAI Chat Model": {
"ai_languageModel": [
[
{
"node": "Writing Agent",
"type": "ai_languageModel",
"index": 0
},
{
"node": "Editing Agent",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"If Status Complete": {
"main": [
[
{
"node": "chatOutput",
"type": "main",
"index": 0
}
],
[
{
"node": "handle edits",
"type": "main",
"index": 0
}
]
]
},
"Window Buffer Memory": {
"ai_memory": [
[
{
"node": "Editing Agent",
"type": "ai_memory",
"index": 0
},
{
"node": "Writing Agent",
"type": "ai_memory",
"index": 0
}
]
]
},
"Structured Output Parser": {
"ai_outputParser": [
[
{
"node": "Editing Agent",
"type": "ai_outputParser",
"index": 0
}
]
]
},
"When chat message received": {
"main": [
[
{
"node": "chatInput",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
中级 - 人工智能, 营销
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
完成YouTube
基于细分领域的AI YouTube趋势发现器
If
Set
Code
+10
18 节点Leonardo Grigorio
人工智能
HDW潜在客户越野车
使用AI代理的自动化LinkedIn潜在客户生成、评分与沟通
If
Code
Sort
+17
86 节点Andrey
销售
创建品牌化AI驱动的网站聊天机器人
创建品牌化AI驱动的网站聊天机器人
If
Set
Code
+12
24 节点Wayne Simpson
产品
面试安排器
使用GPT-4o和Google Calendar聊天机器人自动安排面试
If
Set
Code
+11
25 节点Robert Breen
人力资源
LinkedIn人才管道:AI驱动的候选人搜索与排名(GPT-4o)
LinkedIn人才管道:AI驱动的候选人搜索与排名(GPT-4o)
If
Set
Code
+14
24 节点Badr
人力资源
构建与销售AI自动化与智能体
构建与销售AI自动化与智能体
If
Set
Wait
+15
74 节点NICKYAI
其他