{
  "name": "LLM Council",
  "nodes": [
    {
      "parameters": {
        "modelId": {
          "__rl": true,
          "value": "models/gemini-pro-latest",
          "mode": "list",
          "cachedResultName": "models/gemini-pro-latest"
        },
        "messages": {
          "values": [
            {
              "content": "={{ $json.user_prompt }}"
            }
          ]
        },
        "builtInTools": {
          "googleSearch": true
        },
        "options": {
          "systemMessage": "={{ $json.system_prompt }}"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "typeVersion": 1.1,
      "position": [
        -256,
        -336
      ],
      "id": "0be5bf57-3970-45ad-afe9-57ba6f3f5c12",
      "name": "Gemini",
      "retryOnFail": true,
      "credentials": {
        "googlePalmApi": {}
      }
    },
    {
      "parameters": {
        "fieldsToAggregate": {
          "fieldToAggregate": [
            {
              "fieldToAggregate": "text"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.aggregate",
      "typeVersion": 1,
      "position": [
        320,
        -336
      ],
      "id": "036d8b5a-3a54-4bf8-a3a2-b9159d152c9d",
      "name": "Aggregate"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "38c33cf0-4af4-4c64-a108-c2dc0749224c",
              "name": "system_prompt",
              "value": "={{ $('Start').item.json.system_prompt }}",
              "type": "string"
            },
            {
              "id": "66133cfe-68f6-4087-a051-83469bed2fe3",
              "name": "user_prompt",
              "value": "={{ $('Start').item.json.user_prompt }}",
              "type": "string"
            },
            {
              "id": "d03fdfea-ff59-4855-a41f-1e9be5381bf5",
              "name": "model",
              "value": "={{ $('Gemini').params.modelId.cachedResultName }}",
              "type": "string"
            },
            {
              "id": "38902551-56ab-4135-8540-2376f7d4282d",
              "name": "output",
              "value": "={{ $json.text.join(\"\\n\") }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        544,
        -336
      ],
      "id": "694129b6-1fd5-4531-bd29-925a42ddea6d",
      "name": "Gemini Output"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "02a12f71-9668-48da-bf13-dcf907f277c0",
              "name": "system_prompt_scoring",
              "value": "=Du bist ein Bewertungsassistent. \nZu einem System- und Userprompt gibt es verschiedene Outputs. \nDu sollst jeden Output mit einem Score von 0.0 (sehr schlecht) bis 1.0 (sehr gut) bewerten.\nIch erwarte eine Antwort als JSON : [score_0, score_1, ...]\nGib bitte das reine JSON ohne irgendetwas dazu aus.",
              "type": "string"
            },
            {
              "id": "9c4f2bbb-e638-4c88-801b-1fe934faaac5",
              "name": "user_prompt_scoring",
              "value": "={\n  \"system_prompt\": \"{{ $('Start').item.json.system_prompt }}\",\n  \"user_prompt\": \"{{ $('Start').item.json.user_prompt }}\",\n  \"output\": {{ JSON.stringify($json.output) }}\n}",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1216,
        -432
      ],
      "id": "c48cb006-a56f-41e8-99f7-9e251ae8d9dd",
      "name": "Scoring Prompt"
    },
    {
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Gemini').params.modelId.value }}"
        },
        "messages": {
          "values": [
            {
              "content": "={{ $json.system_prompt_scoring }}",
              "role": "model"
            },
            {
              "content": "={{ $json.user_prompt_scoring }}"
            }
          ]
        },
        "builtInTools": {
          "googleSearch": true
        },
        "options": {
          "systemMessage": "={{ $json.system_prompt_scoring }}"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "typeVersion": 1.1,
      "position": [
        1440,
        -336
      ],
      "id": "ccf70691-d67e-4871-94a2-fabba2c93021",
      "name": "Gemini Scorer",
      "retryOnFail": true,
      "credentials": {
        "googlePalmApi": {}
      }
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "position": [
        2016,
        -432
      ],
      "id": "7655cd63-e0b3-4ba3-9edc-3b32dc916121",
      "name": "Merge Scores"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "99ac887f-f7c8-483a-b3b7-7af90a4bc028",
              "name": "system_prompt",
              "value": "={{ $('Scoring Prompt').item.json.system_prompt }}",
              "type": "string"
            },
            {
              "id": "0e91128b-0a1a-4cb8-9e47-6c6da1732f0d",
              "name": "user_prompt",
              "value": "={{ $('Scoring Prompt').item.json.user_prompt }}",
              "type": "string"
            },
            {
              "id": "72934923-c55f-469b-83e8-cec377a16ab5",
              "name": "model",
              "value": "={{ $('Scoring Prompt').item.json.model }}",
              "type": "array"
            },
            {
              "id": "05b1c813-8a48-4582-a9a2-4dffe43384ef",
              "name": "output",
              "value": "={{ $('Scoring Prompt').item.json.output }}",
              "type": "array"
            },
            {
              "id": "d051abc4-0f8b-437f-8061-194213f086c5",
              "name": "system_prompt_scoring",
              "value": "={{ $('Scoring Prompt').item.json.system_prompt_scoring }}",
              "type": "string"
            },
            {
              "id": "d0f016f8-3417-405a-9a07-0954b2c1fac6",
              "name": "user_prompt_scoring",
              "value": "={{ $('Scoring Prompt').item.json.user_prompt_scoring }}",
              "type": "string"
            },
            {
              "id": "a26dd7c3-d3ef-4e74-a82f-6571d62f0cf9",
              "name": "scores",
              "value": "={{ JSON.parse($json.content.parts[0].text.replace(\"```json\", \"\").replace(\"```\", \"\").trim()) }}",
              "type": "array"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1792,
        -336
      ],
      "id": "2a798777-54e2-43ee-a77c-788683f4deff",
      "name": "parse score from Gemini"
    },
    {
      "parameters": {
        "fieldToSplitOut": "content.parts",
        "options": {}
      },
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        96,
        -336
      ],
      "id": "8213fb6d-c93f-47d5-9dbd-fdfde093b8bd",
      "name": "Split Gemini output"
    },
    {
      "parameters": {
        "workflowInputs": {
          "values": [
            {
              "name": "system_prompt"
            },
            {
              "name": "user_prompt"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1.1,
      "position": [
        -704,
        -432
      ],
      "id": "8be80bd3-86b9-4b41-99ab-5b9d91e60ce7",
      "name": "Start"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "position": [
        768,
        -432
      ],
      "id": "56ccc5f7-4f37-42c6-a7e1-c5842ceb1b04",
      "name": "Merge Output"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "19eef0d1-2ceb-4782-bcd8-98144e0e9490",
              "name": "=model",
              "value": "={{ $json.test_dummy }}",
              "type": "string"
            },
            {
              "id": "d4a41b20-e1ec-4a67-8d5c-85ce53c1c0db",
              "name": "output",
              "value": "={{ \"\" }}",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.5,
      "position": [
        544,
        -528
      ],
      "id": "909b3c5a-b11e-49aa-96f0-c09f06aa58d6",
      "name": "test dummy"
    },
    {
      "parameters": {
        "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nfor (const item of $input.all()) {\n  const dummy_model = item.json.test_dummy;\n  const scores = [];\n  scores.length = item.json.model.length;\n  \n  item.json.model.forEach((model, i) => {\n    scores[i] = model === dummy_model ? 0 : 1;\n  })\n  \n  item.json.scores = scores;\n}\n\nreturn $input.all();"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1792,
        -528
      ],
      "id": "e3a6dcb3-81ae-4579-bb76-376dc27a051e",
      "name": "test dummy scoring"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "b9489d27-90ff-4e67-b4b4-7fc3153e960e",
              "name": "test_dummy",
              "value": "dummy",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.5,
      "position": [
        -480,
        -432
      ],
      "id": "a74f39d0-3b35-4ffa-a4cb-848a86007da5",
      "name": "Variables"
    },
    {
      "parameters": {
        "jsCode": "\nconst items = [];\nconst input = $input.all();\n\nconst empty = (item) => {\n  return item.json.model === null\n      || item.json.output === null;\n}\n\nconst pair = (item1, item2) => {\n  return item1.json.system_prompt === item2.json.system_prompt\n    && item1.json.user_prompt === item2.json.user_prompt\n    && !empty(item2);\n}\n\nfor (let index1 = 0; index1 < input.length; ++index1) {\n  const item1 = input[index1];\n  if (empty(item1)) {\n    continue;\n  }\n  item1.json.model = [item1.json.model];\n  item1.json.output = [item1.json.output];\n  items.push(item1);\n  for (let index2 = index1 + 1; index2 < input.length; ++index2) {\n    const item2 = input[index2];\n    if (!pair(item1, item2)) {\n      continue;\n    }\n    item1.json.model.push(item2.json.model);\n    item1.json.output.push(item2.json.output);\n\n    item2.json = {...item2.json, \"model\": null, \"output\": null};\n  }\n}\n\nreturn items;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        992,
        -432
      ],
      "id": "98a83dc4-b9a8-42d3-9bcb-ba8a7cc423c1",
      "name": "Aggregate model and output"
    },
    {
      "parameters": {
        "jsCode": "const items = [];\nconst input = $input.all();\n\nconst empty = (item) => {\n  return item.json.model === null\n      || item.json.output === null\n      || item.json.scores === null;\n}\n\nconst pair = (item1, item2) => {\n  return item1.json.system_prompt === item2.json.system_prompt\n    && item1.json.user_prompt === item2.json.user_prompt\n    && !empty(item2);\n}\n\n\nfor (let index1 = 0; index1 < input.length; ++index1) {\n  const item1 = input[index1];\n  if (empty(item1)) {\n    continue;\n  }\n\n  items.push(item1);\n  for (let index2 = index1 + 1; index2 < input.length; ++index2) {\n    const item2 = input[index2];\n    if (!pair(item1, item2)) {\n      continue;\n    }\n\n    for (let index = 0; index < item1.json.scores.length; ++index) {\n      item1.json.scores[index] += item2.json.scores[index];\n    }\n\n    item2.json = {...item2.json, \"model\": null, \"output\": null, \"scores\": null};\n  }\n  \n}\n\nitems.forEach(item => {\n  item.json.scores = item.json.scores.map((v, i, all) => v / all.length);\n});\n\nreturn items;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2240,
        -432
      ],
      "id": "0dc0cca5-4d28-4e7d-a0ca-4acb0b39bc2a",
      "name": "Compute scores"
    },
    {
      "parameters": {
        "jsCode": "\nfor (const item of $input.all()) {\n  const scores = item.json.scores;\n  const max_index = scores.reduce((max_index, score, index, scores) => {\n    if (index === 0) {\n      return 0;\n    }\n    const max_score = scores[max_index];\n    \n    return score > max_score ? index : max_index;\n  });\n\n  item.json = {\n    \"system_prompt\": $input.first().json.system_prompt,\n    \"user_prompt\": $input.first().json.user_prompt,\n    \"output\": item.json.output[max_index],\n    \"model\": item.json.model[max_index],\n    \"score\": item.json.scores[max_index]\n  }\n}\n\nreturn $input.all();"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2464,
        -432
      ],
      "id": "eb6aadd7-a6e7-4fa1-ba18-5a0d4f516d02",
      "name": "return best result"
    }
  ],
  "pinData": {},
  "connections": {
    "Gemini": {
      "main": [
        [
          {
            "node": "Split Gemini output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate": {
      "main": [
        [
          {
            "node": "Gemini Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gemini Output": {
      "main": [
        [
          {
            "node": "Merge Output",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Scoring Prompt": {
      "main": [
        [
          {
            "node": "Gemini Scorer",
            "type": "main",
            "index": 0
          },
          {
            "node": "test dummy scoring",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gemini Scorer": {
      "main": [
        [
          {
            "node": "parse score from Gemini",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Scores": {
      "main": [
        [
          {
            "node": "Compute scores",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "parse score from Gemini": {
      "main": [
        [
          {
            "node": "Merge Scores",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Split Gemini output": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Start": {
      "main": [
        [
          {
            "node": "Variables",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Output": {
      "main": [
        [
          {
            "node": "Aggregate model and output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "test dummy": {
      "main": [
        [
          {
            "node": "Merge Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "test dummy scoring": {
      "main": [
        [
          {
            "node": "Merge Scores",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Variables": {
      "main": [
        [
          {
            "node": "test dummy",
            "type": "main",
            "index": 0
          },
          {
            "node": "Gemini",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate model and output": {
      "main": [
        [
          {
            "node": "Scoring Prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Compute scores": {
      "main": [
        [
          {
            "node": "return best result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "availableInMCP": false,
    "timeSavedMode": "fixed",
    "errorWorkflow": "ZgRERlb7YOFD2Fgh",
    "timezone": "Europe/Berlin",
    "callerPolicy": "workflowsFromSameOwner"
  },
  "versionId": "25169260-8405-4968-aa6a-ba620592596e",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "dd55c636a6af52dda22aa424fe424e1cb9469e4dc4ef9144fc48554c03d56158"
  },
  "nodeGroups": [],
  "id": "0MK6Rte48EYnbvGBqivuE",
  "tags": [
    {
      "updatedAt": "2026-02-11T10:02:57.643Z",
      "createdAt": "2026-02-11T10:02:57.643Z",
      "id": "XmmbE9qqu5eRxRGV",
      "name": "Subflow"
    },
    {
      "updatedAt": "2026-01-30T10:59:10.142Z",
      "createdAt": "2026-01-30T10:59:10.142Z",
      "id": "hovbDxVxuy7qshmh",
      "name": "LLM"
    }
  ]
}