{
  "name": "Evaluation Agent",
  "nodes": [
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "typeVersion": 1.4,
      "position": [
        -16,
        320
      ],
      "id": "19d1414f-c4a3-4070-9b1d-e0c91c915803",
      "name": "When chat message received",
      "retryOnFail": true
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-5-mini"
        },
        "builtInTools": {},
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        288,
        544
      ],
      "id": "871d0a91-57bc-47cd-97e3-5edd48c8e434",
      "name": "OpenAI Chat Model"
    },
    {
      "parameters": {
        "resource": "audio",
        "input": "={{ $json.output }}",
        "voice": "onyx",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 2.1,
      "position": [
        -16,
        -16
      ],
      "id": "37b04567-8215-4225-b366-aa9645a7d22c",
      "name": "Generate audio"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-5-mini"
        },
        "builtInTools": {},
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        640,
        544
      ],
      "id": "7fc23f7c-5513-40b4-8401-9d437d959852",
      "name": "OpenAI Chat Model1"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-5-mini"
        },
        "builtInTools": {},
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        992,
        544
      ],
      "id": "0f1288ce-a965-4fb2-b4f9-b6d9c6c3df17",
      "name": "OpenAI Chat Model2"
    },
    {
      "parameters": {
        "options": {
          "systemMessage": "You are writing for a brand whose voice is:\n\n**System Role:** You are an expert Marketing Strategist at MMA Global (Marketing + Media Alliance). Your goal is to generate advertising messages that are evidence-based, high-impact, and designed to drive measurable enterprise value.\n\n**Guiding Principles:**\n1. **Focus on Growth:** Every message must tie back to business outcomes (ROI, ROAS, or enterprise value). Avoid \"fluff\" or storytelling for its own sake.\n2. **The \"Movable Middle\" Logic:** When applicable, target the \"Movable Middle\"\u2014audience segments where the brand has the highest potential to change behavior and maximize return.\n3. **Scientific Tone:** Maintain an authoritative yet collaborative tone. Use language that suggests rigor, precision, and proven results (e.g., \"validated,\" \"framework-driven,\" \"attribution-ready\").\n4. **Technology Integration:** Position AI and MarTech as strategic enablers of better consumer engagement, not just as shiny new tools.\n5. **Brand as Performance:** Ensure messages acknowledge that brand-building is a performance driver. Balance emotional resonance with a clear path to action.\n6. **Integrity & Privacy:** All messaging must reflect a \"privacy-first\" mindset, prioritizing consumer trust and brand suitability.\n\n**Constraint:** Be concise and precise. Avoid sycophantic language. Stick to the facts and the data-driven potential of the marketing action."
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [
        208,
        320
      ],
      "id": "91a19017-adc4-41ad-b060-b3de9f9558af",
      "name": "Ad Director Agent"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.output }}",
        "options": {
          "systemMessage": "Your role is to extract the voiceover script from the prompt. Output only the voiceover script. Nothing more."
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [
        560,
        320
      ],
      "id": "a38a6ff5-e3de-4535-a940-50f30dbc4b45",
      "name": "Voice over Agent"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.output }}",
        "options": {
          "systemMessage": "Grade the output in relation to the brand guidelines (see below) and goals for a 10 second or less audio advertising script. IMPORTANT: Use a letter grade (A through F). Output the Letter grade first and label it with this format: \"Grade: X\" where X is the letter grade you assign.\n\n#Brand Guidelines\nYou are writing for a brand whose voice is authoritative, modern, evidence-based, and growth-oriented. The brand exists to help senior marketing leaders create value, drive business growth, and navigate transformation with confidence. Its tone is executive, clear, credible, and intellectually serious.\n\nWhen generating advertising messages:\n- Write for senior marketers, business leaders, and decision-makers.\n- Emphasize value creation, business impact, practical outcomes, and confidence.\n- Sound research-backed, strategic, and useful rather than flashy or hype-driven.\n- Use concise, strong language with clear points and a modern, forward-looking tone.\n- Reflect a collaborative, ecosystem-wide perspective across marketing, media, data, AI, measurement, and organizational leadership.\n- Position the brand as a trusted guide that helps solve hard marketing problems.\n\nAvoid:\n- Empty buzzwords\n- Overly casual or consumer-y language\n- Exaggerated claims without substance\n- Generic \u201cinnovation\u201d language with no business relevance\n- Cleverness that undermines clarity or credibility\n\nDefault style:\nconfident, sharp, practical, executive, future-facing, and grounded in real-world marketing effectiveness."
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [
        912,
        320
      ],
      "id": "2a69a296-9529-4db9-b39d-63da61917629",
      "name": "Evaluation Agent"
    },
    {
      "parameters": {
        "jsCode": "// Extract letter grade from Evaluation Agent output\nfor (const item of $input.all()) {\n  const output = item.json.output || '';\n  \n  // Use regex to find 'Grade: X' pattern where X is the letter grade\n  const gradeMatch = output.match(/Grade:\\s*([A-F][+-]?)/i);\n  \n  // Extract the grade or set to 'Not Found' if pattern doesn't match\n  item.json.letterGrade = gradeMatch ? gradeMatch[1].toUpperCase() : 'Not Found';\n  \n  // Also keep the full evaluation for reference\n  item.json.fullEvaluation = output;\n}\n\nreturn $input.all();"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1264,
        320
      ],
      "id": "f72e21d4-61f5-40d2-a02e-c0a2de34ab5f",
      "name": "Code in JavaScript"
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "YOUR_GOOGLE_SHEET_ID",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "Sheet1",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Evaluation": "={{ $json.letterGrade }}",
            "Ouput": "={{ $('Voice over Agent').item.json.output }}",
            "Prompt": "={{ $('When chat message received').item.json.chatInput }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Prompt",
              "displayName": "Prompt",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Ouput",
              "displayName": "Ouput",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Evaluation",
              "displayName": "Evaluation",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        1456,
        320
      ],
      "id": "7a560c1b-2c30-4054-9487-6f5cb039bcb9",
      "name": "Append row in sheet"
    }
  ],
  "pinData": {},
  "connections": {
    "When chat message received": {
      "main": [
        [
          {
            "node": "Ad Director Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Ad Director Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "Voice over Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model2": {
      "ai_languageModel": [
        [
          {
            "node": "Evaluation Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Ad Director Agent": {
      "main": [
        [
          {
            "node": "Voice over Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Voice over Agent": {
      "main": [
        [
          {
            "node": "Evaluation Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Evaluation Agent": {
      "main": [
        [
          {
            "node": "Code in JavaScript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript": {
      "main": [
        [
          {
            "node": "Append row in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "availableInMCP": false
  },
  "tags": []
}