{
  "name": "Outscraper - AI Agent lead qualification",
  "nodes": [
    {
      "parameters": {},
      "id": "7014be3d-d5d5-4f16-9559-f393f40c4ed1",
      "name": "Manual Trigger",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "query",
              "name": "query",
              "type": "string",
              "value": "dentists in Austin, TX"
            },
            {
              "id": "limit",
              "name": "limit",
              "type": "number",
              "value": 15
            }
          ]
        },
        "options": {}
      },
      "id": "53c3fe17-bee6-428a-97af-fb5d41348429",
      "name": "Set Search",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        224,
        0
      ]
    },
    {
      "parameters": {
        "query": "={{$json.query}}",
        "limit": "={{$json.limit}}",
        "requestOptions": {}
      },
      "id": "9959c73a-73f0-4615-9501-785106a0acf1",
      "name": "Outscraper - Google Maps Search",
      "type": "n8n-nodes-outscraper.outscraper",
      "typeVersion": 2,
      "position": [
        464,
        0
      ],
      "credentials": {
        "outscraperApi": {
          "id": "8AvSJfwIww0gbyf7",
          "name": "Outscraper account"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "function isLead(v){return v&&typeof v==='object'&&!Array.isArray(v)&&(v.name||v.title||v.place_id||v.google_id||v.location_link);} function collect(v,out=[]){if(!v)return out; if(Array.isArray(v)){for(const x of v)collect(x,out); return out;} if(isLead(v)){out.push(v); return out;} if(typeof v==='object'){for(const key of ['data','results','items','businesses']) if(key in v) collect(v[key],out);} return out;} const leads=$input.all().flatMap(i=>collect(i.json)).slice(0,15).map(l=>({name:l.name||l.title||'', website:l.website||l.site||'', phone:l.phone||'', address:l.address||l.full_address||'', rating:l.rating||null, reviews:l.reviews||l.reviews_count||null, category:l.category||l.type||l.subtypes||'', booking:l.booking_appointment_link||'', maps:l.location_link||''})); return [{json:{lead_count:leads.length, leads}}];"
      },
      "id": "b3d2d64c-10f9-425f-90f2-05348f6758ba",
      "name": "Normalize Leads for Agent",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        704,
        0
      ]
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=You are qualifying local business leads from Outscraper data. Rank by business quality, contact readiness, and outreach potential. Use the connected structured output parser and return only the requested JSON shape. Input JSON: {{ JSON.stringify($json) }}",
        "hasOutputParser": true,
        "options": {
          "enableStreaming": false
        }
      },
      "id": "a37e48eb-cd01-4d42-9287-15ba03f1aa6e",
      "name": "AI Agent - Lead Qualification",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [
        992,
        0
      ]
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-5.4-mini",
          "mode": "list",
          "cachedResultName": "gpt-5.4-mini"
        },
        "builtInTools": {},
        "options": {}
      },
      "id": "ea9346dc-9741-43ea-998f-65bd2de70e0c",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        944,
        224
      ],
      "credentials": {
        "openAiApi": {
          "id": "cF6D8w13EQm9nSZt",
          "name": "OpenAI account"
        }
      }
    },
    {
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"object\",\n  \"additionalProperties\": false,\n  \"required\": [\"summary\", \"best_leads\", \"weak_leads\", \"enrichment_needed\", \"recommended_next_step\"],\n  \"properties\": {\n    \"summary\": {\n      \"type\": \"string\"\n    },\n    \"best_leads\": {\n      \"type\": \"array\",\n      \"items\": {\n        \"type\": \"object\",\n        \"additionalProperties\": false,\n        \"required\": [\"name\", \"score\", \"reason\", \"outreach_angle\", \"website\", \"phone\"],\n        \"properties\": {\n          \"name\": { \"type\": \"string\" },\n          \"score\": { \"type\": \"number\" },\n          \"reason\": { \"type\": \"string\" },\n          \"outreach_angle\": { \"type\": \"string\" },\n          \"website\": { \"type\": \"string\" },\n          \"phone\": { \"type\": \"string\" }\n        }\n      }\n    },\n    \"weak_leads\": {\n      \"type\": \"array\",\n      \"items\": {\n        \"type\": \"object\",\n        \"additionalProperties\": false,\n        \"required\": [\"name\", \"reason\"],\n        \"properties\": {\n          \"name\": { \"type\": \"string\" },\n          \"reason\": { \"type\": \"string\" }\n        }\n      }\n    },\n    \"enrichment_needed\": {\n      \"type\": \"array\",\n      \"items\": {\n        \"type\": \"object\",\n        \"additionalProperties\": false,\n        \"required\": [\"name\", \"missing\", \"next_service\"],\n        \"properties\": {\n          \"name\": { \"type\": \"string\" },\n          \"missing\": {\n            \"type\": \"array\",\n            \"items\": { \"type\": \"string\" }\n          },\n          \"next_service\": { \"type\": \"string\" }\n        }\n      }\n    },\n    \"recommended_next_step\": { \"type\": \"string\" }\n  }\n}"
      },
      "id": "4d6b36a9-de88-4183-b4e9-a7ec599f786b",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.3,
      "position": [
        1184,
        224
      ]
    }
  ],
  "pinData": {},
  "connections": {
    "Manual Trigger": {
      "main": [
        [
          {
            "node": "Set Search",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Search": {
      "main": [
        [
          {
            "node": "Outscraper - Google Maps Search",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Outscraper - Google Maps Search": {
      "main": [
        [
          {
            "node": "Normalize Leads for Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Leads for Agent": {
      "main": [
        [
          {
            "node": "AI Agent - Lead Qualification",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent - Lead Qualification",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "AI Agent - Lead Qualification",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate"
  },
  "versionId": "a21f5ac7-a449-46d2-b7ea-16e4b8c53b57",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "bd51ba3d599fc63602ae14309acd27ef3912f3068784a786f28ba05657ba8dbb"
  },
  "id": "3SrvHBVlBNP25tK0",
  "tags": []
}
