{
  "name": "Automatically optimize AI prompts with OpenAI using OPRO & DSPy methodology",
  "nodes": [
    {
      "id": "0ce67220-10c9-4084-8ec4-aea6df878e63",
      "name": "Sticky Note Main",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2048,
        -432
      ],
      "parameters": {
        "width": 528,
        "height": 660,
        "content": "## Auto-Optimize Prompts (OPRO/DSPy Implementation)\n\nThis workflow implements cutting-edge concepts from **Google DeepMind's OPRO** and **Stanford's DSPy** to automatically refine AI prompts.\n\n## Why "
      }
    },
    {
      "id": "7c651fda-e903-4d5e-b05f-5be23acf49d8",
      "name": "Sticky Note Init",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1504,
        -432
      ],
      "parameters": {
        "width": 494,
        "height": 656,
        "content": "## 1. Initialization\nDefine the starting prompt and the test case.\n\nExample: Invoice Data Extraction"
      }
    },
    {
      "id": "5d2b7a89-6415-41b6-94a8-3e77f1eb7703",
      "name": "Sticky Note Gen Eval",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -496,
        -432
      ],
      "parameters": {
        "width": 708,
        "height": 640,
        "content": "## 2. Generation & Evaluation\nGenerate response and score it against ground truth."
      }
    },
    {
      "id": "95c31df9-4ffe-46ea-a06c-a53e21b81f82",
      "name": "Sticky Note Opt",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        240,
        -432
      ],
      "parameters": {
        "width": 516,
        "height": 640,
        "content": "## 3. Optimization Loop\nAnalyze results and improve the prompt if needed."
      }
    },
    {
      "id": "167addf3-7815-4c26-8fab-f3e523894bf7",
      "name": "When clicking ‘Execute workflow’",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -1440,
        -160
      ]
    },
    {
      "id": "9519a48a-e021-4552-908e-ef5973b784cd",
      "name": "Define Initial Prompt & Test Data",
      "type": "n8n-nodes-base.set",
      "position": [
        -1216,
        -160
      ]
    },
    {
      "id": "55fcf4d8-9209-4c61-8f2c-bfbe070bccc0",
      "name": "AI Prompt Optimizer",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        256,
        -256
      ]
    },
    {
      "id": "b6ac0833-f4fe-4f66-9dbe-77bf99844b6c",
      "name": "AI Response Evaluator",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -96,
        -256
      ]
    },
    {
      "id": "98670d2b-e4eb-4181-aa06-5a16aea57ebc",
      "name": "Manage Loop & State",
      "type": "n8n-nodes-base.code",
      "position": [
        -928,
        -368
      ]
    },
    {
      "id": "de205d99-043f-4d91-94b0-64820be376e6",
      "name": "AI Response Generator",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -448,
        -256
      ]
    },
    {
      "id": "de86fe42-e5f2-4b91-96e0-31d763579b98",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -368,
        -32
      ]
    },
    {
      "id": "9746cbd5-283a-4f3f-ad21-6cb96f1243af",
      "name": "Check Loop Condition",
      "type": "n8n-nodes-base.if",
      "position": [
        -752,
        -368
      ]
    },
    {
      "id": "77d542df-3380-4dbe-9f64-a871f3053145",
      "name": "End Loop",
      "type": "n8n-nodes-base.noOp",
      "position": [
        -480,
        -752
      ]
    },
    {
      "id": "4f1e33e3-5b62-4262-afc8-45020f92337b",
      "name": "Evaluator Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        -16,
        -32
      ]
    },
    {
      "id": "24716665-625b-4507-8e19-be973cccb81d",
      "name": "Optimizer Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        336,
        -32
      ]
    },
    {
      "id": "d83ce8ae-70ed-40ef-b989-bb29a8663b82",
      "name": "Update Prompt & Loop Count",
      "type": "n8n-nodes-base.set",
      "position": [
        592,
        -48
      ]
    }
  ],
  "connections": {
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Prompt Optimizer",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "AI Response Evaluator",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "AI Response Generator",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "AI Prompt Optimizer": {
      "main": [
        [
          {
            "node": "Update Prompt & Loop Count",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Manage Loop & State": {
      "main": [
        [
          {
            "node": "Check Loop Condition",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Loop Condition": {
      "main": [
        [
          {
            "node": "End Loop",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "AI Response Generator",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Response Evaluator": {
      "main": [
        [
          {
            "node": "AI Prompt Optimizer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Response Generator": {
      "main": [
        [
          {
            "node": "AI Response Evaluator",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Evaluator Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "AI Response Evaluator",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Optimizer Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "AI Prompt Optimizer",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Update Prompt & Loop Count": {
      "main": [
        [
          {
            "node": "Manage Loop & State",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Define Initial Prompt & Test Data": {
      "main": [
        [
          {
            "node": "Manage Loop & State",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking ‘Execute workflow’": {
      "main": [
        [
          {
            "node": "Define Initial Prompt & Test Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}