{
  "name": "My workflow",
  "nodes": [
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "typeVersion": 1.1,
      "position": [
        80,
        64
      ],
      "id": "2abe41ec-3646-4181-b11b-8298c642630a",
      "name": "When chat message received"
    },
    {
      "parameters": {
        "options": {
          "systemMessage": "You are a research agent that helps find contact information from \nGoogle Maps or websites.\nAfter searching, save your results to Google Sheets.\nWhen \ndoing this, you must use this JSON format in a single call:\n[\n{\n  \"Name\": \"Company \nname\",\n  \"Address\": \"Company address\",\n  \"Number\": \"Company phone number\",\n  \n\"Website\": \"Company website\",\n  \"Rating\": \"Company rating\", \n  \"Opening Hours\": \n\"Company opening hours\",\n  \"Email\": \"Company email address\"\n},\n...\n]\n\nWhen \nsending the number to \"Add to Google Sheets\", remove the + at the beginning of each \nnumber.\n\nWhen going through multiple pages, call \"Add to Google Sheets\" after each \n\"Map Search\" call to save the data directly, without consolidating it.\n\nIf no email is found, \npass it as N/A to \"Add to Google Sheets\".\n\nKeep searching in Map Search until you find \nno more pages or results.",
          "maxIterations": 10
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.8,
      "position": [
        304,
        64
      ],
      "id": "8c635585-72e7-4596-abbc-5816e0738c30",
      "name": "AI Agent"
    },
    {
      "parameters": {},
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.3,
      "position": [
        400,
        288
      ],
      "id": "6e82ebbb-32bc-4f4f-8733-d3dbb8e360d1",
      "name": "Simple Memory"
    },
    {
      "parameters": {
        "toolDescription": "=This bot helps you extract all contact information for lead \ngeneration from Google Maps.\nInput parameters:\n\"q\" for the search term (e.g., \"Dental \nClinic Ahmedabad\").\n\"ll\" for geographic coordinates.\n\"page\" for the current search \nresults page.",
        "url": "https://google.serper.dev/maps",
        "sendQuery": true,
        "parametersQuery": {
          "values": [
            {
              "name": "q"
            },
            {
              "name": "ll",
              "valueProvider": "fieldValue",
              "value": "@23.233247,77.416724,13z"
            },
            {
              "name": "page",
              "valueProvider": "fieldValue",
              "value": "4"
            },
            {
              "name": "hl",
              "valueProvider": "fieldValue",
              "value": "en"
            },
            {
              "name": "location",
              "valueProvider": "fieldValue",
              "value": "India"
            },
            {
              "name": "gl",
              "valueProvider": "fieldValue",
              "value": "in"
            }
          ]
        },
        "sendHeaders": true,
        "parametersHeaders": {
          "values": [
            {
              "name": "X-API-KEY",
              "valueProvider": "fieldValue",
              "value": "a005d60f799985029d07e29076e7f4a28b72bce9"
            }
          ]
        }
      },
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "typeVersion": 1.1,
      "position": [
        560,
        288
      ],
      "id": "338b3003-081c-46a0-8b8c-33917fac8e12",
      "name": "Map Search Tool"
    },
    {
      "parameters": {
        "content": "Map Search Agent",
        "height": 500,
        "width": 900
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        0
      ],
      "typeVersion": 1,
      "id": "af738ea0-9674-4436-8dee-1c4f64efa2d9",
      "name": "Sticky Note"
    },
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "documentId": {
          "__rl": true,
          "value": "1f0HpYChdF_9EaestzV7xPBgOgVNq0owaBggf8J5NFWo",
          "mode": "list",
          "cachedResultName": "Leads Gen - AI Agent",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1f0HpYChdF_9EaestzV7xPBgOgVNq0owaBggf8J\n5NFWo/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1f0HpYChdF_9EaestzV7xPBgOgVNq0owaBggf8J\n5NFWo/edit#gid=0"
        },
        "event": "rowAdded",
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheetsTrigger",
      "typeVersion": 1,
      "position": [
        -96,
        528
      ],
      "id": "6a8ade3a-d95c-4ad9-a675-b24ccc5ab6ea",
      "name": "Google Sheets Trigger",
      "credentials": {
        "googleSheetsTriggerOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "b925ecd9-541f-4d3c-9bc1-0f683bd420cc",
              "leftValue": "={{ $json.Name }}",
              "rightValue": "Name",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              }
            },
            {
              "id": "e241db34-fd92-468e-802d-b4485d260b85",
              "leftValue": "={{ $json.Name }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.2,
      "position": [
        128,
        528
      ],
      "id": "cf7ceb03-a704-4032-812d-aec001021026",
      "name": "Filter"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        352,
        528
      ],
      "id": "7b68790a-435c-4d15-8936-8da46d96ed3c",
      "name": "Loop Over Items"
    },
    {
      "parameters": {
        "jsCode": "const items = $input.all()[0].json.choices[0].message.content;\nconst \ncleaned = items.replace('```json', '').replace('```', '')\nconst parsed = \nJSON.parse(cleaned);\n\nreturn { data: parsed }"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        592,
        544
      ],
      "id": "d548b2f5-06d1-4deb-a3a8-b91b6a8e468a",
      "name": "Code"
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "value": "1f0HpYChdF_9EaestzV7xPBgOgVNq0owaBggf8J5NFWo",
          "mode": "list",
          "cachedResultName": "Leads Gen - AI Agent",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1f0HpYChdF_9EaestzV7xPBgOgVNq0owaBggf8J\n5NFWo/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1f0HpYChdF_9EaestzV7xPBgOgVNq0owaBggf8J\n5NFWo/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Email": "={{ $json.data.email }}",
            "Background": "={{ $json.data.background }}",
            "UUID": "={{ $('Loop Over Items').item.json.UUID }}"
          },
          "matchingColumns": [
            "UUID"
          ],
          "schema": [
            {
              "id": "UUID",
              "displayName": "UUID",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Name",
              "displayName": "Name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "Address",
              "displayName": "Address",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "Number",
              "displayName": "Number",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "Website",
              "displayName": "Website",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "Rating",
              "displayName": "Rating",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "Opening Hours",
              "displayName": "Opening Hours",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "Email",
              "displayName": "Email",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Background",
              "displayName": "Background",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "displayName": "row_number",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "readOnly": true,
              "removed": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        800,
        544
      ],
      "id": "c1df23ef-309b-45c5-9139-664bfd83271c",
      "name": "Google Sheets",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "inputSource": "passthrough"
      },
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1.1,
      "position": [
        64,
        864
      ],
      "id": "1513813f-2f24-45a4-8f0f-388efbd6a7eb",
      "name": "When Executed by Another Workflow"
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1f0HpYChdF_9EaestzV7xPBgOgVNq0owaBggf8J5NFWo",
          "mode": "list",
          "cachedResultName": "Leads Gen - AI Agent",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1f0HpYChdF_9EaestzV7xPBgOgVNq0owaBggf8J\n5NFWo/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1f0HpYChdF_9EaestzV7xPBgOgVNq0owaBggf8J\n5NFWo/edit#gid=0"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {},
          "matchingColumns": [],
          "schema": [
            {
              "id": "UUID",
              "displayName": "UUID",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Name",
              "displayName": "Name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Address",
              "displayName": "Address",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Number",
              "displayName": "Number",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Website",
              "displayName": "Website",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Rating",
              "displayName": "Rating",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Opening Hours",
              "displayName": "Opening Hours",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Email",
              "displayName": "Email",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        512,
        864
      ],
      "id": "f54bda60-2459-437c-8bbb-eb58c132ddf4",
      "name": "Google Sheets1",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const v7 = () => {\n  return \n'tttttttt-tttt-7xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c){\n    const r = \nMath.trunc(Math.random() * 16);\n    const v = c == 'x' ? r : (r & 0x3 | 0x8);\n    return \nv.toString(16);\n  }).replace(/[t]{8}-[t]{4}/, function (){\n    const unixtimestamp = \nDate.now().toString(16).padStart(12, '0');\n    return unixtimestamp.slice(0, 8) + '-' + \nunixtimestamp.slice(8);\n  })\n}\n\nconst data = \nJSON.parse($input.all()[0].json.query);\nconst datawithId = data.map(i => {\n  const uuid = \nv7();\n  return { UUID: uuid, ... i}\n});\n\nreturn datawithId;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        288,
        864
      ],
      "id": "29bdd62d-1d7d-425a-baea-db3a201dd9f4",
      "name": "Code2"
    },
    {
      "parameters": {
        "jsCode": "return { json: { response: \"ok \"}}"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        688,
        864
      ],
      "id": "40fc5623-8253-4d04-9a96-bdcd0c61251a",
      "name": "Code1"
    },
    {
      "parameters": {
        "content": "Keep this subworkflow in different workflow",
        "height": 320,
        "width": 940,
        "color": 4
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        784
      ],
      "typeVersion": 1,
      "id": "a11e942a-4386-4337-a014-b0afa26219c0",
      "name": "Sticky Note1"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "typeVersion": 1,
      "position": [
        176,
        272
      ],
      "id": "be6db887-fb32-4ce9-b050-ce535c7bd737",
      "name": "Google Gemini Chat Model",
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "name": "store_to_google_sheets",
        "description": "=This is a tool to analyze the input and store it in Google Sheets \ncolumns, including:\n{\n  \"Name\": xxx,\n  \"Address\": xxx,\n  \"Number\": xxx,\n  \n\"Website\": xxx,\n  \"Rating\": xxx,\n  \"Opening Hours\": xxx,\n  \"Email\": xxx\n}",
        "workflowId": {
          "__rl": true,
          "value": "K7uNaGXGdvgq0Y6f",
          "mode": "list",
          "cachedResultName": "My workflow"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {},
          "matchingColumns": [],
          "schema": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      },
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "typeVersion": 2,
      "position": [
        768,
        288
      ],
      "id": "8b96a98d-804b-4313-bcb6-0165b8e49a5e",
      "name": "Call 'My workflow'"
    }
  ],
  "connections": {
    "When chat message received": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Map Search Tool": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets Trigger": {
      "main": [
        [
          {
            "node": "Filter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code": {
      "main": [
        [
          {
            "node": "Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When Executed by Another Workflow": {
      "main": [
        [
          {
            "node": "Code2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets1": {
      "main": [
        [
          {
            "node": "Code1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code2": {
      "main": [
        [
          {
            "node": "Google Sheets1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Call 'My workflow'": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "e2ef9f90-8638-4586-b29b-0dd168afc3d3",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "K7uNaGXGdvgq0Y6f",
  "tags": []
}