8
n8n 中文网amn8n.com

基础提示词转换为专业 AI 提示词(多智能体优化)

高级

这是一个Engineering, Multimodal AI领域的自动化工作流,包含 19 个节点。主要使用 Set, Code, Switch, Telegram, GoogleSheets 等节点。 通过多智能体优化将基础提示词转换为专业 AI 提示词

前置要求
  • Telegram Bot Token
  • Google Sheets API 凭证
  • Google Gemini API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "dc282686e80274fa577fe33e0807b4c85e8e2d2a1228cc825cb4dd308cceebf3",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "ab09b71e-8343-4a46-8937-910afdd103e6",
      "name": "Google Sheets 触发器",
      "type": "n8n-nodes-base.googleSheetsTrigger",
      "position": [
        -96,
        48
      ],
      "parameters": {
        "options": {
          "columnsToWatch": [
            "Original Prompt ID",
            "Original Prompt"
          ]
        },
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1O4dPvdvpRe6X6i7iwA2O-a7JsxHtFswS4_phjIv_wSA/edit#gid=0",
          "cachedResultName": "OriginalPrompt"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1O4dPvdvpRe6X6i7iwA2O-a7JsxHtFswS4_phjIv_wSA",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1O4dPvdvpRe6X6i7iwA2O-a7JsxHtFswS4_phjIv_wSA/edit?usp=drivesdk",
          "cachedResultName": "Prompt"
        }
      },
      "credentials": {
        "googleSheetsTriggerOAuth2Api": {
          "id": "MyejtRWKlKDhm2MD",
          "name": "Mr.Eo account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "9dec857c-b6ac-4476-bc38-c16afa8132e2",
      "name": "准备首次生成 - OPM",
      "type": "n8n-nodes-base.set",
      "position": [
        80,
        240
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "f94c3091-aec9-40ec-a028-f0b15c656042",
              "name": "=Original Prompt ID",
              "type": "number",
              "value": "={{ $json[\"Original Prompt ID\"] }}"
            },
            {
              "id": "ff9f7965-6c0f-416b-8a76-f1c6ee03f5a6",
              "name": "chatInput",
              "type": "string",
              "value": "={{ $json.chatInput }}"
            },
            {
              "id": "2024e446-f2dc-4664-8574-1a6260ce5050",
              "name": "=isProcessed",
              "type": "boolean",
              "value": false
            },
            {
              "id": "801ba818-932c-4ba9-8a30-2db9bb8d7296",
              "name": "sessionId",
              "type": "number",
              "value": 0
            },
            {
              "id": "11c635c0-afad-464b-87cf-a83bddf303b9",
              "name": "systemMessage",
              "type": "string",
              "value": "={{ $json.systemMessage }}"
            }
          ]
        }
      },
      "typeVersion": 3.4,
      "alwaysOutputData": false
    },
    {
      "id": "1ffa6b8e-c262-41a2-94b7-8fbf1b06b2db",
      "name": "聊天历史 - PM",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        128,
        560
      ],
      "parameters": {
        "contextWindowLength": 4
      },
      "typeVersion": 1.3
    },
    {
      "id": "a5edfdc1-32f1-4b6b-89b4-f82a8e4593e4",
      "name": "Qwen3 - PM",
      "type": "@n8n/n8n-nodes-langchain.lmChatGroq",
      "position": [
        -144,
        560
      ],
      "parameters": {
        "model": "qwen/qwen3-32b",
        "options": {}
      },
      "credentials": {
        "groqApi": {
          "id": "8X67cqHRl8dDEhIG",
          "name": "Groq account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "37cca21a-1928-4d37-b886-eada46a0e2d0",
      "name": "Gemini - PM",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        -16,
        560
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "googlePalmApi": {
          "id": "2p62L6kxEmXHWxxx",
          "name": "Google Gemini(PaLM) Api account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "f9f19043-f30b-4c17-adb0-ad074ae25638",
      "name": "创建/更新修改后的提示",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        864,
        288
      ],
      "parameters": {
        "columns": {
          "value": {
            "Topic": "={{ $json.Topic }}",
            "Model Used": "Gemini Pro 2.5",
            "Prompt Type": "={{ $json[\"Prompt Type\"] }}",
            "isProcessed": "={{ $json[\"Parsing Success\"] }}",
            "Created Time": "={{ $now.toISO() }}",
            "Prompt Title": "={{ $json[\"Prompt Title\"] }}",
            "Updated Time": "={{ $json[\"Last Updated\"] }}",
            "Modified Prompt": "={{ $json[\"Modified Prompt\"] }}",
            "Topic Categories": "={{ $json[\"Topic Categories\"] }}",
            "Improvement Notes": "={{ $json[\"Improvement Notes\"] }}",
            "Original Prompt ID": "={{ $json[\"Original Prompt ID\"] }}"
          },
          "schema": [
            {
              "id": "Modified Prompt ID",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Modified Prompt ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Original Prompt ID",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Original Prompt ID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "isProcessed",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "isProcessed",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Topic",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Topic",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Topic Categories",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Topic Categories",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Modified Prompt",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Modified Prompt",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Prompt Title",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Prompt Title",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Prompt Type",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Prompt Type",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Input Variables",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Input Variables",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Model Used",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Model Used",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Improvement Notes",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Improvement Notes",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Updated Time",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Updated Time",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Created Time",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Created Time",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "Original Prompt ID"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1751172685,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1O4dPvdvpRe6X6i7iwA2O-a7JsxHtFswS4_phjIv_wSA/edit#gid=1751172685",
          "cachedResultName": "ModifiedPrompt"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1O4dPvdvpRe6X6i7iwA2O-a7JsxHtFswS4_phjIv_wSA",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1O4dPvdvpRe6X6i7iwA2O-a7JsxHtFswS4_phjIv_wSA/edit?usp=drivesdk",
          "cachedResultName": "Prompt"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "HBspBjsKUBEdhs2e",
          "name": "Mr.Eo - Prompt Refiner"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "933a9dba-3786-43ad-8c00-02c321792af0",
      "name": "遍历项目",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        80,
        48
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "ebaf3675-b5bd-45bf-acb0-bb7550df38c5",
      "name": "提示修改器",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -96,
        416
      ],
      "parameters": {
        "options": {
          "systemMessage": "={{$json.systemMessage}}"
        },
        "needsFallback": true
      },
      "typeVersion": 2.1
    },
    {
      "id": "805e65df-27b1-4336-bc71-6dd964d0ca16",
      "name": "解析 AI 聊天",
      "type": "n8n-nodes-base.code",
      "position": [
        272,
        416
      ],
      "parameters": {
        "jsCode": "// AI Response Parser for Prompt Refiner Workflow\n// This script parses AI agent output and extracts structured data\n\nconst outputItems = []; // Array to store our final, precisely structured items\n\nfor (const item of items) {\n    const inputItem = item.json; // The combined item from the Merge node\n    \n    // Initialize parsed data with defaults - MOVED OUTSIDE TRY BLOCK\n    let parsedData = {\n        \"Original Prompt ID\": $getWorkflowStaticData(\"global\")[\"Original Prompt ID\"] || null,\n        \"Prompt Title\": \"\",\n        \"Topic\": \"\",\n        \"Topic Categories\": \"\",\n        \"Modified Prompt\": \"ERROR: Could not parse AI response\",\n        \"Prompt Type\": \"Error\",\n        \"Last Updated\": new Date().toISOString(),\n        \"Improvement Notes\": \"\",\n        \"Raw AI Output Length\": 0,\n        \"Parsing Success\": false,\n        \"Operation Counts\": $getWorkflowStaticData(\"global\").opm_counts || 0\n    };\n    \n    try {\n        // Get the AI output from the response\n        let aiOutput = inputItem.output || inputItem.text || '';\n      // console.log(aiOutput)\n        parsedData[\"Raw AI Output Length\"] = aiOutput.length;\n        \n        // Try different methods to extract JSON from AI response\n        let jsonData = null;\n        \n        // Method 1: Look for JSON block between ```json and ```\n        const jsonBlockMatch = aiOutput.match(/```json\\s*([\\s\\S]*?)\\s*```/);\n        if (jsonBlockMatch) {\n            try {\n                jsonData = JSON.parse(jsonBlockMatch[1].trim());\n            } catch (e) {\n                console.log('Failed to parse JSON block:', e.message);\n            }\n        }\n        \n        // Method 2: Look for JSON object starting with { and ending with }\n        if (!jsonData) {\n            const jsonObjectMatch = aiOutput.match(/\\{[\\s\\S]*\\}/);\n            if (jsonObjectMatch) {\n                try {\n                    jsonData = JSON.parse(jsonObjectMatch[0]);\n                } catch (e) {\n                    console.log('Failed to parse JSON object:', e.message);\n                }\n            }\n        }\n        \n        // Method 3: Try to parse the entire output as JSON\n        if (!jsonData) {\n            try {\n                jsonData = JSON.parse(aiOutput.trim());\n            } catch (e) {\n                console.log('Failed to parse entire output as JSON:', e.message);\n            }\n        }\n        \n        // If we successfully parsed JSON, extract the data\n        if (jsonData) {\n          parsedData[\"sessionId\"] = $('PrepareForFirstGen - OPM').first().json.sessionId\n          parsedData[\"Modified Prompt\"] = jsonData.modified_prompt || jsonData.modifiedPrompt || \"ERROR: No modified prompt found\";\n          parsedData[\"Prompt Type\"] = jsonData.prompt_type || jsonData.promptType || \"\";\n          parsedData[\"Prompt Title\"] = jsonData.prompt_title || jsonData.promptTitle || \"\";\n          parsedData[\"Topic\"] = jsonData.topic || jsonData[\"Topic\"] || \"\";\n          parsedData[\"Topic Categories\"] = jsonData.topic_categories || jsonData.topicCategory || \"\";\n          parsedData[\"Parsing Success\"] = true;\n            \n            // Extract additional fields\n            parsedData[\"Improvement Notes\"] = jsonData.improvement_notes || jsonData.improvementNotes || null;\n          \n            // If we have a valid modified prompt, change type from Error\n            if (parsedData[\"Modified Prompt\"] !== \"ERROR: No modified prompt found\") {\n                // Keep the prompt type from JSON, but default to \"Text\" if it's still \"Error\"\n                if (parsedData[\"Prompt Type\"] === \"Error\") {\n                    parsedData[\"Prompt Type\"] = \"Text\";\n                }\n            } else {\n                parsedData[\"Prompt Type\"] = \"Error\";\n            }\n        } else {\n            // If no JSON found, try to extract some basic info from text\n            parsedData[\"Modified Prompt\"] = \"ERROR: AI output format unexpected (no JSON block).\";\n            parsedData[\"Improvement Notes\"] = \"AI did not respond in expected JSON format. Raw output length: \" + aiOutput.length + \" characters\";\n        }\n      \n        \n    } catch (error) {\n        // Handle any unexpected errors - parsedData is already defined above\n        parsedData[\"Modified Prompt\"] = `ERROR: Parsing failed - ${error.message}`;\n        parsedData[\"Prompt Type\"] = \"Error\";\n        parsedData[\"Improvement Notes\"] = `Parsing error: ${error.message}`;\n        parsedData[\"Parsing Success\"] = false;\n    }\n    \n    outputItems.push(parsedData);\n}\n\nreturn outputItems;"
      },
      "typeVersion": 2
    },
    {
      "id": "19ece185-4692-474d-9550-67182ece8b81",
      "name": "执行控制器",
      "type": "n8n-nodes-base.code",
      "position": [
        -96,
        240
      ],
      "parameters": {
        "jsCode": "// Fixed ExecutionController for n8n - Prevents Duplicate AI Executions\n// This code prevents duplicate AI agent executions by tracking processed prompts\n// Fixing loop, proccess twice at the same time, and limiting the number of executions for a single prompt\n\n// Get input data\nconst input = $input.first();\n\n// Check if input is existing and there is json in input\nif (!input || !input.json) {\n  throw new Error(\"No input data for AI Agent\");\n}\nconsole.log(\"From OPG - Execution Controller: \\n\", input);\n\n//-------------Global---Variables---Init--------------//\n// Prevent multiple executions\n// Initialize Execution Key use to track if the prompt has already executed.\nconst staticData = $getWorkflowStaticData(\"global\");\nconst promptId = input.json[\"Original Prompt ID\"];\nconst timestamp = new Date().toISOString();\nconst agentKey = `exec_prompt_#${promptId}_${timestamp}`;\nconst EXEC_KEY = \"lastAgentExecutionKey\";\nconst MAX_OPM_COUNTS = staticData.MAX_OPM_COUNTS || 3;\nlet systemMessage = \"\";\nlet opm_counts = staticData.opm_counts || 1;\n\n// 1) Duplicate prevention\n// Check if agent processes the input twice at the time.\nif (staticData[EXEC_KEY] === agentKey) {\n  console.log(\"Skipping duplicate AI execution\");\n  return [input];\n}\n\nstaticData[EXEC_KEY] = agentKey;\n\n// 2) Track how many times we've run for this prompt\nif (staticData[\"Original Prompt ID\"] === promptId) {\n  opm_counts += 1;\n} else {\n  staticData[\"Original Prompt ID\"] = promptId;\n  opm_counts = 1;\n}\n\nstaticData.opm_counts = opm_counts;\n\n// check if agent processes the same prompt and if it not exeeds opm limits ,meaning: Do not let the OPM Agent run more than 3 times for 1 prompt.\n\n// 4) Now check against your limit\nif (opm_counts > MAX_OPM_COUNTS) {\n  throw new Error(\"Exceeded Original Prompt Modifier Limits!\");\n}\nconst buildSystemMessage = () => {\n  let message = \"\"\n  // Check if from isMissingFields Node, if yes means regenerate with all missing data.\n  if (opm_counts > 1) {\n    message = `\n# Prompt Regeneration Agent (Retry ${opm_counts}/${MAX_OPM_COUNTS})\n\nYou are handling a REGENERATION task. The previous attempt didn't complete all required fields. Your job is to COMPLETE the missing data while preserving any good existing content.\n\n## CRITICAL REQUIREMENTS\n⚠️ **This is attempt ${opm_counts} of ${MAX_OPM_COUNTS}** - YOU MUST generate ALL fields this time.\n\n## Context Information\n- **Original User Prompt**: {{ $json[\"Original Prompt\"] || $json.chatInput }}\n- **Current Modified Prompt**: {{ $json[\"Modified Prompt\"] || \"None generated yet\" }}\n- **Missing Fields**: {{ JSON.stringify($json[\"Missing Fields\"] || []) }}\n- **Previous Attempt Quality**: {{ $json[\"Previous Quality Score\"] || \"Unknown\" }}\n\n## Your Regeneration Task\n1. **PRESERVE** any existing good content from the current modified prompt\n2. **COMPLETE** all missing fields with high-quality data\n3. **IMPROVE** the overall prompt structure and clarity\n4. **ENSURE** all required fields have meaningful, non-empty values\n5. **FOCUS** on fixing the specific issues from the previous attempt\n\n## Field Requirements (ALL MUST BE COMPLETED)\n- **modified_prompt**: Enhanced, detailed prompt (not empty, not \"Unknown\")\n- **prompt_type**: Exactly one of: Code|Text|Image|Analysis|Creative|Query\n- **prompt_title**: Descriptive, specific title (not generic)\n- **topic**: Clear main subject matter (not vague)\n- **topic_categories**: 2-3 relevant categories, comma-separated\n- **input_variables**: Array of meaningful variable names (if applicable)\n- **improvement_notes**: Specific details about what was enhanced\n\n## Quality Standards\n- **No empty values** - every field must have meaningful content\n- **No generic responses** - be specific and relevant\n- **No \"Unknown\" or error values** - generate real data\n- **Professional quality** - this is the final attempt\n\n## Your Response Format\nYou MUST respond ONLY with a complete JSON object containing ALL fields:\n\n\\`\\`\\`json\n{\n  \"modified_prompt\": \"Comprehensive enhanced prompt with all details\",\n  \"prompt_type\": \"Choose from: Code|Text|Image|Analysis|Creative|Query\",\n  \"prompt_title\": \"Specific, descriptive title\",\n  \"topic\": \"Clear, specific main topic\",\n  \"topic_categories\": \"Category1, Category2, Category3\",\n  \"input_variables\": [\"variable1\", \"variable2\", \"variable3\"],\n  \"improvement_notes\": \"Detailed explanation of all enhancements made\"\n}\n\\`\\`\\`\n\n## ⚠️ CRITICAL WARNING\nIf you fail to complete ALL fields properly this time, the workflow will terminate with an error. This is your final opportunity to create a complete, high-quality enhanced prompt.\n`;\n  } else {\n    message = `\n# Prompt Modifier Agent\n\nYou are the first agent in a prompt refinement pipeline. Your job is to take a basic user prompt and enhance it with more details and clarity.\n\n## Your Task\n1. **Analyze** the original prompt for intent and context\n2. **Add specificity** - make vague requests more specific\n3. **Add structure** - break down complex requests into clear steps\n4. **Identify variables** - parts that could be parameterized for reuse\n5. **Maintain intent** - don't change what the user actually wants\n\n## Enhancement Guidelines\n- Add context clues and examples where helpful\n- Specify expected output format if unclear\n- Add relevant constraints or requirements\n- Keep the core request unchanged\n- Make it more actionable and clear\n\n## Your Response Format\nYou MUST respond ONLY with a JSON object:\n\n\\`\\`\\`json\n{\n  \"modified_prompt\": \"Enhanced version with more detail and context\",\n  \"prompt_type\": \"Code|Text|Image|Analysis|Creative|Query\",\n  \"prompt_title\": \"\",\n  \"topic\": \"Main topic...\",\n  \"topic_categories\": \"Comma-separated categories...\",\"\n  \"improvement_notes\": \"What was added/changed\"\n}\n\\`\\`\\`\n\n## Original Prompt:\n{{ $json.chatInput }}\n`;\n  }\n  return message\n};\n\nsystemMessage = buildSystemMessage()\n\n// ✅ FIXED: Always return array of objects in proper n8n format\nreturn [\n  {\n    json: {\n      sessionId: input.json.sessionId || 0,\n      chatInput: input.json[\"Original Prompt\"] || input.json[\"Modified Prompt\"] || \"\",\n      systemMessage: systemMessage,\n      isProcessed: input.json.isProcessed || false,\n      \"Original Prompt ID\": staticData[\"Original Prompt ID\"],\n      opm_counts: opm_counts,\n      processedAt: new Date().toISOString(),\n    },\n  },\n];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "7b68ef9c-b740-4e76-8525-d95fce436c8c",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -832,
        -496
      ],
      "parameters": {
        "width": 624,
        "height": 464,
        "content": "## 🤖 AI 驱动的提示增强助手"
      },
      "typeVersion": 1
    },
    {
      "id": "9d6f75aa-1ce3-4fab-9e21-32895c1fca8d",
      "name": "向用户发送成功消息",
      "type": "n8n-nodes-base.telegram",
      "position": [
        304,
        48
      ],
      "webhookId": "bcadb4ba-4c20-42ae-8ed6-71eb04f3cab1",
      "parameters": {
        "text": "=🤖 **Prompt Refiner Complete!**  \n\n✅ **\"{{ $('Create/Upate Modified Prompt').item.json['Prompt Title'] }}\"**\n\n📝 **Topic**: {{ $('Create/Upate Modified Prompt').item.json.Topic }} \n\n🏷️ **Type**: {{ $('Create/Upate Modified Prompt').item.json['Prompt Type'] }} \n\n🎯 **Categories**: {{ $('Create/Upate Modified Prompt').item.json['Topic Categories'] }}  \n\n🚨**Enhanced Prompt Preview:** {{ $('Create/Upate Modified Prompt').item.json['Modified Prompt'].substring(0, 150) }}...  \n\n⚡ **Processed by**: {{ $('Create/Upate Modified Prompt').item.json['Model Used'] }} \n\n🕒 **Completed**: {{ $now.toFormat('HH:mm') }}  View full results in your Google Sheet! 📊",
        "chatId": "7449389541",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "HzB95YfWtLzBKrKQ",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "2ba1aa1f-98fc-482e-8d2e-1b04f6f3f2ba",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -832,
        0
      ],
      "parameters": {
        "color": 5,
        "width": 624,
        "height": 736,
        "content": "## 🛠️ 分步设置指南"
      },
      "typeVersion": 1
    },
    {
      "id": "6d349710-659e-4eb7-8845-44603c13305e",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -160,
        -592
      ],
      "parameters": {
        "color": 5,
        "width": 624,
        "height": 512,
        "content": "## 🔄 工作流程说明"
      },
      "typeVersion": 1
    },
    {
      "id": "1ae38515-539f-4721-8fdc-cbb3ccbaf9ab",
      "name": "最终确定修改后提示数据模型",
      "type": "n8n-nodes-base.set",
      "position": [
        656,
        288
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "f6605c6c-29ff-4916-ac5a-1b0f3fe6dc86",
              "name": "Original Prompt ID",
              "type": "string",
              "value": "={{ $json[\"Original Prompt ID\"] }}"
            },
            {
              "id": "24a66be5-64d9-4700-b05d-c01f1cae58e5",
              "name": "isProcessed",
              "type": "boolean",
              "value": true
            },
            {
              "id": "52150325-d494-4898-8564-1e38a7edeea7",
              "name": "Prompt Title",
              "type": "string",
              "value": "={{ $json[\"Prompt Title\"] }}"
            },
            {
              "id": "2c2a145b-2d97-44ae-8eae-32a6e1f3b45c",
              "name": "Topic",
              "type": "string",
              "value": "={{ $json.Topic }}"
            },
            {
              "id": "ed392bfe-04cb-4f90-819b-23d0a8dc3b80",
              "name": "Topic Categories",
              "type": "string",
              "value": "={{ $json[\"Topic Categories\"] }}"
            },
            {
              "id": "a2eb11e6-9aae-4b44-9c11-c3bf02313557",
              "name": "Modified Prompt",
              "type": "string",
              "value": "={{ $json[\"Modified Prompt\"] }}"
            },
            {
              "id": "5a8f69aa-5026-4435-8dc0-6cd2ac99bd80",
              "name": "Prompt Type",
              "type": "string",
              "value": "={{ $json[\"Prompt Type\"] }}"
            },
            {
              "id": "03510c85-ccc8-4237-a3a7-508d00eaf2e6",
              "name": "Last Updated",
              "type": "string",
              "value": "={{ $now.toISO() }}"
            },
            {
              "id": "ed43101a-4553-4233-8eab-8db63673833d",
              "name": "Improvement Notes",
              "type": "string",
              "value": "={{ $json[\"Improvement Notes\"] }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "1b2e4c68-d5c4-4dcf-b88a-eeaf44318ac9",
      "name": "发送超出限制错误",
      "type": "n8n-nodes-base.telegram",
      "position": [
        656,
        528
      ],
      "webhookId": "8e19ad94-df4f-46db-817f-8855adc898bf",
      "parameters": {
        "text": "=❌ **PromptRefiner Processing Failed**\n\n**Prompt ID**: {{ $('Google Sheets Trigger').item.json['Original Prompt ID'] }}\n**Original Prompt**: \"{{ $('Google Sheets Trigger').item.json['Original Prompt'].substring(0, 80) }}...\"\n\n🔄 **Issue**: Maximum retry attempts reached (3/3)\n💡 **Reason**: AI agents couldn't complete all required fields after multiple attempts\n\n**What happened:**\nOur system tried 3 times to enhance your prompt but encountered persistent issues with field completion. This might be due to:\n• Complex or unclear original prompt\n• AI service temporary limitations\n• Missing context information\n\n**Next steps:**\n✅ Try rephrasing your prompt more clearly\n✅ Check if your prompt has sufficient detail\n✅ Wait a few minutes and try again\n✅ Contact support if issue persists\n\n📋 **Check your Google Sheets Logging tab for detailed error information**\n\n⏰ **Failed at**: {{ $now.toFormat('HH:mm') }}",
        "chatId": "7449389541",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "HzB95YfWtLzBKrKQ",
          "name": "Telegram account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "2302528e-d5c3-4a06-9864-67dd888f07d7",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -176,
        -48
      ],
      "parameters": {
        "width": 1232,
        "height": 784
      },
      "typeVersion": 1
    },
    {
      "id": "5ca70762-a37f-4cda-a5fc-889e0f2afa90",
      "name": "便签4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1088,
        -144
      ],
      "parameters": {
        "color": 5,
        "width": 608,
        "height": 880,
        "content": "## 🔧 自定义选项"
      },
      "typeVersion": 1
    },
    {
      "id": "42fe199c-c5e3-4f75-800e-fc3ed355e8ee",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "position": [
        448,
        400
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "allDatavalid",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "loose"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "95bda34b-9a58-4039-b520-0d6088619481",
                    "operator": {
                      "type": "boolean",
                      "operation": "false",
                      "singleValue": true
                    },
                    "leftValue": "={{ \n  (\n    !$json[\"Original Prompt ID\"] ||\n    !$json[\"Topic\"] || \n    !$json[\"Prompt Title\"] || \n    !$json[\"Topic Categories\"] || \n    !$json[\"Prompt Type\"] || \n    !$json[\"Improvement Notes\"]\n  ) && \n  ($json[\"Operation Counts\"] <= 2)\n}}\n",
                    "rightValue": 1
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "missingData",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "loose"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "ee181ecc-a353-4209-8dab-9da3fa775481",
                    "operator": {
                      "type": "boolean",
                      "operation": "true",
                      "singleValue": true
                    },
                    "leftValue": "={{ (!$json[\"Original Prompt ID\"] || !$json[\"Topic\"] || !$json[\"Prompt Title\"] || !$json[\"Topic Categories\"] || !$json[\"Prompt Type\"] || !$json[\"Improvement Notes\"]) &&  ($json[\"Operation Counts\"] <= 2) }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "exceedLimits",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "loose"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "a2b258da-c5c6-4258-89a4-fdb749c7aeef",
                    "operator": {
                      "type": "number",
                      "operation": "gte"
                    },
                    "leftValue": "={{ $json[\"Operation Counts\"] }}",
                    "rightValue": 3
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {},
        "looseTypeValidation": true
      },
      "typeVersion": 3.2
    }
  ],
  "pinData": {},
  "connections": {
    "Switch": {
      "main": [
        [
          {
            "node": "Finalize ModifiedPrompt DataModel",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "ExecutionController",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send Exceed Limits Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Qwen3 - PM": {
      "ai_languageModel": [
        [
          {
            "node": "PromptModifer",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Gemini - PM": {
      "ai_languageModel": [
        [
          {
            "node": "PromptModifer",
            "type": "ai_languageModel",
            "index": 1
          }
        ]
      ]
    },
    "Parse AI Chat": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "PromptModifer": {
      "main": [
        [
          {
            "node": "Parse AI Chat",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [
          {
            "node": "Send Success Message To User",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "ExecutionController",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ChatHistory - PM": {
      "ai_memory": [
        [
          {
            "node": "PromptModifer",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "ExecutionController": {
      "main": [
        [
          {
            "node": "PrepareForFirstGen - OPM",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets Trigger": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "PrepareForFirstGen - OPM": {
      "main": [
        [
          {
            "node": "PromptModifer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create/Upate Modified Prompt": {
      "main": [
        []
      ]
    },
    "Finalize ModifiedPrompt DataModel": {
      "main": [
        [
          {
            "node": "Create/Upate Modified Prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

高级 - 工程, 多模态 AI

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
高级
节点数量19
分类2
节点类型12
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

外部链接
在 n8n.io 查看

分享此工作流