
Transform Basic Prompts into Professional AI Prompts with Multi-Agent Refinement
ๆ่ฟฐ
ๅ็ฑป
๐ง Engineering๐ค AI & Machine Learning
ไฝฟ็จ็่็น
n8n-nodes-base.setn8n-nodes-base.setn8n-nodes-base.coden8n-nodes-base.coden8n-nodes-base.switchn8n-nodes-base.telegramn8n-nodes-base.telegramn8n-nodes-base.stickyNoten8n-nodes-base.stickyNoten8n-nodes-base.stickyNote
ไปทๆ ผๅ
่ดน
ๆต่ง้0
ๆๅๆดๆฐ11/28/2025
workflow.json
{
"meta": {
"instanceId": "dc282686e80274fa577fe33e0807b4c85e8e2d2a1228cc825cb4dd308cceebf3",
"templateCredsSetupCompleted": true
},
"nodes": [
{
"id": "ab09b71e-8343-4a46-8937-910afdd103e6",
"name": "Google Sheets Trigger",
"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": "PrepareForFirstGen - 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": "ChatHistory - 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": "Create/Upate Modified Prompt",
"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": "Loop Over Items",
"type": "n8n-nodes-base.splitInBatches",
"position": [
80,
48
],
"parameters": {
"options": {}
},
"typeVersion": 3
},
{
"id": "ebaf3675-b5bd-45bf-acb0-bb7550df38c5",
"name": "PromptModifer",
"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": "Parse AI Chat",
"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": "ExecutionController",
"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": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"position": [
-832,
-496
],
"parameters": {
"width": 624,
"height": 464,
"content": "## ๐ค AI-Powered Prompt Enhancement Assistant\n### โก Quick Demo\n**Input**: \"Create a marketing strategy\" \n**Output**: \"Develop a comprehensive digital marketing strategy for a [business_type] targeting [target_audience]. Include market analysis, channel selection, budget allocation, timeline, and KPIs. Focus on [primary_goals] and consider [constraints].\"\n### ๐ What You Get\nโ
Enhanced prompts with clear structure \nโ
Extracted input variables for reusability \nโ
Topic classification and categories \nโ
Professional improvement notes \nโ
Complete audit trail in Google Sheets\n### ๐ฌ Perfect For\n- Content creation workflows\n- AI chatbot prompt optimization \n- Marketing copy enhancement\n- Technical documentation prompts\n- Educational prompt examples\n---\n๐ก **Ready to transform your prompts?** Follow the setup steps in the white notes below! โฌ๏ธ"
},
"typeVersion": 1
},
{
"id": "9d6f75aa-1ce3-4fab-9e21-32895c1fca8d",
"name": "Send Success Message To User",
"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": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"position": [
-832,
0
],
"parameters": {
"color": 5,
"width": 624,
"height": 736,
"content": "## ๐ ๏ธ STEP-BY-STEP SETUP GUIDE\n### 1๏ธโฃ Create Google Sheets (5 minutes)\nCreate a new Google Spreadsheet with 2 tabs:\n\n**๐Main Sheet** (Input prompts):\n- Columns: Original Prompt ID | Model | Original Prompt | Created Time\n**๐Modified Prompt Sheet** (Results):\n- Columns: Modified Prompt ID | Original Prompt ID | Topic | Topic Categories | Modified Prompt | Prompt Title | Prompt Type | Model Used | Improvement Notes | Updated Time | Created Time | isProcessed\n\n### 2๏ธโฃ Configure n8n Credentials\nAdd these in **Settings > Credentials**:\n- Gemini API credential\n- Telegram API credential \n- Groq API credential\n- Google Sheets OAuth2 credential\n\n### 3๏ธโฃ Update Workflow Settings\n- Replace ALL Google Sheets node **Document IDs** with your spreadsheet ID\n- Update **Chat ID** in Telegram node (optional notification)\n- Test API connections in each AI Chat node\n\n### 4๏ธโฃ Test Your Setup\n1. Add test prompt to Main sheet: \"Explain machine learning\"\n2. Run workflow manually\n3. Check ModifiedPrompt sheet for results\n4. Monitor Logging sheet for any errors\n\nโ
**Setup complete!** Your workflow will now process prompts automatically every minute."
},
"typeVersion": 1
},
{
"id": "6d349710-659e-4eb7-8845-44603c13305e",
"name": "Sticky Note2",
"type": "n8n-nodes-base.stickyNote",
"position": [
-160,
-592
],
"parameters": {
"color": 5,
"width": 624,
"height": 512,
"content": "## ๐ WORKFLOW FLOW EXPLAINED\n### ๐ฅ **INPUT STAGE**\n**Google Sheets Trigger** โ **Loop Over Items** โ **ProcessController**\n- Processes one prompt at a time to prevent overload\n- Sets up global variables for execution tracking\n### ๐ค **AI ENHANCEMENT STAGE** \n**ExecutionController** โ **PromptModifier (AI Agent)** โ **Parse AI Chat**\n- **Gemini / Groq AI** analyzes and enhances basic prompts\n- **Smart parsing** extracts JSON data with 3 fallback methods\n### โ
**QUALITY ASSURANCE STAGE**\n**isMissingFields** โ **Finalize Data** โ **Create/Update Google Sheets** โ **Telegram Notification**\n- **Validates** all required fields are complete and accurate\n- **Formats** final data structure for storage\n- **Stores** enhanced prompt with full metadata\n- **Notifies** user via Telegram with result summary\n### ๐ก๏ธ **ERROR HANDLING**\n- **Execution limits** prevent infinite loops (max 3 OPM)\n- **Graceful fallbacks** handle API failures and parsing errors"
},
"typeVersion": 1
},
{
"id": "1ae38515-539f-4721-8fdc-cbb3ccbaf9ab",
"name": "Finalize ModifiedPrompt DataModel",
"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": "Send Exceed Limits Error",
"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": "Sticky Note3",
"type": "n8n-nodes-base.stickyNote",
"position": [
-176,
-48
],
"parameters": {
"width": 1232,
"height": 784
},
"typeVersion": 1
},
{
"id": "5ca70762-a37f-4cda-a5fc-889e0f2afa90",
"name": "Sticky Note4",
"type": "n8n-nodes-base.stickyNote",
"position": [
1088,
-144
],
"parameters": {
"color": 5,
"width": 608,
"height": 880,
"content": "## ๐ง CUSTOMIZATION OPTIONS\n### ๐จ **Modify AI Behavior**\n- **Change AI prompts**: Edit system messages in ExecutionController nodes\n- **Custom enhancement logic**: Update Code nodes with your rules\n### ๐ **Add Custom Fields**\n- **Custom validation**: Modify field checking logic \n- **Extended output**: Add columns to Google Sheets + parsing logic\n### โ๏ธ **Performance Tuning**\n- **Retry limits**: Change MAX_OPM_COUNTS (default: 3)\n- **Processing speed**: Adjust polling interval in Google Sheets Trigger\n- **Batch size**: Modify Loop Over Items batch settings\n---\n\n## ๐ฉบ TROUBLESHOOTING\n### โ **Common Issues**\n- **\"Workflow keeps running infinitely\"** \nโ Check Eorkflow's logs for stuck executions, disable Loop Over Items temporarily\n\n- **\"AI agent returns ERROR responses\"** \nโ Verify API credentials, check rate limits, review system prompts\n\n- **\"Missing fields not generated\"** \nโ Ensure EmptyFieldsExtractor code matches your field names exactly\n\n- **\"Google Sheets sync issues\"** \nโ Refresh OAuth tokens, verify spreadsheet permissions\n### ๐ **Debug Checklist**\nโ
All API credentials valid and connected \nโ
Google Sheets Document IDs updated correctly \nโ
Spreadsheet has all 2 required tabs with correct column names \nโ
Test prompts added to Main sheet follow the expected format \n### ๐ก **Performance Tips** \n- Monitor API usage to avoid rate limits\n- Set up error alerts via Telegram notifications\n- Regular cleanup of old execution logs"
},
"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
}
]
]
}
}
}