{
  "id": "abHolidayReview1",
  "name": "AgentsBench UK bank holiday assistant",
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "nodes": [
    {
      "name": "When you click Execute Workflow",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        100
      ],
      "parameters": {},
      "id": "1d62cf7a-7ae4-422a-a4dc-4f73739ae672"
    },
    {
      "name": "Enter questions",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        220,
        100
      ],
      "parameters": {
        "jsCode": "// Replace or add questions here. For a lookup, use one region and a date in YYYY-MM-DD form.\nconst questions = [\n  [\n    \"scotland-nov30\",\n    \"Is 2026-11-30 a bank holiday in Scotland?\"\n  ],\n  [\n    \"england-nov30\",\n    \"Does England and Wales list a bank holiday on 2026-11-30?\"\n  ],\n  [\n    \"northern-ireland-mar17\",\n    \"Is 2026-03-17 a bank holiday in Northern Ireland?\"\n  ],\n  [\n    \"boxing-day\",\n    \"Is there a bank holiday in England and Wales on 2026-12-28?\"\n  ],\n  [\n    \"scotland-aug31\",\n    \"Is 2026-08-31 a bank holiday in Scotland?\"\n  ],\n  [\n    \"england-aug31\",\n    \"Does England and Wales list a bank holiday on 2026-08-31?\"\n  ],\n  [\n    \"office\",\n    \"Will our Scotland office be open on 2026-11-30?\"\n  ],\n  [\n    \"out-of-range\",\n    \"Is 2099-02-05 a bank holiday in Scotland?\"\n  ],\n  [\n    \"missing-region\",\n    \"Is 2026-11-30 a bank holiday?\"\n  ],\n  [\n    \"ambiguous-date\",\n    \"Is 03/04/2026 a bank holiday in England?\"\n  ]\n];\nconst endpoint = \"http://127.0.0.1:11434/v1/chat/completions\";\nconst model = \"qwen2.5:1.5b\";\nconst instruction = \"Classify the question into exactly one label: HOLIDAY, OFFICE, OTHER. HOLIDAY asks if a day is an official bank or public holiday or asks for its name. OFFICE asks about the opening hours or closing of an employer, office, shop, or location. A missing date or region does not change the label. Answer with the label only. Example \\\"Is this a bank holiday?\\\" = HOLIDAY. Example \\\"Is our office open?\\\" = OFFICE.\";\nreturn questions.map(([id,question]) => ({json:{id,question,endpoint,model,instruction}}));"
      },
      "id": "d5ccee06-2589-408a-8e22-f0639dcc026a"
    },
    {
      "name": "Route with the local model",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        440,
        100
      ],
      "parameters": {
        "method": "POST",
        "url": "={{ $json.endpoint }}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ {model: $json.model, messages: [{role: \"system\", content: $json.instruction}, {role: \"user\", content: $json.question}], temperature: 0, max_tokens: 12, stream: false} }}",
        "options": {
          "timeout": 30000
        }
      },
      "id": "fe138d0c-3cf1-4710-86c1-668b2ea3723d",
      "onError": "continueRegularOutput"
    },
    {
      "name": "Validate date and region",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        660,
        100
      ],
      "parameters": {
        "jsCode": "\nconst original = $('Enter questions').all();\nconst regions = [\n  ['northern-ireland', /\\bnorthern ireland\\b/i],\n  ['scotland', /\\bscotland\\b/i],\n  ['england-and-wales', /\\b(?:england|wales)\\b/i],\n];\nreturn $input.all().map((entry,index) => {\n  const item = original[index].json;\n  const raw = entry.json.choices?.[0]?.message?.content;\n  const route = typeof raw === 'string' ? raw.trim().toUpperCase() : '';\n  const base = {id:item.id,question:item.question,route};\n  const answer = (status,message) => ({json:{...base,lookup:false,status,message},pairedItem:{item:index}});\n  if (route === 'OFFICE') return answer('need_office_schedule','Check the office schedule or ask its owner about opening hours.');\n  if (route === 'OTHER') return answer('unsupported','I can check a published UK bank holiday.');\n  if (route !== 'HOLIDAY') return answer('router_unavailable','The routing model did not return a usable decision.');\n  const matches = regions.filter(([,pattern]) => pattern.test(item.question));\n  if (matches.length !== 1) return answer('ask_region','Which division should I use: England and Wales, Scotland, or Northern Ireland?');\n  const dates = item.question.match(/\\b\\d{4}-\\d{2}-\\d{2}\\b/g) || [];\n  if (dates.length !== 1) return answer('ask_date','What date should I check? Please use YYYY-MM-DD.');\n  const date = dates[0];\n  const parsed = new Date(date+'T00:00:00Z');\n  if (!Number.isFinite(parsed.valueOf()) || parsed.toISOString().slice(0,10) !== date) {\n    return answer('ask_date','Please give a real calendar date in YYYY-MM-DD form.');\n  }\n  return {json:{...base,lookup:true,division:matches[0][0],date},pairedItem:{item:index}};\n});\n"
      },
      "id": "754f82c9-0157-4073-bc4b-bc5081020131"
    },
    {
      "name": "Read the calendar?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        880,
        100
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "9fe63714-1e8f-4467-ae92-a85d9a3e7fd9",
              "leftValue": "={{ $json.lookup }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "d0ce2ba1-8dad-4c01-bf53-d83a9b671bed"
    },
    {
      "name": "Fetch GOV.UK calendar",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1100,
        0
      ],
      "parameters": {
        "url": "https://www.gov.uk/bank-holidays.json",
        "options": {
          "timeout": 15000
        }
      },
      "id": "97189673-6a47-4cf8-9f23-4fead7ef824e",
      "onError": "continueRegularOutput"
    },
    {
      "name": "Return calendar results",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1320,
        0
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "\nconst request = $('Validate date and region').item.json;\nconst source = 'https://www.gov.uk/bank-holidays';\nconst events = $json[request.division]?.events;\nconst response = (status, extra = {}) => ({json:{...request,status,source,...extra}});\nif (!Array.isArray(events) || !events.length || events.some(event => !event.date || !event.title)) {\n  return response('source_unavailable',{message:'I could not check the official calendar.'});\n}\nconst dates = events.map(event => event.date).sort();\nconst coverage = {from:dates[0],through:dates[dates.length-1]};\nif (request.date < coverage.from || request.date > coverage.through) {\n  return response('outside_coverage',{coverage,message:'The published entries do not cover that date.'});\n}\nconst found = events.find(event => event.date === request.date);\nif (found) return response('listed',{coverage,title:found.title,notes:found.notes || ''});\nreturn response('not_listed',{coverage,message:'The published calendar lists no bank holiday for that date in this division.'});\n"
      },
      "id": "b0993932-58a5-4514-85e9-f143e43b6faa"
    },
    {
      "name": "Return clarification or scope",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1100,
        230
      ],
      "parameters": {
        "jsCode": "return $input.all();"
      },
      "id": "9e041aae-9167-43df-8982-9f6f7e9d25d2"
    }
  ],
  "connections": {
    "When you click Execute Workflow": {
      "main": [
        [
          {
            "node": "Enter questions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Enter questions": {
      "main": [
        [
          {
            "node": "Route with the local model",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route with the local model": {
      "main": [
        [
          {
            "node": "Validate date and region",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate date and region": {
      "main": [
        [
          {
            "node": "Read the calendar?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch GOV.UK calendar": {
      "main": [
        [
          {
            "node": "Return calendar results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read the calendar?": {
      "main": [
        [
          {
            "node": "Fetch GOV.UK calendar",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Return clarification or scope",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
