{
  "id": "HyjRDR7O78FdTjJM",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "6. Generate and Auto-Evaluate Facebook Ad Headlines using GPT-4o-mini",
  "tags": [],
  "nodes": [
    {
      "id": "53bc6494-458c-4dcb-a66c-092fb30bf6b7",
      "name": "Send a message",
      "type": "n8n-nodes-base.gmail",
      "position": [
        2784,
        144
      ],
      "parameters": {
        "message": "={{ $('Agent_HeadlineWriter').item.json.output }}",
        "options": {}
      },
      "typeVersion": 2.1
    },
    {
      "id": "ca661097-1b4e-4dc6-b22c-2ff220106928",
      "name": "FormTrigger_CopywritingBrief",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        256,
        400
      ],
      "parameters": {
        "options": {},
        "formTitle": "Copywriting Agent",
        "formFields": {
          "values": [
            {
              "fieldLabel": "What is your product about?",
              "requiredField": true
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "340fb887-e9e7-45d6-8294-09337c5b20fc",
      "name": "Set_PromptForHeadline",
      "type": "n8n-nodes-base.set",
      "position": [
        464,
        432
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "e1ad4483-fb6d-4a4a-8589-615fbe8530c9",
              "name": "Prompt For Agent",
              "type": "string",
              "value": "Write a facebook ad headline for this product:"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "08915a22-5c32-4680-a299-9588fffc08b2",
      "name": "LLM_HeadlineWriterModel",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        784,
        608
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "a831df58-17e1-4e56-863b-e5918b1a4e80",
      "name": "Agent_HeadlineWriter",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        816,
        384
      ],
      "parameters": {
        "text": "={{ $json['Prompt For Agent'] }}:{{ $('FormTrigger_CopywritingBrief').item.json['What is your product about?'] }}\n\n",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 1.8
    },
    {
      "id": "fd5cdd53-4738-4023-ac23-f8ada2c176f9",
      "name": "LLM_EvalCriteriaModel",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1216,
        576
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "d9e284c1-92d1-43c9-9307-a4b3a2d3479f",
      "name": "LLM_HeadlineEvaluatorModel",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1616,
        592
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "2484f5c0-6d3b-4a81-a82e-bb9619bc27c6",
      "name": "LLM_BottomLineModel",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        2128,
        624
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "15d3350a-4fe1-49dd-8a2a-3f03350c18a2",
      "name": "Agent_IterationDecision",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        2144,
        384
      ],
      "parameters": {
        "text": "=Based on the bottom line:{{ $json.output }}\n\n\nDecide if we need another iteration.\nReturn NO if we dont,\notherwise return YES and add your feedback.",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 1.8
    },
    {
      "id": "086982ae-6aef-43c8-8cd1-228a2fcaebe0",
      "name": "If_NeedMoreIterations",
      "type": "n8n-nodes-base.if",
      "position": [
        2576,
        224
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "7f7d7b1c-e8ae-4a87-a8fe-43e32f270b64",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.output }}",
              "rightValue": "NO"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "02058dda-acda-4d7d-bf31-062598f91683",
      "name": "Agent_HeadlineEvaluator",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1712,
        384
      ],
      "parameters": {
        "text": "=Your goal is to asses the output of an AI agent.\nIt was supposed to:\n{{ $('Set_PromptForHeadline').item.json['Prompt For Agent'] }}\n\nThe answer it gave is:{{ $('Agent_HeadlineWriter').item.json.output }}\n\nProvide your response using these parameters:{{ $json.output }}. make sure you calculate your average and give a bottom line.",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 1.8
    },
    {
      "id": "14734fe9-5368-40b6-b386-df80aa281507",
      "name": "Agent_EvalCriteriaBuilder",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1264,
        384
      ],
      "parameters": {
        "text": "=Your goal is to define parametes for assesing the output of this prompt:\n{{ $('Set_PromptForHeadline').item.json['Prompt For Agent'] }}\n\nWhich parameters would you suggest? give me 5 parameters including the scale. All should be in scale of 1-10 (10 will be the most positive)",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 1.8
    },
    {
      "id": "ff7e0559-fc28-4be8-bf1b-492e4cbcb3f9",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1216,
        -272
      ],
      "parameters": {
        "color": 4,
        "width": 1300,
        "height": 320,
        "content": "=======================================\n            WORKFLOW ASSISTANCE\n=======================================\nFor any questions or support, please contact:\n    Yaron@nofluff.online\n\nExplore more tips and tutorials here:\n   - YouTube: https://www.youtube.com/@YaronBeen/videos\n   - LinkedIn: https://www.linkedin.com/in/yaronbeen/\n=======================================\n"
      },
      "typeVersion": 1
    },
    {
      "id": "d3cbada6-0cbe-42cb-b7a9-600bd1c1a567",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1216,
        96
      ],
      "parameters": {
        "color": 4,
        "width": 1289,
        "height": 2214,
        "content": "# Generate and Auto-Evaluate Facebook Ad Headlines using GPT-4o-mini\n\nBuilt with **n8n + OpenAI**\n\nThis workflow captures a product description, generates ad headlines, evaluates them with custom criteria, decides whether another draft is needed, and finally sends the best version via Gmail.\n\n---\n\n## \u26a1 Section 1: Capture the Brief & Build the Prompt\n\n* **\ud83d\udcdd FormTrigger\\_CopywritingBrief** \u2192 A simple form asks: *\u201cWhat is your product about?\u201d*\n* **\u2699\ufe0f Set\\_PromptForHeadline** \u2192 Prepares the input by appending the instruction:\n  *\u201cWrite a Facebook ad headline for this product:\u201d*\n\n**Benefit:** Ensures consistent, structured prompts so the AI receives clear context every time.\n\n---\n\n## \u270d\ufe0f Section 2: Draft the Headline\n\n* **\ud83d\udcac LLM\\_HeadlineWriterModel** \u2192 GPT-4o-mini model provides the intelligence.\n* **\u270d\ufe0f Agent\\_HeadlineWriter** \u2192 Generates a first-pass Facebook ad headline.\n\n**Benefit:** Produces creative copy instantly without waiting on a human writer.\n\n---\n\n## \ud83d\udccb Section 3: Define Scoring Criteria\n\n* **\ud83d\udcac LLM\\_EvalCriteriaModel** \u2192 Calls GPT-4o-mini again.\n* **\ud83d\udcd1 Agent\\_EvalCriteriaBuilder** \u2192 Suggests 5 scoring parameters (scale 1-10).\n  Example: Clarity, Relevance, Hook Strength, Brand Voice, Scroll-Stoppage.\n\n**Benefit:** Builds an objective, repeatable evaluation rubric automatically.\n\n---\n\n## \ud83d\udd0d Section 4: Evaluate the Headline\n\n* **\ud83d\udcac LLM\\_HeadlineEvaluatorModel** \u2192 Supplies reasoning power.\n* **\ud83d\udd0d Agent\\_HeadlineEvaluator** \u2192 Applies the 5 criteria to the generated headline and outputs:\n\n  * JSON with scores per parameter\n  * An average score\n  * A plain-language bottom-line\n\n**Benefit:** Turns subjective copy quality into measurable numbers.\n\n---\n\n## \ud83d\udd04 Section 5: Decide & Iterate (if needed)\n\n* **\ud83d\udcac LLM\\_BottomLineModel** \u2192 Interprets the evaluation results.\n* **\ud83e\udd14 Agent\\_IterationDecision** \u2192 Decides:\n\n  * Return **NO** \u2192 headline is acceptable.\n  * Return **YES** + feedback \u2192 headline should be rewritten.\n* **\ud83d\udd00 If\\_NeedMoreIterations** \u2192 Branches:\n\n  * If **NO** \u2192 continue workflow.\n  * If **YES** \u2192 (loop wiring possible) headline can be regenerated with feedback.\n\n**Benefit:** Keeps iterating until the AI headline meets your standards.\n\n---\n\n## \ud83d\udce9 Section 6: Deliver the Result\n\n* **\ud83d\udce7 Send a message (Gmail node)** \u2192 Sends the accepted headline via email.\n\n**Benefit:** Automates delivery of the polished, AI-approved headline to your inbox or team.\n\n---\n\n## \ud83d\udcca Workflow Overview\n\n| Section              | Purpose                            | Key Nodes                                             | Benefit                        |\n| -------------------- | ---------------------------------- | ----------------------------------------------------- | ------------------------------ |\n| \u26a1 Capture Brief      | Collect product info & prep prompt | FormTrigger, Set                                      | Structured AI input            |\n| \u270d\ufe0f Draft Headline    | Generate first headline            | LLM\\_HeadlineWriterModel, Agent\\_HeadlineWriter       | Instant creative draft         |\n| \ud83d\udccb Define Criteria   | Build scoring rubric               | LLM\\_EvalCriteriaModel, Agent\\_EvalCriteriaBuilder    | Objective evaluation           |\n| \ud83d\udd0d Evaluate Headline | Score headline & summarize         | LLM\\_HeadlineEvaluatorModel, Agent\\_HeadlineEvaluator | Transparent quality check      |\n| \ud83d\udd04 Decide & Iterate  | Accept or refine headline          | LLM\\_BottomLineModel, Agent\\_IterationDecision, If    | Only good results move forward |\n| \ud83d\udce9 Deliver Result    | Share the final copy               | Gmail                                                 | Automates delivery             |\n\n---\n\n## \u2705 Final Benefits\n\n* \ud83d\ude80 One-click workflow: from product description to tested headline.\n* \ud83d\udcca Automatic rubric: objective scoring each time.\n* \ud83d\udd04 Self-improving: poor headlines can auto-iterate with feedback.\n* \ud83d\udce7 Direct integration: approved headlines land in Gmail instantly.\n* \ud83e\udde9 Fully modular: easy to extend with Google Sheets, Slack, or CRM nodes.\n\n---\n\n"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "5f62337f-55ba-47a5-b3c4-0fe66cf02527",
  "connections": {
    "LLM_BottomLineModel": {
      "ai_languageModel": [
        [
          {
            "node": "Agent_IterationDecision",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Agent_HeadlineWriter": {
      "main": [
        [
          {
            "node": "Agent_EvalCriteriaBuilder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If_NeedMoreIterations": {
      "main": [
        [
          {
            "node": "Send a message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "LLM_EvalCriteriaModel": {
      "ai_languageModel": [
        [
          {
            "node": "Agent_EvalCriteriaBuilder",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Set_PromptForHeadline": {
      "main": [
        [
          {
            "node": "Agent_HeadlineWriter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Agent_HeadlineEvaluator": {
      "main": [
        [
          {
            "node": "Agent_IterationDecision",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Agent_IterationDecision": {
      "main": [
        [
          {
            "node": "If_NeedMoreIterations",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "LLM_HeadlineWriterModel": {
      "ai_languageModel": [
        [
          {
            "node": "Agent_HeadlineWriter",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Agent_EvalCriteriaBuilder": {
      "main": [
        [
          {
            "node": "Agent_HeadlineEvaluator",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "LLM_HeadlineEvaluatorModel": {
      "ai_languageModel": [
        [
          {
            "node": "Agent_HeadlineEvaluator",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "FormTrigger_CopywritingBrief": {
      "main": [
        [
          {
            "node": "Set_PromptForHeadline",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}