{
  "name": "Chat with Postgresql database",
  "nodes": [
    {
      "id": "6501a54f-a68c-452d-b353-d7e871ca3780",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        -300,
        -80
      ]
    },
    {
      "id": "cd32221b-2a36-408d-b57e-8115fcd810c9",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        0,
        -80
      ]
    },
    {
      "id": "8accbeeb-7eaf-4e9e-aabc-de8ab3a0459b",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -60,
        160
      ]
    },
    {
      "id": "11f2013f-a080-4c9e-8773-c90492e2c628",
      "name": "Get Table Definition",
      "type": "n8n-nodes-base.postgresTool",
      "position": [
        780,
        140
      ]
    },
    {
      "id": "760bc9bc-0057-4088-b3f0-3ee37b3519df",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -300,
        -240
      ],
      "parameters": {
        "width": 560,
        "height": 120,
        "content": "### 👨‍🎤 Setup\n1. Add your **postgresql** and **OpenAI** credentials.\n2. Click **Chat** button and start asking questions to your database.\n3. Activate the workflow and you can make the chat publicly a"
      }
    },
    {
      "id": "0df33341-c859-4a54-b6d9-a99670e8d76d",
      "name": "Chat History",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        120,
        160
      ]
    },
    {
      "id": "4938b22e-f187-4ca0-b9f1-60835e823799",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        360,
        300
      ],
      "parameters": {
        "width": 562,
        "height": 156,
        "content": "🛠️ Tools Used:\n1. Execute SQL Query: Used to execute any query generated by the agent.\n2. Get DB Schema and Tables List: It returns the list of all the tables with its schema name.\n3. Get Table Defini"
      }
    },
    {
      "id": "39780c78-4fbc-403e-a220-aa6a4b06df8c",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -100,
        300
      ],
      "parameters": {
        "width": 162,
        "height": 99,
        "content": "👆 You can exchange this with any other chat model of your choice."
      }
    },
    {
      "id": "28a5692c-5003-46cb-9a09-b7867734f446",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        100,
        300
      ],
      "parameters": {
        "width": 162,
        "height": 159,
        "content": "👆 You can change how many number of messages to keep using `Context Window Length` option. It's 5 by default."
      }
    },
    {
      "id": "c18ced71-6330-4ba0-9c52-1bb5852b3039",
      "name": "Execute SQL Query",
      "type": "n8n-nodes-base.postgresTool",
      "position": [
        380,
        140
      ]
    },
    {
      "id": "557623c6-e499-48a6-a066-744f64f8b6f3",
      "name": "Get DB Schema and Tables List",
      "type": "n8n-nodes-base.postgresTool",
      "position": [
        580,
        140
      ]
    }
  ],
  "connections": {
    "Chat History": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Execute SQL Query": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Get Table Definition": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get DB Schema and Tables List": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  }
}