{
  "name": "Build your first AI data analyst chatbot",
  "nodes": [
    {
      "id": "0951fd33-1811-4a89-b84f-f46dc9e6fde1",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        20,
        -340
      ]
    },
    {
      "id": "699c2f89-5547-4d28-92a9-5e216aecb251",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        240,
        -340
      ]
    },
    {
      "id": "640c29f7-b67e-49f6-a864-c9b396c446b7",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        160,
        -100
      ]
    },
    {
      "id": "807630b4-c138-4b66-a438-fb70eab12a07",
      "name": "Calculator",
      "type": "@n8n/n8n-nodes-langchain.toolCalculator",
      "position": [
        840,
        60
      ]
    },
    {
      "id": "132a97a3-239c-403f-843f-55b652e3efc5",
      "name": "Code",
      "type": "n8n-nodes-base.code",
      "position": [
        840,
        640
      ]
    },
    {
      "id": "3dc1e670-bfb1-4b63-b9c8-85656134c843",
      "name": "When Executed by Another Workflow",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        280,
        640
      ]
    },
    {
      "id": "52a26e43-12a5-4b4a-a224-d70cdabf6aaf",
      "name": "Records by date",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "position": [
        1020,
        -120
      ]
    },
    {
      "id": "e1811519-8699-4243-8c64-0db1ab26004d",
      "name": "Aggregate",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        1280,
        640
      ]
    },
    {
      "id": "3b129abd-ac9a-460c-abb3-007e2c94e284",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1220,
        400
      ],
      "parameters": {
        "width": 220,
        "height": 400,
        "content": "To send all the items back to the AI, we need to finish with everything aggregated into one single item.\n\nOtherwise it will respond with one item at a time, and the AI will only get the first item tha"
      }
    },
    {
      "id": "645ac0f9-8022-4f2c-8c6c-5aadd6cf09cc",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        460,
        400
      ],
      "parameters": {
        "width": 300,
        "height": 400,
        "content": "This node sends a custom HTTP Request to the Google Sheets API.\n\nFiltering by date range in the Google Sheets API is very complicated.\n\nThis node solves that problem.\n\nBut doing the same in a database"
      }
    },
    {
      "id": "14221a72-914d-4c75-866a-d64ba7f8109f",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        780,
        400
      ],
      "parameters": {
        "width": 220,
        "height": 400,
        "content": "The output from this complex request is also messy.\n\nSo we use some code generated by ChatGPT to transform the data into JSON objects."
      }
    },
    {
      "id": "f12668ea-b59d-4caf-a997-381f78b7cfe7",
      "name": "Google Sheets request",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        560,
        640
      ]
    },
    {
      "id": "f59a2606-0981-43d1-9a07-b802891b9220",
      "name": "Get transactions by product name",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        1020,
        -320
      ]
    },
    {
      "id": "1ed7168c-1639-4b3b-a3b4-ed162bcef880",
      "name": "Get all transactions",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        840,
        -120
      ]
    },
    {
      "id": "798453da-8a65-4d14-ae0a-778d64ab02ad",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -360,
        -340
      ],
      "parameters": {
        "width": 320,
        "height": 340,
        "content": "## Some questions to try\nThere's a red button on this page that you can click to chat with the AI.\n\nTry asking it these questions:\n\n- How many refunds in January and what was the amount refunded?\n\n- H"
      }
    },
    {
      "id": "b8336f1a-3855-4247-9589-2f9aa35d211f",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -780,
        -340
      ],
      "parameters": {
        "width": 400,
        "height": null,
        "content": "## Copy this Sheets file to your Google Drive\nhttps://docs.google.com/spreadsheets/d/18A4d7KYrk8-uEMbu7shoQe_UIzmbTLV1FMN43bjA7qc/edit?gid=0#gid=0"
      }
    },
    {
      "id": "99a55b39-965b-4454-b416-d3991f0bdfbc",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        940,
        60
      ],
      "parameters": {
        "width": 200,
        "height": 140,
        "content": "### 👈\nThe Calculator is a tool that allows an agent to run mathematical calculations."
      }
    },
    {
      "id": "7ebebf56-e065-41c4-8270-f636785b0def",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -780,
        -160
      ],
      "parameters": {
        "width": 400,
        "height": null,
        "content": "### How to connect to Google Sheets?\nTo connect your n8n to your Google Sheets you're gonna need Google OAuth credentials\n\nSee documentation **[here](https://docs.n8n.io/integrations/builtin/credentia"
      }
    },
    {
      "id": "b64df0dd-6425-4fc2-9f60-8c5a85412d61",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        120,
        20
      ],
      "parameters": {
        "width": 170,
        "height": 260,
        "content": "## 👆\nYou can use many models here, including the free Google Gemini options.\n\nMake sure to test it thoroughly. Some models are better for data analysis."
      }
    },
    {
      "id": "23c7bb52-b189-45f1-949b-ea588f065583",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        340,
        20
      ],
      "parameters": {
        "width": 150,
        "height": 260,
        "content": "## 👆\nThis is a short term memory. It will remember the 5 previous interactions during the chat"
      }
    },
    {
      "id": "6097e5a1-139b-4329-81ff-4fda16ea5221",
      "name": "Buffer Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        360,
        -100
      ]
    },
    {
      "id": "6de4a7f2-5c58-4401-bd7c-19c5a73ba775",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1160,
        -320
      ],
      "parameters": {
        "width": 340,
        "height": 180,
        "content": "The **AI Tools Agent** has access to all the tools at the same time. It uses the name and description to decide when to use each tool.\n\nNotice I'm using `$fromAI` function in all of them.\n\nSee documen"
      }
    },
    {
      "id": "a308d895-bc18-4b2c-9567-78f6c29f79e8",
      "name": "Sticky Note11",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1160,
        -120
      ],
      "parameters": {
        "width": 340,
        "height": 320,
        "content": "## 👈 This is a special tool\nIt is used to call another workflow.\nThis concept is called sub-workflow.\n\nSee documentation [here](https://docs.n8n.io/flow-logic/subworkflows/).\n\nInstead of running a com"
      }
    },
    {
      "id": "0a6d94bc-21e1-4949-b7f4-c93abbecf08c",
      "name": "Sticky Note12",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        120,
        340
      ],
      "parameters": {
        "width": 1380,
        "height": 520,
        "content": "# Sub-workflow\nThe AI can call this sub-workflow anytime,\nby using the **Records by date** tool.\n\nThe sub-workflow automatically return\n the result of the last executed node to the AI."
      }
    },
    {
      "id": "3e424615-6e49-4bd3-b066-005b9f0f773e",
      "name": "Filter by status",
      "type": "n8n-nodes-base.filter",
      "position": [
        1060,
        640
      ]
    },
    {
      "id": "0ad0102c-adb9-4ec9-bdf3-b1ce425b88ba",
      "name": "Get transactions by status",
      "type": "n8n-nodes-base.googleSheetsTool",
      "position": [
        840,
        -320
      ]
    },
    {
      "id": "5b80cb08-6e19-47b2-8146-c299e709a34a",
      "name": "Sticky Note13",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        820,
        -540
      ],
      "parameters": {
        "width": 300,
        "height": null,
        "content": "## Change the URL of the Sheets file in all the Sheets tools 👇"
      }
    },
    {
      "id": "ddc1351e-0ad0-480f-9742-30f2aa860d61",
      "name": "Sticky Note14",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        500,
        820
      ],
      "parameters": {
        "width": 260,
        "height": 100,
        "content": "## 👆 Change the URL of the Sheets file"
      }
    },
    {
      "id": "ab837a10-932f-4b14-8e2c-546077ca2c86",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -780,
        20
      ],
      "parameters": {
        "width": 740,
        "height": 640,
        "content": "# Author\n![Solomon](https://gravatar.com/avatar/79aa147f090807fe0f618fb47a1de932669e385bb0c84bf3a7f891ae7d174256?r=pg&d=retro&size=200)\n### Solomon\nFreelance consultant from Brazil, specializing in au"
      }
    },
    {
      "id": "e58351b3-3b18-4c03-9435-27ba853d03bb",
      "name": "Sticky Note15",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -780,
        680
      ],
      "parameters": {
        "width": 740,
        "height": 180,
        "content": "# Need help?\nFor getting help with this workflow, please create a topic on the community forums here:\nhttps://community.n8n.io/c/questions/"
      }
    },
    {
      "id": "4519d880-7448-4fb3-b2dc-ccea787729be",
      "name": "Sticky Note16",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -760,
        560
      ],
      "parameters": {
        "width": 700,
        "height": 80,
        "content": "### 💡 **Want to learn advanced n8n skills and earn money building workflows?**\n‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎Check out [Scrapes Academy](https://www.skool.com/scrapes/about?ref=21f10ad99f4d46ba9b8aaea8c9f58c34)"
      }
    }
  ],
  "connections": {
    "Code": {
      "main": [
        [
          {
            "node": "Filter by status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculator": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Buffer Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Records by date": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Filter by status": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Get all transactions": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets request": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get transactions by status": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get transactions by product name": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "When Executed by Another Workflow": {
      "main": [
        [
          {
            "node": "Google Sheets request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}