{
  "name": "simple_rag",
  "nodes": [
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "typeVersion": 1.1,
      "position": [
        -20,
        0
      ],
      "id": "e3561d16-a655-486e-b405-84192a608a2f",
      "name": "When chat message received"
    },
    {
      "parameters": {
        "options": {
          "systemMessage": "=You are a helpful assistant with tools. Today is {{ $now }}.\n\n**Column Definitions and Data Types**\n- The data you handle must have the following columns and types:\n  - `date`: date, format `yyyy-mm-dd`\n  - `item`: string\n  - `cat`: string\n  - `unit`: string\n  - `price`: integer\n  - `qty`: integer\n  - `amount`: integer\n\n**Rules**\n1. When the user requests, create new rows in Google Sheets with the above columns and types.\n2. Do not modify or delete existing rows in Google Sheets; only add or create new rows.\n3. Ensure that:\n   - `price`, `qty`, and `amount` are integers only.\n   - `date` must be a valid date in the format `yyyy-mm-dd`.\n   - `item`, `cat`, and `unit` are strings.\n4. Use data validation rules in Google Sheets to enforce these data types and formats for each column.\n5. If the input does not match the required type or format, reject the input and prompt the user to correct it.\n\n**Example Row**\n| date      | item      | cat      | unit   | price | qty | amount |\n|-----------|-----------|----------|--------|-------|-----|--------|\n| 25/05/01  | Apple     | Fruit    | kg     | 3000  | 2   | 6000   |\n\n**Additional Notes**\n- Always validate the data before adding to the sheet.\n- Only allow data entry that matches the specified column types and formats.\n"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.9,
      "position": [
        220,
        0
      ],
      "id": "724e43b5-da75-4d19-ab4d-0c609c3ff3e3",
      "name": "AI Agent"
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1MBQqwE8mL_KiG-1jHvgGUg5Jr26l1nzoV4ShwNAZefk",
          "mode": "list",
          "cachedResultName": "test",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1MBQqwE8mL_KiG-1jHvgGUg5Jr26l1nzoV4ShwNAZefk/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1MBQqwE8mL_KiG-1jHvgGUg5Jr26l1nzoV4ShwNAZefk/edit#gid=0"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4.5,
      "position": [
        500,
        220
      ],
      "id": "5808b98c-85a7-4874-807e-ce7663001fb9",
      "name": "Google Sheets",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4.1-mini",
          "mode": "list",
          "cachedResultName": "gpt-4.1-mini"
        },
        "options": {
          "temperature": 0.2
        }
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        60,
        220
      ],
      "id": "58d00563-f19f-4b86-8837-196163eca963",
      "name": "OpenAI Chat Model",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {},
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.3,
      "position": [
        200,
        220
      ],
      "id": "492bd2c7-c2e0-4e0e-b5c7-cc277a8fa186",
      "name": "Simple Memory"
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1MBQqwE8mL_KiG-1jHvgGUg5Jr26l1nzoV4ShwNAZefk",
          "mode": "list",
          "cachedResultName": "test",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1MBQqwE8mL_KiG-1jHvgGUg5Jr26l1nzoV4ShwNAZefk/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1MBQqwE8mL_KiG-1jHvgGUg5Jr26l1nzoV4ShwNAZefk/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "date": "={{ $fromAI('date__using_to_match_', ``, 'string') }}",
            "item": "={{ $fromAI('item', ``, 'string') }}",
            "cat": "={{ $fromAI('cat', ``, 'string') }}",
            "unit": "={{ $fromAI('unit', ``, 'string') }}",
            "price": "={{ $fromAI('price', ``, 'string') }}",
            "qty": "={{ $fromAI('qty', ``, 'string') }}",
            "amount": "={{ $fromAI('amount', ``, 'string') }}"
          },
          "matchingColumns": [
            "date"
          ],
          "schema": [
            {
              "id": "date",
              "displayName": "date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "item",
              "displayName": "item",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "cat",
              "displayName": "cat",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "unit",
              "displayName": "unit",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "price",
              "displayName": "price",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "qty",
              "displayName": "qty",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "amount",
              "displayName": "amount",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4.5,
      "position": [
        380,
        220
      ],
      "id": "017c9196-a8b6-42d0-97bd-d3a9db1d0c97",
      "name": "Google Sheets1",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "When chat message received": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets1": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "f126124d-0a8b-4330-a757-5019c239242c",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "RlZMTCPEodSpIKaf",
  "tags": []
}