{
  "name": "Code-Orch_Agent",
  "nodes": [
    {
      "parameters": {
        "public": true,
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "typeVersion": 1.1,
      "position": [
        -280,
        -140
      ],
      "id": "bfa33772-f937-493d-8417-2c1977fd07e5",
      "name": "When chat message received"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4.1",
          "mode": "list",
          "cachedResultName": "gpt-4.1"
        },
        "options": {
          "temperature": 0.4
        }
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        100,
        20
      ],
      "id": "4d360ea0-22d5-4cb3-b644-fe20b9fd42d9",
      "name": "OpenAI Chat Model",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "tableName": "orch_agent_history"
      },
      "type": "@n8n/n8n-nodes-langchain.memoryPostgresChat",
      "typeVersion": 1.3,
      "position": [
        200,
        20
      ],
      "id": "d2568835-8289-4b15-bd44-969554cecaa4",
      "name": "Postgres Chat Memory",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "description": "=Call this tool to answer questions about the **B \u2013 Stability & Durability** \u2014ensuring that buildings, elements, and site-works remain structurally sound under self-weight, temperature, water, earthquake, snow, wind, and fire loads during construction, alteration, and service life, and that chosen materials stay functional for no less than 50, 15, or 5 years so the building continues to protect people and property.\n\nIf the question is *not* about the NZ Building Code, reply: \"Out of scope \u2013 NZ Building Code only.\"\n\nIf you can not answer the query from retrieved documents, reply: \"I dont know.\"",
        "workflowId": {
          "__rl": true,
          "value": "RoIksA8jto3Vgg8S",
          "mode": "list",
          "cachedResultName": "Code-B Agent"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {},
          "matchingColumns": [],
          "schema": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "typeVersion": 2.2,
      "position": [
        2260,
        500
      ],
      "id": "7f790e33-b45f-48da-8b09-3b6f8757abfe",
      "name": "code-b-agent"
    },
    {
      "parameters": {
        "description": "=Call this tool to answer questions about the Building Code\u2019s **C Protection from Fire** provisions\u2014Clauses **C1 to C6**, which together address:\n\n* **Preventing fires from starting (C2)**\n* **Limiting fire spread beyond the source (C3)**\n* **Ensuring safe movement to a place of safety for occupants (C4)**\n* **Providing access and safety for firefighting and rescue operations (C5)**\n* **Maintaining structural stability during fire (C6)**\n\nThese clauses aim to let building users evacuate safely, protect firefighters and rescuers, and restrict the extent and effects of fire so people and property remain safeguarded.\n\nIf the question is *not* about the NZ Building Code, reply: \"Out of scope \u2013 NZ Building Code only.\"\n\nIf you can not answer the query from retrieved documents, reply: \"I dont know.\"",
        "workflowId": {
          "__rl": true,
          "value": "P9D4MZDPUZQEu57I",
          "mode": "list",
          "cachedResultName": "Code-C Agent"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {},
          "matchingColumns": [],
          "schema": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "typeVersion": 2.2,
      "position": [
        1700,
        500
      ],
      "id": "19932798-9c38-4ead-8ed9-4d66c9743759",
      "name": "code-c-agent"
    },
    {
      "parameters": {
        "description": "=Call this tool to answer questions about the Building Code\u2019s **D Access** provisions\u2014Clauses **D1 Access routes** and **D2 Mechanical installations for access**\u2014which together ensure that:\n\n* **Safe movement** is possible into, within, and out of buildings via approaches, corridors, doors, stairs, ramps, lifts, and other access routes.\n* **People with disabilities** can carry out normal activities and functions throughout a building.\n* **Access routes** meet requirements for slip resistance, stair-tread geometry, handrails, cross-falls, and the movement, loading, and parking of vehicles.\n* **Mechanical installations** such as lifts, escalators, platform lifts, and moving walks are designed to resist normal service loads, prevent accidents and injuries, and safeguard users and maintenance personnel during overloads or emergencies.\n\nUse these clauses to verify compliance pathways and performance expectations for all features that enable safe, inclusive access in New Zealand buildings.\n\nIf the question is *not* about the NZ Building Code, reply: \"Out of scope \u2013 NZ Building Code only.\"\n\nIf you can not answer the query from retrieved documents, reply: \"I dont know.\"",
        "workflowId": {
          "__rl": true,
          "value": "iNUM5SPOqrpUKjoN",
          "mode": "list",
          "cachedResultName": "Code-D Agent"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {},
          "matchingColumns": [],
          "schema": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "typeVersion": 2.2,
      "position": [
        1140,
        500
      ],
      "id": "33a24ade-8d28-46de-81a4-94cea34de9fb",
      "name": "code-d-agent"
    },
    {
      "parameters": {
        "description": "=Call this tool to answer questions about the Building Code\u2019s **E Moisture** provisions\u2014Clauses **E1 Surface water, E2 External moisture, and E3 Internal moisture**\u2014which together ensure buildings manage water so they remain healthy, safe, and durable. These clauses protect people and property from undue dampness, structural damage, condensation, and fungal growth by requiring:\n\n* **E1 Surface water** \u2013 Site-work and drainage systems that dispose of rainwater by gravity where possible, preventing surface-water entry, leakage, and blockages.\n* **E2 External moisture** \u2013 Roofs, wall claddings, and external openings that resist water penetration, absorption, and accumulation while allowing dissipation to avoid dampness or damage.\n* **E3 Internal moisture** \u2013 Habitable spaces, bathrooms, laundries, and similar areas with impervious, easy-clean surfaces, adequate ventilation, thermal resistance, space temperature control, and overflow-water disposal to prevent excess moisture and fungal growth.\n\n\nIf the question is *not* about the NZ Building Code, reply: \"Out of scope \u2013 NZ Building Code only.\"\n\nIf you can not answer the query from retrieved documents, reply: \"I dont know.\"",
        "workflowId": {
          "__rl": true,
          "value": "8HASDl63WCAVQuFd",
          "mode": "list",
          "cachedResultName": "Code-E Agent"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {},
          "matchingColumns": [],
          "schema": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "typeVersion": 2.2,
      "position": [
        580,
        500
      ],
      "id": "0fc767ec-f363-49f6-9360-656bc3c910f7",
      "name": "code-e-agent"
    },
    {
      "parameters": {
        "description": "=Call this tool to answer questions about the Building Code\u2019s **F Safety of Users** provisions\u2014Clauses **F1 to F9**\u2014which together safeguard people (including those with disabilities) and property from injury, illness, and loss of amenity throughout a building\u2019s life. These clauses cover:\n\n* **F1 Hazardous agents on site** \u2013 Identifying and neutralising site contamination or other hazardous agents before and during construction.\n* **F2 Hazardous building materials** \u2013 Ensuring the safe use of glass, glazing methods, asbestos, and any materials that emit noxious fumes.\n* **F3 Hazardous substances and processes** \u2013 Protecting occupants where hazardous substances are stored, handled, or used, and where hazardous processes occur.\n* **F4 Safety from falling** \u2013 Designing barriers, balustrades, and edges to prevent falls inside and outside the building.\n* **F5 Construction and demolition hazards** \u2013 Providing protection for people and other property during construction and demolition activities.\n* **F6 Visibility in escape routes** \u2013 Maintaining safe visibility along escape routes if the main lighting fails.\n* **F7 Warning systems** \u2013 Installing early-warning systems that alert occupants to emergencies.\n* **F8 Signs** \u2013 Supplying clear signs that identify escape routes, hazards, emergency features, and accessible facilities.\n* **F9 Restricting access to residential pools** \u2013 Preventing young children from gaining unsupervised access to residential swimming pools.\n\nIf the question is *not* about the NZ Building Code, reply: \"Out of scope \u2013 NZ Building Code only.\"\n\nIf you can not answer the query from retrieved documents, reply: \"I dont know.\"\n",
        "workflowId": {
          "__rl": true,
          "value": "iO0SlclPyNGzIqMw",
          "mode": "list",
          "cachedResultName": "Code-F Agent"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {},
          "matchingColumns": [],
          "schema": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "typeVersion": 2.2,
      "position": [
        20,
        500
      ],
      "id": "c47211f9-3c74-4ef7-96e0-2c6bda3c2165",
      "name": "code-f-agent"
    },
    {
      "parameters": {
        "description": "=Call this tool to answer questions about the Building Code\u2019s **G Services and Facilities** provisions\u2014Clauses **G1 to G15**\u2014which together ensure that sanitary fixtures, utilities, and environmental services are provided safely and adequately to protect health, wellbeing, and amenity for all building users (including people with disabilities) without creating hazards for others or for property. These clauses cover:\n\n* **G1 Personal hygiene** \u2013 Supplying sufficient toilets, showers, and basins.\n* **G2 Laundering** \u2013 Providing adequate laundry facilities.\n* **G3 Food preparation and prevention of contamination** \u2013 Ensuring safe, hygienic storage and preparation areas for food.\n* **G4 Ventilation** \u2013 Delivering adequate ventilation to all occupied spaces.\n* **G5 Interior environment** \u2013 Maintaining suitable space, accessibility, and controlled internal temperature in habitable areas.\n* **G6 Airborne and impact sound** \u2013 Limiting noise transmission between occupancies or common spaces.\n* **G7 Natural light** \u2013 Providing sufficient daylight and visual connection to the outdoors.\n* **G8 Artificial light** \u2013 Supplying artificial lighting that prevents injury and supports safe use.\n* **G9 Electricity** \u2013 Ensuring the safe use and distribution of electrical systems.\n* **G10 Piped services** \u2013 Safely distributing hot, cold, or toxic substances through piping.\n* **G11 Gas as an energy source** \u2013 Installing gas-fuelled appliances safely.\n* **G12 Water supplies** \u2013 Securing safe supply, storage, and delivery of hot and cold water.\n* **G13 Foul water** \u2013 Disposing of foul water safely to prevent illness, odour, and buildup.\n* **G14 Industrial liquid waste** \u2013 Collecting, treating, and disposing of industrial liquid waste hygienically to avoid contamination.\n* **G15 Solid waste** \u2013 Providing safe, hygienic collection and interim holding of solid waste prior to disposal.\n\n\nIf the question is *not* about the NZ Building Code, reply: \"Out of scope \u2013 NZ Building Code only.\"\n\nIf you can not answer the query from retrieved documents, reply: \"I dont know.\"",
        "workflowId": {
          "__rl": true,
          "value": "P8FoSrpQlMrLA7PP",
          "mode": "list",
          "cachedResultName": "Code-G Agent"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {},
          "matchingColumns": [],
          "schema": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "typeVersion": 2.2,
      "position": [
        -540,
        500
      ],
      "id": "20530c0d-0a5d-4b5e-b78c-65d971a1544a",
      "name": "code-g-agent"
    },
    {
      "parameters": {
        "description": "=Call this tool to answer questions about the Building Code\u2019s **H Energy efficiency** provisions\u2014Clause **H1 Energy efficiency**\u2014which ensure that applicable buildings (such as housing and other temperature- or humidity-conditioned spaces) use energy efficiently by:\n\n* Requiring adequate **thermal resistance** of the building envelope.\n* **Limiting uncontrolled airflow** to reduce heat loss or gain.\n* Setting physical conditions that influence overall **energy performance**.\n* Establishing performance requirements for **hot-water systems**, **artificial lighting**, and **HVAC** equipment.\n\n\nIf the question is *not* about the NZ Building Code, reply: \"Out of scope \u2013 NZ Building Code only.\"\n\nIf you can not answer the query from retrieved documents, reply: \"I dont know.\"",
        "workflowId": {
          "__rl": true,
          "value": "2nkh7MhUZNjtXr6s",
          "mode": "list",
          "cachedResultName": "Code-H Agent"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {},
          "matchingColumns": [],
          "schema": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "typeVersion": 2.2,
      "position": [
        -1120,
        500
      ],
      "id": "89600ecb-a1ca-4fcf-a9d4-7a7ebfd66e1e",
      "name": "code-h-agent"
    },
    {
      "parameters": {
        "content": "## Code-H-Agent",
        "height": 600,
        "width": 540,
        "color": 5
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -1540,
        480
      ],
      "id": "93a1d814-6dba-470c-8960-a3af6aa7d076",
      "name": "Sticky Note"
    },
    {
      "parameters": {
        "content": "## Code-G-Agent",
        "height": 600,
        "width": 540,
        "color": 5
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -980,
        480
      ],
      "id": "255d5d99-39b7-4b17-8dfa-c7cc38516df9",
      "name": "Sticky Note1"
    },
    {
      "parameters": {
        "content": "## Code-F-Agent\n",
        "height": 600,
        "width": 540,
        "color": 5
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -420,
        480
      ],
      "id": "7ca7b07c-54c4-4294-b1bf-63677a8b1a19",
      "name": "Sticky Note2"
    },
    {
      "parameters": {
        "content": "## Code-E-Agent",
        "height": 600,
        "width": 540,
        "color": 5
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        140,
        480
      ],
      "id": "e06199cf-74bb-451e-b749-292b553d77eb",
      "name": "Sticky Note3"
    },
    {
      "parameters": {
        "content": "## Code-D-Agent\n",
        "height": 600,
        "width": 540,
        "color": 5
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        700,
        480
      ],
      "id": "42044f98-8f25-4473-a484-29996cb30a59",
      "name": "Sticky Note4"
    },
    {
      "parameters": {
        "content": "## Code-C-Agent",
        "height": 600,
        "width": 540,
        "color": 5
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1260,
        480
      ],
      "id": "e3a52ed8-2089-4314-83a9-9b49e2f341bc",
      "name": "Sticky Note5"
    },
    {
      "parameters": {
        "content": "## Code-B-Agent",
        "height": 600,
        "width": 540,
        "color": 5
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1820,
        480
      ],
      "id": "ebfcaddd-59cf-406c-abfb-2d514c4b2285",
      "name": "Sticky Note6"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.query }}",
        "options": {
          "systemMessage": "=You are a New Zealand Building Code expert (focusing on Building Code \u201cH\u201d).\nAnswer questions about the Code\u2019s H1 Energy efficiency provisions\u2014thermal-resistance requirements, control of uncontrolled airflow, and performance criteria for hot-water systems, artificial lighting, and HVAC in conditioned spaces.\n\nUse only the information returned from the vectorstore.\n\nIf there are images provided from the retrieved information, you should return this in markdown format.\n\nIf the answer is not in the vectorstore, reply \u201cI don\u2019t know.\u201d Then add:\nFor more detail, see https://www.building.govt.nz/building-code-compliance/h-energy-efficiency"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 2,
      "position": [
        -1480,
        580
      ],
      "id": "b2bf982b-5b1e-40eb-bd48-15430c2df8c2",
      "name": "Code-H-Agent"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.query }}",
        "options": {
          "systemMessage": "=You are a New Zealand Building Code expert (focusing on Building Code \u201cG\u201d).\nAnswer questions about the Code\u2019s G Services and Facilities provisions\u2014Clauses G1-G15 addressing personal hygiene, laundering, food preparation, ventilation, interior environment, sound control, natural and artificial light, electricity, piped services, gas, water supply, foul water, industrial liquid waste, and solid-waste management.\n\nUse only the information returned from the vectorstore.\n\nIf there are images provided from the retrieved information, you should return this in markdown format.\n\nIf the answer is not in the vectorstore, reply \u201cI don\u2019t know.\u201d Then add:\nFor more detail, see https://www.building.govt.nz/building-code-compliance/g-services-and-facilities"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 2,
      "position": [
        -900,
        580
      ],
      "id": "d05c385a-3a3b-4ed7-b470-071e7af7b834",
      "name": "Code-G-Agent"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.query }}",
        "options": {
          "systemMessage": "=You are a New Zealand Building Code expert (focusing on Building Code \u201cF\u201d).\nAnswer questions about the Code\u2019s F Safety of Users provisions\u2014Clauses F1 to F9 covering hazardous agents (F1), hazardous materials (F2), hazardous substances/processes (F3), safety from falling (F4), construction & demolition hazards (F5), visibility in escape routes (F6), warning systems (F7), safety signage (F8), and restricting young-children access to residential pools (F9).\n\nUse only the information returned from the vectorstore.\n\nIf there are images provided from the retrieved information, you should return this in markdown format.\n\nIf the answer is not in the vectorstore, reply \u201cI don\u2019t know.\u201d Then add:\nFor more detail, see https://www.building.govt.nz/building-code-compliance/f-safety-of-users"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 2,
      "position": [
        -360,
        580
      ],
      "id": "e1ab801c-82a1-430f-b117-795c9b1b8ee7",
      "name": "Code-F-Agent"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.query }}",
        "options": {
          "systemMessage": "=You are a New Zealand Building Code expert (focusing on Building Code \u201cE\u201d).\nAnswer questions about the Code\u2019s E Moisture provisions\u2014Clause E1 Surface water (drainage and disposal of rainwater), Clause E2 External moisture (roofs, claddings, and openings must prevent water entry and accumulation), and Clause E3 Internal moisture (impervious surfaces, ventilation, thermal resistance, overflow disposal to avoid condensation and fungal growth).\n\nUse only the information returned from the vectorstore.\n\nIf there are images provided from the retrieved information, you should return this in markdown format.\n\nIf the answer is not in the vectorstore, reply \u201cI don\u2019t know.\u201d Then add:\nFor more detail, see https://www.building.govt.nz/building-code-compliance/e-moisture"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 2,
      "position": [
        220,
        580
      ],
      "id": "8d128090-309a-4385-99a6-8dac7bcf43fb",
      "name": "Code-E-Agent"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.query }}",
        "options": {
          "systemMessage": "=You are a New Zealand Building Code expert (focusing on Building Code \u201cD\u201d).\nAnswer questions about the Code\u2019s D Access provisions\u2014Clause D1 Access routes (safe entry, internal/external stairs, ramps, corridors, lifts; slip resistance; facilities for people with disabilities; vehicle movement, loading, parking) and Clause D2 Mechanical installations for access (lifts, escalators, moving walks must resist service loads, prevent accidents, and safeguard users and maintenance staff).\n\nyour goal is to provide an accurate answer based on this information ONLY.\n\nIf there are images provided from the retrieved information, you should return this in markdown format.\n\nIf the answer is not in the vectorstore, reply \u201cI don\u2019t know.\u201d Then add:\nFor more detail, see https://www.building.govt.nz/building-code-compliance/d-access"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 2,
      "position": [
        800,
        580
      ],
      "id": "f8914f4b-786c-433d-b4a4-7bf8cba10f4a",
      "name": "Code-D-Agent"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.query }}",
        "options": {
          "systemMessage": "=You are a New Zealand Building Code expert (focusing on Building Code \u201cB\u201d).\nAnswer questions about the Code\u2019s B Stability provisions\u2014Clause B1 Structure (buildings, elements, and site-works must resist self-weight, temperature, water, earthquake, snow, wind, and fire loads during construction, alteration, and service life) and Clause B2 Durability (materials must remain functional for at least 50, 15, or 5 years so the building continues to meet performance requirements and protect people and property).\n\nUse only the information returned from the vectorstore.\n\nIf there are images provided from the retrieved information, you should return this in markdown format.\n\nIf the answer is not in the vectorstore, reply \u201cI don\u2019t know.\u201d Then add:\nFor more detail, see https://www.building.govt.nz/building-code-compliance/b-stability"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 2,
      "position": [
        1900,
        580
      ],
      "id": "d48510d0-abb4-4f03-8417-9bd294614a8d",
      "name": "Code-B-Agent"
    },
    {
      "parameters": {
        "content": "## Orchestration Agent\n**(can connect to webhook)**",
        "height": 460,
        "width": 840,
        "color": 3
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -360,
        -300
      ],
      "id": "b7f8a4b2-7388-4868-9d07-63a37f3b8eb5",
      "name": "Sticky Note7"
    },
    {
      "parameters": {
        "options": {
          "systemMessage": "=## ROLE & OBJECTIVE\nYou are **the Orchestration Agent** for the NZ Building Code multi-agent system.  \nYour sole task is to **receive a user\u2019s natural-language query, determine which NZ Building Code clause it pertains to, and forward the query to the specialised clause agent(s)** listed below.  \n\nYou never answer building-code questions yourself; you only route them.\n\n---\n\n## AVAILABLE CLAUSE AGENTS  \n- **B \u2013 Stability & Durability**  \n  \u2022 Topics: structure, loads, durability periods  \n  \u2022 Agent name: `agent_B`  \n  \u2022 Invocation keyword: `route:B`\n\n- **C \u2013 Fire Safety**  \n  \u2022 Topics: fire-resistance, means of escape, protection of other property  \n  \u2022 Agent name: `agent_C`  \n  \u2022 Invocation keyword: `route:C`\n\n- **D \u2013 Access**  \n  \u2022 Topics: access routes, barriers, accessible design  \n  \u2022 Agent name: `agent_D`  \n  \u2022 Invocation keyword: `route:D`\n\n- **E \u2013 Moisture**  \n  \u2022 Topics: weathertightness, internal moisture, surface water, hazardous agents  \n  \u2022 Agent name: `agent_E`  \n  \u2022 Invocation keyword: `route:E`\n\n- **F \u2013 Safety of Users**  \n  \u2022 Topics: hazards, safety glazing, fall prevention  \n  \u2022 Agent name: `agent_F`  \n  \u2022 Invocation keyword: `route:F`\n\n- **G \u2013 Services & Facilities**  \n  \u2022 Topics: sanitary fixtures, ventilation, natural light, hot water  \n  \u2022 Agent name: `agent_G`  \n  \u2022 Invocation keyword: `route:G`\n\n- **H \u2013 Energy Efficiency**  \n  \u2022 Topics: thermal envelope, hot-water systems, HVAC efficiency  \n  \u2022 Agent name: `agent_H`  \n  \u2022 Invocation keyword: `route:H`\n\nIf a query clearly spans multiple clauses, forward it to **each** relevant agent.\n\n---\n\n## OPERATING RULES\n\n1. **Analyse First**  \n   Think step-by-step:  \n   - Extract key nouns/verbs from the query.  \n   - Match them to clause topics above.  \n   - Choose the best-fit clause(s).\n\n2. **No Answer Generation** \u2013 never attempt to answer, summarise, or transform the query content.\n\n3. **Uncertain Classification**\n\n   * If you cannot confidently map the query to a clause, route to **all** clause agents:\n   * Clause agents will handle clarification.\n\n4. **Out-of-Scope Queries**\n\n   * If the question is *not* about the NZ Building Code, reply: \"Out of scope \u2013 NZ Building Code only.\"\n\n5. **Persistence** \u2013 continue routing until the user\u2019s request is successfully delivered to the correct clause agent(s).\n\n\n## FINAL REMINDERS\n\n* Do **not** modify user wording.\n* If unsure, favour broader routing rather than missing a relevant clause.\n* Date: {{CURRENT\\_DATE}} (NZST)\n* Ask follow-up questions **only** if essential for correct routing.\n\n"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 2,
      "position": [
        100,
        -140
      ],
      "id": "7d84bc0e-7fb2-42bf-b9e7-feadee5453f6",
      "name": "Orchestration Agent"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.query }}",
        "options": {
          "systemMessage": "=You are a New Zealand Building Code expert (focusing on Building Code \u201cC\u201d).\nAnswer questions about the Code\u2019s C Protection from Fire provisions\u2014Clauses C1\u2013C6, which cover: preventing fires (C2), limiting fire spread (C3), enabling safe evacuation (C4), providing firefighting access (C5), and maintaining structural stability during fire (C6), all in line with the objectives of C1.\n\nUse only the information returned from the vectorstore.\n\nIf there are images provided from the retrieved information, you should return this in markdown format.\n\nIf the answer is not in the vectorstore, reply \u201cI don\u2019t know.\u201d Then add:\nFor more detail, see https://www.building.govt.nz/building-code-compliance/c-protection-from-fire"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 2,
      "position": [
        1320,
        580
      ],
      "id": "2b14c9b6-2a8e-449d-a7d0-cb9f9ae42b73",
      "name": "Code-C Agent"
    },
    {
      "parameters": {
        "mode": "retrieve-as-tool",
        "toolDescription": "Use this tool to retrieve relevant information from the vectorstore.",
        "tableName": {
          "__rl": true,
          "value": "code-c",
          "mode": "list",
          "cachedResultName": "code-c"
        },
        "topK": 5,
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "typeVersion": 1.3,
      "position": [
        1500,
        780
      ],
      "id": "73a4abee-ec89-41b2-bc1a-684d493264fc",
      "name": "Supabase Vector Store code c",
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "mode": "retrieve-as-tool",
        "toolDescription": "Use this tool to retrieve relevant information from the vectorstore.",
        "tableName": {
          "__rl": true,
          "value": "code-b",
          "mode": "list",
          "cachedResultName": "code-b"
        },
        "topK": 5,
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "typeVersion": 1.3,
      "position": [
        2040,
        780
      ],
      "id": "db9e98ad-3b4e-4f55-8781-e3e50db77ad0",
      "name": "Supabase Vector Store code b",
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "mode": "retrieve-as-tool",
        "toolDescription": "Use this tool to retrieve relevant information from the vectorstore.",
        "tableName": {
          "__rl": true,
          "value": "code-d",
          "mode": "list",
          "cachedResultName": "code-d"
        },
        "topK": 5,
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "typeVersion": 1.3,
      "position": [
        940,
        780
      ],
      "id": "8b4f56cf-4334-4eae-92af-94dfb7a5d17b",
      "name": "Supabase Vector Store code d",
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "mode": "retrieve-as-tool",
        "toolDescription": "Use this tool to retrieve relevant information from the vectorstore.",
        "tableName": {
          "__rl": true,
          "value": "code-e",
          "mode": "list",
          "cachedResultName": "code-e"
        },
        "topK": 5,
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "typeVersion": 1.3,
      "position": [
        400,
        780
      ],
      "id": "1bbea2a6-7d36-4522-879d-20fc5256714c",
      "name": "Supabase Vector Store code e",
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "mode": "retrieve-as-tool",
        "toolDescription": "Use this tool to retrieve relevant information from the vectorstore.",
        "tableName": {
          "__rl": true,
          "value": "code-f",
          "mode": "list",
          "cachedResultName": "code-f"
        },
        "topK": 5,
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "typeVersion": 1.3,
      "position": [
        -180,
        780
      ],
      "id": "4d937c6c-5cc3-4e5c-9844-dcd0c6ad2e77",
      "name": "Supabase Vector Store code f",
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "mode": "retrieve-as-tool",
        "toolDescription": "Use this tool to retrieve relevant information from the vectorstore.",
        "tableName": {
          "__rl": true,
          "value": "code-g",
          "mode": "list",
          "cachedResultName": "code-g"
        },
        "topK": 5,
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "typeVersion": 1.3,
      "position": [
        -720,
        800
      ],
      "id": "a3456a98-0474-4735-a717-9d2af310b0f8",
      "name": "Supabase Vector Store code g",
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "mode": "retrieve-as-tool",
        "toolDescription": "Use this tool to retrieve relevant information from the vectorstore.",
        "tableName": {
          "__rl": true,
          "value": "code-h",
          "mode": "list",
          "cachedResultName": "code-h"
        },
        "topK": 5,
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "typeVersion": 1.3,
      "position": [
        -1300,
        800
      ],
      "id": "16f99860-5aa4-42c7-b89b-d99bab328ffb",
      "name": "Supabase Vector Store code h",
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4.1",
          "mode": "list",
          "cachedResultName": "gpt-4.1"
        },
        "options": {
          "temperature": 0.4
        }
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        -1480,
        800
      ],
      "id": "f517e1ce-8753-467b-a8f9-f90d71a3c918",
      "name": "OpenAI Chat Model code h",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "typeVersion": 1.2,
      "position": [
        -1300,
        940
      ],
      "id": "a5eb9a82-e2bc-49b3-a277-75ec2222cc32",
      "name": "Embeddings OpenAI code h",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4.1",
          "mode": "list",
          "cachedResultName": "gpt-4.1"
        },
        "options": {
          "temperature": 0.4
        }
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        -900,
        800
      ],
      "id": "28f74f6c-e2ab-4af3-bb27-e78def9cc7b2",
      "name": "OpenAI Chat Model code g",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "typeVersion": 1.2,
      "position": [
        -720,
        920
      ],
      "id": "bd4acb37-939e-42ca-addc-d26ce1dd1e50",
      "name": "Embeddings OpenAI code g",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4.1",
          "mode": "list",
          "cachedResultName": "gpt-4.1"
        },
        "options": {
          "temperature": 0.4
        }
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        -360,
        780
      ],
      "id": "a16fa0c1-ec7d-46fa-9d9f-9693515bea4c",
      "name": "OpenAI Chat Model code f",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "typeVersion": 1.2,
      "position": [
        -180,
        920
      ],
      "id": "41a6b66e-f454-4afe-b291-f3f58136a936",
      "name": "Embeddings OpenAI code f",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4.1",
          "mode": "list",
          "cachedResultName": "gpt-4.1"
        },
        "options": {
          "temperature": 0.4
        }
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        220,
        780
      ],
      "id": "a59516ab-b5ca-4aad-84a4-5e184e47cb96",
      "name": "OpenAI Chat Model code e",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "typeVersion": 1.2,
      "position": [
        400,
        920
      ],
      "id": "8a22699b-d97b-469e-8d2e-8973ded6f81d",
      "name": "Embeddings OpenAI code e",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4.1",
          "mode": "list",
          "cachedResultName": "gpt-4.1"
        },
        "options": {
          "temperature": 0.4
        }
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        780,
        780
      ],
      "id": "e35af57c-e789-487b-b804-f71a7de1bd8e",
      "name": "OpenAI Chat Model code d",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "typeVersion": 1.2,
      "position": [
        940,
        920
      ],
      "id": "71c9f136-f583-45ae-b742-849cc467e29d",
      "name": "Embeddings OpenAI code d",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4.1",
          "mode": "list",
          "cachedResultName": "gpt-4.1"
        },
        "options": {
          "temperature": 0.4
        }
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        1320,
        780
      ],
      "id": "9f97d68a-69c7-4df2-bb89-fca989f99044",
      "name": "OpenAI Chat Model code c",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "typeVersion": 1.2,
      "position": [
        1500,
        920
      ],
      "id": "766babec-74de-4193-b6cd-7f4f8bae81bf",
      "name": "Embeddings OpenAI code c",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4.1",
          "mode": "list",
          "cachedResultName": "gpt-4.1"
        },
        "options": {
          "temperature": 0.4
        }
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        1880,
        780
      ],
      "id": "e54d164e-86b8-440f-8529-e092a130bcd5",
      "name": "OpenAI Chat Model code b",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "typeVersion": 1.2,
      "position": [
        2060,
        920
      ],
      "id": "85827bc6-b655-4ba6-ad1e-a7e50607a83d",
      "name": "Embeddings OpenAI codeb",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "When chat message received": {
      "main": [
        [
          {
            "node": "Orchestration Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Orchestration Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Postgres Chat Memory": {
      "ai_memory": [
        [
          {
            "node": "Orchestration Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "code-b-agent": {
      "ai_tool": [
        [
          {
            "node": "Orchestration Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "code-c-agent": {
      "ai_tool": [
        [
          {
            "node": "Orchestration Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "code-d-agent": {
      "ai_tool": [
        [
          {
            "node": "Orchestration Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "code-e-agent": {
      "ai_tool": [
        [
          {
            "node": "Orchestration Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "code-f-agent": {
      "ai_tool": [
        [
          {
            "node": "Orchestration Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "code-g-agent": {
      "ai_tool": [
        [
          {
            "node": "Orchestration Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "code-h-agent": {
      "ai_tool": [
        [
          {
            "node": "Orchestration Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Supabase Vector Store code c": {
      "ai_tool": [
        [
          {
            "node": "Code-C Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Supabase Vector Store code b": {
      "ai_tool": [
        [
          {
            "node": "Code-B-Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Supabase Vector Store code d": {
      "ai_tool": [
        [
          {
            "node": "Code-D-Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Supabase Vector Store code e": {
      "ai_tool": [
        [
          {
            "node": "Code-E-Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Supabase Vector Store code f": {
      "ai_tool": [
        [
          {
            "node": "Code-F-Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Supabase Vector Store code g": {
      "ai_tool": [
        [
          {
            "node": "Code-G-Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Supabase Vector Store code h": {
      "ai_tool": [
        [
          {
            "node": "Code-H-Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model code h": {
      "ai_languageModel": [
        [
          {
            "node": "Code-H-Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI code h": {
      "ai_embedding": [
        [
          {
            "node": "Supabase Vector Store code h",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model code g": {
      "ai_languageModel": [
        [
          {
            "node": "Code-G-Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI code g": {
      "ai_embedding": [
        [
          {
            "node": "Supabase Vector Store code g",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model code f": {
      "ai_languageModel": [
        [
          {
            "node": "Code-F-Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI code f": {
      "ai_embedding": [
        [
          {
            "node": "Supabase Vector Store code f",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model code e": {
      "ai_languageModel": [
        [
          {
            "node": "Code-E-Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI code e": {
      "ai_embedding": [
        [
          {
            "node": "Supabase Vector Store code e",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model code d": {
      "ai_languageModel": [
        [
          {
            "node": "Code-D-Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI code d": {
      "ai_embedding": [
        [
          {
            "node": "Supabase Vector Store code d",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model code c": {
      "ai_languageModel": [
        [
          {
            "node": "Code-C Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI code c": {
      "ai_embedding": [
        [
          {
            "node": "Supabase Vector Store code c",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model code b": {
      "ai_languageModel": [
        [
          {
            "node": "Code-B-Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI codeb": {
      "ai_embedding": [
        [
          {
            "node": "Supabase Vector Store code b",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "256ac6ab-27b8-4671-9763-66bff3c36128",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "nY9H6CMMrDbmJIwd",
  "tags": []
}