AutomationFlowsAI & RAG › Improve AI Agent System Prompts with Gpt-4o Feedback Analysis and Email Delivery

Improve AI Agent System Prompts with Gpt-4o Feedback Analysis and Email Delivery

ByDaniel Rosehill @danielrosehill on n8n.io

This workflow configures an AI agent which provides an edited system prompt for an autonomous AI agent Based on the following pieces of information provided by the user in an input form: Agent name Agent purpose What's working What's not working Current system prompt

Event trigger★★☆☆☆ complexityAI-powered5 nodesForm TriggerAgentOpenAI ChatOutput Parser StructuredGmail
AI & RAG Trigger: Event Nodes: 5 Complexity: ★★☆☆☆ AI nodes: yes Added:

This workflow corresponds to n8n.io template #4197 — we link there as the canonical source.

This workflow follows the Agent → Form 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 →

Download .json
{
  "id": "rx7v6helgDYENRs2",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "System Prompt Tuner",
  "tags": [],
  "nodes": [
    {
      "id": "62a0e2bc-7c17-4546-b627-bbedc863a3a0",
      "name": "User inputs",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        -460,
        -80
      ],
      "parameters": {
        "options": {
          "buttonLabel": "Send For Evaluation"
        },
        "formTitle": "Agent Prompt Tuner",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Agent Name",
              "requiredField": true
            },
            {
              "fieldType": "textarea",
              "fieldLabel": "Agent Purpose",
              "requiredField": true
            },
            {
              "fieldType": "textarea",
              "fieldLabel": "What's Working?",
              "requiredField": true
            },
            {
              "fieldType": "textarea",
              "fieldLabel": "What's Not Working?",
              "requiredField": true
            },
            {
              "fieldType": "textarea",
              "fieldLabel": "Current System Prompt",
              "requiredField": true
            },
            {
              "fieldType": "textarea",
              "fieldLabel": "Sample Input (Prompt)"
            },
            {
              "fieldType": "textarea",
              "fieldLabel": "Example Output"
            }
          ]
        },
        "formDescription": "Enhances autonomous agent system prompts based on user provided descriptions of behavior and examples "
      },
      "typeVersion": 2.2
    },
    {
      "id": "355883e9-05c4-47a1-a9f1-37aec5e3a550",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -240,
        -80
      ],
      "parameters": {
        "text": "=Here is the information for your analysis:\n\nAgent Name: {{ $json['Agent Name'] }}\n\nAgent Purpose: {{ $json['Agent Purpose'] }}\n\nCurrent System Prompt: {{ $json['Current System Prompt'] }}\n\nHere is how I would evaluate its current performance.\n\nThis is working well: {{ $json['What\\'s Working?'] }}\n\nThis is what's going wrong: {{ $json['What\\'s Not Working?'] }}\n\nHere's an examlple of a prompt I wrote and the output I received. If the following section is blank, please disregard it. Otherwise, consider it in your evaluation:\n\nSample prompt: {{ $json['Sample Input (Prompt)'] }}\n\nThe prompt generated the following output:\n\n{{ $json['Example Output'] }}\n\n\nPlease generate the improved system prompt ensuring that your response adheres to the JSON formatting instruction.",
        "options": {
          "systemMessage": "You are an expert AI prompt engineer. \n\nYour task is to receive a set of observations about how a specific AI agent is performing. These observations include:\n\n* The name of the AI agent\n* A short description of the agent's intended purpose\n* A description of what *is* working well\n* A description of what *is not* working as expected\n* (Optionally) An example output from the current version of the agent\n\nUsing this information, your task is to analyze the shortcomings or gaps in the agent's behavior and generate a revised, full **system prompt** intended to improve its performance and address the identified issues.\n\nYour response should be in **JSON** format with the following fields:\n\n```json\n{\n  \"updated_system_prompt\": \"The full improved system prompt, rewritten from scratch or as a modification of the implied original\",\n  \"summary_of_improvements\": \"A short explanation of what was changed or improved and why\"\n}\n```\n\nYou must:\n\n* Use clear and specific instructions in the new system prompt.\n* Preserve functionality that is working well.\n* Directly address behaviors that need correction.\n* Avoid vague language and ensure the new prompt is actionable and well-structured.\n\nDo not include any commentary outside the JSON response."
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.9
    },
    {
      "id": "b869ffde-2392-4465-8092-9fbbbc9853b0",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -380,
        120
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "gpt-4o"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "315ef666-e3cc-4b75-9ec3-4a0c8f4938a0",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        -80,
        140
      ],
      "parameters": {
        "jsonSchemaExample": "{\n  \"updated_system_prompt\": \"The full improved system prompt, rewritten from scratch or as a modification of the implied original\",\n  \"summary_of_improvements\": \"A short explanation of what was changed or improved and why\"\n}"
      },
      "typeVersion": 1.2
    },
    {
      "id": "9143224c-c6ab-4e58-8b0c-e95b1f2f00a7",
      "name": "Gmail",
      "type": "n8n-nodes-base.gmail",
      "position": [
        120,
        -100
      ],
      "parameters": {
        "sendTo": "user@example.com",
        "message": "=<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n  <meta charset=\"UTF-8\">\n  <title>AI System Prompt Improvement Notification</title>\n  <style>\n    body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; background-color: #f9f9f9; padding: 20px; }\n    .container { background-color: #ffffff; border-radius: 8px; padding: 24px; max-width: 700px; margin: auto; box-shadow: 0 0 10px rgba(0,0,0,0.05); }\n    h2 { color: #2c3e50; border-bottom: 1px solid #ddd; padding-bottom: 4px; }\n    pre { background-color: #f4f4f4; padding: 12px; border-radius: 4px; overflow-x: auto; font-family: monospace; }\n    .footer { margin-top: 30px; font-size: 0.9em; color: #777; }\n  </style>\n</head>\n<body>\n  <div class=\"container\">\n    <p>Hi there!</p>\n    <p>You asked the <strong>AI System Prompt Improvement Agent</strong> to review the system prompt for <strong>{{ $('User inputs').item.json['Agent Name'] }}</strong>.</p>\n    <h2>\u2705 Recommended Updated System Prompt</h2>\n    <pre>{{ $json.output.updated_system_prompt }}</pre>\n    <h2>\ud83d\udcc4 Original System Prompt</h2>\n    <pre>{{ $('User inputs').item.json['Current System Prompt'] }}</pre>\n    <h2>\u270f\ufe0f Summary of Improvements</h2>\n    <p>{{ $json.output.summary_of_improvements }}</p>\n    <div class=\"footer\">\n      Regards,<br>\n      <strong>AI Improvement Agent</strong>\n    </div>\n  </div>\n</body>\n</html>",
        "subject": "=Improved prompt for: {{ $('User inputs').item.json['Agent Name'] }}"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "447d5b7f-6409-4470-aac7-be8e36c9e34d",
  "connections": {
    "AI Agent": {
      "main": [
        [
          {
            "node": "Gmail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "User inputs": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "AI Agent",
            "type": "ai_outputParser",
            "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.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

This workflow configures an AI agent which provides an edited system prompt for an autonomous AI agent Based on the following pieces of information provided by the user in an input form: Agent name Agent purpose What's working What's not working Current system prompt

Source: https://n8n.io/workflows/4197/ — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

This workflow contains community nodes that are only compatible with the self-hosted version of n8n.

Form Trigger, OpenAI Chat, Memory Buffer Window +4
AI & RAG

Innovation Manager. Uses formTrigger, agent, lmChatOpenAi, googleSheetsTool. Event-driven trigger; 9 nodes.

Form Trigger, Agent, OpenAI Chat +4
AI & RAG

This workflow automates end-to-end contract and invoice management using AI intelligence. It processes proposals through intelligent contract generation, approval workflows, and automated invoicing. O

Form Trigger, Data Table, Agent +4
AI & RAG

This n8n workflow template automates your lead generation and follow-up process using AI. It captures leads through a form, enriches them with company data, classifies them into different categories,

Gmail, Output Parser Structured, Form Trigger +5
AI & RAG

Automates SaaS operations by consolidating user management, AI-driven support triage, analytics, and billing into one unified system. User signups flow through registration, support requests route via

Form Trigger, Data Table, Agent +7