{
  "name": "AI agent to chat with you Search Console data, using OpenAI and Postgres",
  "nodes": [
    {
      "id": "9ee6710b-19b7-4bfd-ac2d-0fe1e2561f1d",
      "name": "Postgres Chat Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryPostgresChat",
      "position": [
        1796,
        220
      ]
    },
    {
      "id": "eb9f07e9-ded1-485c-9bf3-cf223458384a",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1356,
        240
      ]
    },
    {
      "id": "1d3d6fb7-a171-4590-be42-df7eb0c208ed",
      "name": "Set fields",
      "type": "n8n-nodes-base.set",
      "position": [
        940,
        -20
      ]
    },
    {
      "id": "92dc5e8b-5140-49be-8713-5749b7e2d46b",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        407.32142857142867,
        -320
      ],
      "parameters": {
        "width": 347.9910714285712,
        "height": 516.8973214285712,
        "content": "## Webhook - ChatInput\n\nThis webhook serves as the endpoint for receiving `ChatInput` data. Ensure that you include:\n- `chatInput` – the content you wish to send (😉)\n- `sessionId` – a unique identifie"
      }
    },
    {
      "id": "ca9f3732-9b62-4f44-b970-77d5d470ec76",
      "name": "Webhook - ChatInput",
      "type": "n8n-nodes-base.webhook",
      "position": [
        500,
        -20
      ]
    },
    {
      "id": "9d684873-6dfe-4709-928d-293b187dfb30",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        820,
        -320
      ],
      "parameters": {
        "width": 347.9910714285712,
        "height": 516.8973214285712,
        "content": "## Set fields\n\nThis node sets three fields:\n- `chatInput`: retrieved from the previous webhook node\n- `sessionId`: retrieved from the previous webhook node\n- `date_message`: formatted within this node"
      }
    },
    {
      "id": "8750215a-1e33-4ac8-a6da-95efa8ffed65",
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        2600,
        -20
      ]
    },
    {
      "id": "1b879496-5c0f-4bd5-b4cb-18df2662aef2",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1240,
        -320
      ],
      "parameters": {
        "width": 1154.2857142857138,
        "height": 516.8973214285712,
        "content": "## AI Agent - Tools Agent\n\nThis AI Agent is configured with a system prompt that instructs it to:\n- On the first user message, **retrieve available Search Console properties** and offer the user the o"
      }
    },
    {
      "id": "c44c6402-9ddd-4a7b-bc5a-b6c3679a3f68",
      "name": "Call Search Console Tool",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "position": [
        2196,
        220
      ]
    },
    {
      "id": "b1701a89-c5b3-47fb-99d5-4896a6d5c7a2",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1234,
        220
      ],
      "parameters": {
        "width": 328.9664285714292,
        "height": 468.13107142857154,
        "content": "\n\n\n\n\n\n\n\n\n\n\n### AI Agent Sub-node - OpenAI Chat Model\n\nThis sub-node utilizes the selected **OpenAI Chat Model**. You can replace it with any LLM that **supports tool calling**.\n\n### ⚠️ Choose Your Mod"
      }
    },
    {
      "id": "cd1a7cec-5845-47b1-a2c8-d3b458a02eb0",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1656,
        220
      ],
      "parameters": {
        "width": 328.9664285714292,
        "height": 468.13107142857154,
        "content": "\n\n\n\n\n\n\n\n\n\n\n### AI Agent Sub-node - Postgres Chat Memory\n\nConnect your **Postgres credentials** and specify a **table name** to store the chat history. In this template, the default table name is `insi"
      }
    },
    {
      "id": "290a07d1-c7ed-434d-9851-2a2dcdd35bdf",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2076,
        220
      ],
      "parameters": {
        "width": 328.9664285714292,
        "height": 468.13107142857154,
        "content": "\n\n\n\n\n\n\n\n\n\n\n### AI Agent Sub-node - Call Search Console Tool\n\nThis **tool is used by the AI Agent** to:\n- Retrieve the **list of accessible properties in Search Console**\n- **Fetch Search Console data*"
      }
    },
    {
      "id": "07805c90-7ba5-44d0-b6eb-5a65efb0f8be",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2480,
        -320
      ],
      "parameters": {
        "width": 347.9910714285712,
        "height": 516.8973214285712,
        "content": "## Respond to Webhook\n\nThis node is used to send a response back to the user.\n\n**👋 Tip:** `intermediateSteps` are configured, allowing you to use raw data fetched from Search Console to **create chart"
      }
    },
    {
      "id": "9a927a40-45e4-4fd5-ab3e-b77578469f82",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        400,
        800
      ],
      "parameters": {
        "width": 370.3910714285712,
        "height": 492.3973214285712,
        "content": "## Tool Call Trigger\n\nThis **node is triggered when the AI Agent needs to retrieve the `website_list`** (accessible Search Console properties) or **`custom_insights`** based on user data.\n"
      }
    },
    {
      "id": "c54a4653-0f09-46b0-bd20-68919b96e154",
      "name": "Tool calling",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        500,
        1080
      ]
    },
    {
      "id": "cc7303ee-1afa-4859-83e7-3af0e963a0f1",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "position": [
        1300,
        1080
      ]
    },
    {
      "id": "6860ff98-4050-4f64-b8c1-a153e3388df0",
      "name": "Set fields - Consruct API CALL",
      "type": "n8n-nodes-base.set",
      "position": [
        920,
        1080
      ]
    },
    {
      "id": "0a2dfb28-17ee-477f-b9ea-f1d8e05e3745",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        820,
        800
      ],
      "parameters": {
        "width": 370.3910714285712,
        "height": 492.3973214285712,
        "content": "## Set Fields - Construct API Call\n\nThis node configures fields based on the JSON sent by the AI agent:\n- The `request_type` field determines the route: `website_list` (to retrieve the list of website"
      }
    },
    {
      "id": "e6ef5c28-01e4-4a0b-9081-b62ec28be635",
      "name": "Set fields - Create searchConsoleDataArray",
      "type": "n8n-nodes-base.set",
      "position": [
        2180,
        980
      ]
    },
    {
      "id": "abc80061-a794-4e1d-a055-bd88ea5c93eb",
      "name": "Set fields - Create searchConsoleDataArray 2",
      "type": "n8n-nodes-base.set",
      "position": [
        2180,
        1340
      ]
    },
    {
      "id": "24981eea-980e-4e07-9036-d0042c5b2fbe",
      "name": "Search Console - Get Custom Insights",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1620,
        980
      ]
    },
    {
      "id": "645ff407-857d-4629-926b-5cfc52cfa8ba",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1520,
        800
      ],
      "parameters": {
        "width": 370.3910714285712,
        "height": 364.3185243941325,
        "content": "## Search Console - Get Custom Insights\n\nThis node **performs the API call to retrieve data from Search Console**.\n"
      }
    },
    {
      "id": "15aa66e2-f288-4c86-8dad-47e22aa9104f",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1520,
        1180
      ],
      "parameters": {
        "width": 370.3910714285712,
        "height": 334.24982142857124,
        "content": "## Search Console - Get List of Properties\n\nThis node **performs the API call to retrieve the list of accessible properties from Search Console**.\n"
      }
    },
    {
      "id": "cd804a52-833a-451a-8e0c-f640210ee2c4",
      "name": "## Search Console - Get List of Properties",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1620,
        1340
      ]
    },
    {
      "id": "3eac4df1-00ac-4262-b520-3a7e218c7e57",
      "name": "Sticky Note11",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2040,
        800
      ],
      "parameters": {
        "width": 370.3910714285712,
        "height": 725.1298214285712,
        "content": "## Set Fields - Create `searchConsoleDataArray`\n\nThese nodes **create an array based on the response from the Search Console API**.\n"
      }
    },
    {
      "id": "86db5800-a735-4749-a800-63d78908610b",
      "name": "Sticky Note12",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2520,
        800
      ],
      "parameters": {
        "width": 370.3910714285712,
        "height": 722.6464176100125,
        "content": "## Array Aggregation - Response to AI Agent\n\nThese nodes **aggregate the array from the previous** step and send it back to the AI Agent through the field named output as `response`.\n"
      }
    },
    {
      "id": "aefbacc7-8dfc-4655-bc4d-f0498c823711",
      "name": "Array aggregation - response to AI Agent",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        2640,
        980
      ]
    },
    {
      "id": "e5334c72-981c-4375-ae8e-9a3a0457880b",
      "name": "Array aggregation - response to AI Agent1",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        2660,
        1340
      ]
    },
    {
      "id": "2e93a798-6c26-4d34-a553-ba01b64ca3fe",
      "name": "Sticky Note13",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -398.45627799387194,
        -320
      ],
      "parameters": {
        "width": 735.5589746610085,
        "height": 1615.4504601771982,
        "content": "# AI Agent to Chat with Your Search Console Data\n\nThis **AI Agent enables you to interact with your Search Console data** through a **chat interface**. Each node is **documented within the template**,"
      }
    },
    {
      "id": "fa630aa9-3c60-4b27-9477-aaeb79c7f37d",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1676,
        -20
      ]
    }
  ],
  "connections": {
    "Switch": {
      "main": [
        [
          {
            "node": "Search Console - Get Custom Insights",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "## Search Console - Get List of Properties",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set fields": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Tool calling": {
      "main": [
        [
          {
            "node": "Set fields - Consruct API CALL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Webhook - ChatInput": {
      "main": [
        [
          {
            "node": "Set fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Postgres Chat Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Call Search Console Tool": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Set fields - Consruct API CALL": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search Console - Get Custom Insights": {
      "main": [
        [
          {
            "node": "Set fields - Create searchConsoleDataArray",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "## Search Console - Get List of Properties": {
      "main": [
        [
          {
            "node": "Set fields - Create searchConsoleDataArray 2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set fields - Create searchConsoleDataArray": {
      "main": [
        [
          {
            "node": "Array aggregation - response to AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set fields - Create searchConsoleDataArray 2": {
      "main": [
        [
          {
            "node": "Array aggregation - response to AI Agent1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}