{
  "id": "stAU9U3aFNMiUcuS",
  "name": "AI-Powered Lead Aggregation, Enrichment, and Intelligent Agent Routing System",
  "tags": [],
  "nodes": [
    {
      "id": "290bbc1f-6438-486b-a093-1bb4e138b597",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -1648,
        896
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 9
            }
          ]
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "ad313f80-67c1-4dcb-a78f-2182c5c730b5",
      "name": "Workflow Configuration",
      "type": "n8n-nodes-base.set",
      "position": [
        -1424,
        896
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "id-1",
              "name": "mlsApiUrl",
              "type": "string",
              "value": "<__PLACEHOLDER_VALUE__MLS API endpoint URL__>"
            },
            {
              "id": "id-2",
              "name": "crmApiUrl",
              "type": "string",
              "value": "<__PLACEHOLDER_VALUE__CRM API endpoint URL__>"
            },
            {
              "id": "id-3",
              "name": "highPriorityThreshold",
              "type": "number",
              "value": 75
            },
            {
              "id": "id-4",
              "name": "enrichmentApiKey",
              "type": "string",
              "value": "<__PLACEHOLDER_VALUE__Enrichment API key__>"
            },
            {
              "id": "id-5",
              "name": "propertyApiUrl",
              "type": "string",
              "value": "<__PLACEHOLDER_VALUE__Property API endpoint URL__>"
            },
            {
              "id": "id-6",
              "name": "agentApiUrl",
              "type": "string",
              "value": "<__PLACEHOLDER_VALUE__Agent performance API endpoint__>"
            },
            {
              "id": "id-7",
              "name": "slackChannel",
              "type": "string",
              "value": "<__PLACEHOLDER_VALUE__Slack channel ID for high priority leads__>"
            },
            {
              "id": "id-8",
              "name": "databaseTable",
              "type": "string",
              "value": "<__PLACEHOLDER_VALUE__Database table name for leads__>"
            },
            {
              "id": "id-9",
              "name": "senderEmail",
              "type": "string",
              "value": "<__PLACEHOLDER_VALUE__Sender email address__>"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "8345cc83-efc2-4bff-ae28-33d9c185f710",
      "name": "Fetch Leads from MLS/Portals",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1200,
        800
      ],
      "parameters": {
        "url": "={{ $('Workflow Configuration').first().json.mlsApiUrl }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "json"
            }
          }
        },
        "sendHeaders": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "<__PLACEHOLDER_VALUE__MLS API Bearer YOUR_TOKEN_HERE>"
            }
          ]
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "ea502191-3352-4b8e-8815-990421846b7f",
      "name": "Fetch Leads from CRM/Email/Social",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1200,
        992
      ],
      "parameters": {
        "url": "={{ $('Workflow Configuration').first().json.crmApiUrl }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "json"
            }
          }
        },
        "sendHeaders": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "<__PLACEHOLDER_VALUE__CRM API Bearer YOUR_TOKEN_HERE>"
            }
          ]
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "8168dad0-bea9-4a7a-a377-c811ed8ad431",
      "name": "Merge All Lead Sources",
      "type": "n8n-nodes-base.merge",
      "position": [
        -976,
        896
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "combineBy": "combineByPosition"
      },
      "typeVersion": 3.2
    },
    {
      "id": "d874d5e4-d679-4d0d-93fd-dcc4e400e2b4",
      "name": "Lead Enrichment Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -752,
        768
      ],
      "parameters": {
        "text": "={{ $json }}",
        "options": {
          "systemMessage": "You are a lead enrichment specialist for real estate.\n\nYour task is to:\n1. Analyze the provided lead data (name, email, phone, location, property interest)\n2. Enrich the lead with demographic insights (age range, income bracket, family status)\n3. Add behavioral scoring based on engagement patterns (email opens, website visits, property views)\n4. Identify social media presence indicators\n5. Return enriched data in the structured JSON format\n\nProvide comprehensive enrichment to help agents understand lead quality and potential."
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 3.1
    },
    {
      "id": "7126042c-a737-495e-ba50-c55350869faf",
      "name": "OpenAI Model - Enrichment",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -752,
        992
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "e4a8cfaa-bc2a-4aff-b1ee-5534310ae8b1",
      "name": "Structured Output - Enriched Lead Data",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        -624,
        992
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"leadId\": {\"type\": \"string\"},\n    \"name\": {\"type\": \"string\"},\n    \"email\": {\"type\": \"string\"},\n    \"phone\": {\"type\": \"string\"},\n    \"demographics\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"ageRange\": {\"type\": \"string\"},\n        \"incomeBracket\": {\"type\": \"string\"},\n        \"familyStatus\": {\"type\": \"string\"}\n      }\n    },\n    \"socialPresence\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"linkedin\": {\"type\": \"boolean\"},\n        \"facebook\": {\"type\": \"boolean\"},\n        \"instagram\": {\"type\": \"boolean\"}\n      }\n    },\n    \"behavioralData\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"emailEngagement\": {\"type\": \"number\"},\n        \"websiteVisits\": {\"type\": \"number\"},\n        \"propertyViews\": {\"type\": \"number\"}\n      }\n    }\n  }\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "95b84d67-4689-4627-a474-9c557a8fae1a",
      "name": "Agent Routing Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        768,
        480
      ],
      "parameters": {
        "text": "={{ $json }}",
        "options": {
          "systemMessage": "You are an intelligent agent routing specialist for real estate.\n\nYour task is to:\n1. Analyze the scored lead data including conversion score, priority level, and indicators\n2. Match leads to the best-fit agent based on:\n   - Agent specialization (luxury, first-time buyers, commercial, etc.)\n   - Agent performance metrics and success rates\n   - Agent current workload and capacity\n   - Geographic territory alignment\n   - Lead characteristics and preferences\n3. Provide routing rationale\n4. Return routing decision in structured JSON format\n\nOptimize for both lead conversion potential and agent efficiency."
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 3.1
    },
    {
      "id": "2374dd45-4634-4974-a6db-275ad58261bc",
      "name": "OpenAI Model - Routing",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        528,
        704
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "f17ef1f6-cdbd-4e3c-8de7-4bd0d0f09e2c",
      "name": "Structured Output - Routing Decision",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        1104,
        768
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"leadId\": {\"type\": \"string\"},\n    \"assignedAgent\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"agentId\": {\"type\": \"string\"},\n        \"agentName\": {\"type\": \"string\"},\n        \"specialization\": {\"type\": \"string\"},\n        \"matchScore\": {\"type\": \"number\"}\n      }\n    },\n    \"routingRationale\": {\"type\": \"string\"},\n    \"alternativeAgents\": {\n      \"type\": \"array\",\n      \"items\": {\n        \"type\": \"object\",\n        \"properties\": {\n          \"agentId\": {\"type\": \"string\"},\n          \"agentName\": {\"type\": \"string\"},\n          \"matchScore\": {\"type\": \"number\"}\n        }\n      }\n    }\n  }\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "36d703fd-e6e0-4001-b1f6-0a4e3e650c6e",
      "name": "Lead Scoring Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        192,
        512
      ],
      "parameters": {
        "text": "={{ $json }}",
        "options": {
          "systemMessage": "You are a lead scoring specialist for real estate.\n\nYour task is to:\n1. Analyze the enriched lead data including demographics, social presence, and behavioral patterns\n2. Calculate a conversion probability score (0-100) based on:\n   - Engagement level (email opens, website visits, property views)\n   - Demographics alignment with target buyer profile\n   - Social media presence and activity\n   - Property interest match with inventory\n3. Identify key conversion indicators\n4. Assign priority level (High, Medium, Low)\n5. Return scoring results in structured JSON format\n\nBe data-driven and objective in your scoring methodology."
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 3.1
    },
    {
      "id": "773cca87-54fc-4c6a-81f1-8cb39c711422",
      "name": "OpenAI Model - Scoring",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        192,
        704
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "ac3c4afe-83ff-43fd-b68c-5443c9abfeb3",
      "name": "Structured Output - Lead Score",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        352,
        752
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"leadId\": {\"type\": \"string\"},\n    \"conversionScore\": {\"type\": \"number\"},\n    \"priorityLevel\": {\"type\": \"string\", \"enum\": [\"High\", \"Medium\", \"Low\"]},\n    \"conversionIndicators\": {\n      \"type\": \"array\",\n      \"items\": {\"type\": \"string\"}\n    },\n    \"scoringFactors\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"engagementScore\": {\"type\": \"number\"},\n        \"demographicMatch\": {\"type\": \"number\"},\n        \"socialScore\": {\"type\": \"number\"}\n      }\n    }\n  }\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "f573f9bc-6a12-4f9a-8e3c-2886ec5a8142",
      "name": "High-Priority Lead Filter",
      "type": "n8n-nodes-base.if",
      "position": [
        1728,
        480
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": false,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "id-1",
              "operator": {
                "type": "number",
                "operation": "gte"
              },
              "leftValue": "={{ $json.conversionScore }}",
              "rightValue": "={{ $('Workflow Configuration').first().json.highPriorityThreshold }}"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "b4d2fe51-c433-4b59-9a34-cc7b41bbc946",
      "name": "Prepare High-Priority Lead Data",
      "type": "n8n-nodes-base.set",
      "position": [
        2016,
        736
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "id-1",
              "name": "priority",
              "type": "string",
              "value": "HIGH"
            },
            {
              "id": "id-2",
              "name": "notificationUrgency",
              "type": "string",
              "value": "immediate"
            },
            {
              "id": "id-3",
              "name": "followUpWindow",
              "type": "string",
              "value": "24 hours"
            },
            {
              "id": "id-4",
              "name": "assignmentTimestamp",
              "type": "string",
              "value": "={{ $now.toISO() }}"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "ffd1bda8-b27b-4126-8bd7-c63a5b3414c2",
      "name": "Prepare Standard Lead Data",
      "type": "n8n-nodes-base.set",
      "position": [
        2240,
        1120
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "id-1",
              "name": "priority",
              "type": "string",
              "value": "STANDARD"
            },
            {
              "id": "id-2",
              "name": "notificationUrgency",
              "type": "string",
              "value": "normal"
            },
            {
              "id": "id-3",
              "name": "followUpWindow",
              "type": "string",
              "value": "72 hours"
            },
            {
              "id": "id-4",
              "name": "assignmentTimestamp",
              "type": "string",
              "value": "={{ $now.toISO() }}"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "29da799a-3067-4207-bd81-b2d626ad36d8",
      "name": "Track Engagement Metrics",
      "type": "n8n-nodes-base.set",
      "position": [
        2464,
        768
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "id-1",
              "name": "touchpointCount",
              "type": "number",
              "value": 1
            },
            {
              "id": "id-2",
              "name": "lastEngagementDate",
              "type": "string",
              "value": "={{ $now.toISO() }}"
            },
            {
              "id": "id-3",
              "name": "engagementChannel",
              "type": "string",
              "value": "lead_aggregation"
            },
            {
              "id": "id-4",
              "name": "workflowStage",
              "type": "string",
              "value": "routed_to_agent"
            },
            {
              "id": "id-5",
              "name": "roiTrackingId",
              "type": "string",
              "value": "={{ $('Lead Enrichment Agent').item.json.leadId }}_{{ $now.toMillis() }}"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "25360dbc-0b63-4e3d-b3d3-378532b8dade",
      "name": "Loop Over Leads",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        3408,
        1248
      ],
      "parameters": {
        "options": {},
        "batchSize": 10
      },
      "typeVersion": 3
    },
    {
      "id": "1483377b-6735-46fe-8e47-61cc0155cc98",
      "name": "Lead Sentiment Analysis",
      "type": "@n8n/n8n-nodes-langchain.sentimentAnalysis",
      "position": [
        -400,
        768
      ],
      "parameters": {
        "options": {
          "categories": "Positive, Neutral, Negative, Urgent"
        },
        "inputText": "={{ $json.email }} {{ $json.phone }} {{ $json.name }}"
      },
      "typeVersion": 1.1
    },
    {
      "id": "6c8b460a-1b93-4385-8312-bb89e65cab48",
      "name": "OpenAI Model - Sentiment",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -336,
        1056
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "8ef35ea0-d287-4c67-a16a-69b718fe4a8a",
      "name": "Lead Knowledge Base - Insert",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreInMemory",
      "position": [
        2720,
        768
      ],
      "parameters": {
        "mode": "insert",
        "memoryKey": {
          "__rl": true,
          "mode": "id",
          "value": "lead_history"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "f1ac819b-b8e0-4719-ae8a-0e1fb2e81932",
      "name": "Embeddings OpenAI - Insert",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        2688,
        992
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "753ec094-6a96-48ed-ad4b-e0bf80e772dd",
      "name": "Document Loader - Lead Data",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        2816,
        992
      ],
      "parameters": {
        "options": {},
        "textSplittingMode": "custom"
      },
      "typeVersion": 1.1
    },
    {
      "id": "79c5d5c4-8173-4403-bafa-7af6c8394064",
      "name": "Text Splitter - Recursive",
      "type": "@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter",
      "position": [
        2896,
        1200
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "1c34a407-eef4-4307-9fbe-b12f56a8f08c",
      "name": "Lead Knowledge Base - Retrieve",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreInMemory",
      "position": [
        656,
        704
      ],
      "parameters": {
        "mode": "retrieve-as-tool",
        "memoryKey": {
          "__rl": true,
          "mode": "id",
          "value": "lead_history"
        },
        "toolDescription": "Query historical lead data and past interactions to inform routing decisions"
      },
      "typeVersion": 1.3
    },
    {
      "id": "80a942cd-a6c7-42c3-9324-04ed808fd6fb",
      "name": "Embeddings OpenAI - Retrieve",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        736,
        912
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "52d13f50-7a80-49f9-8daf-f25d31982054",
      "name": "HTTP Request Tool - Property Data",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        944,
        704
      ],
      "parameters": {
        "url": "<__PLACEHOLDER_VALUE__Property API endpoint URL__>",
        "options": {},
        "toolDescription": "Fetch current property listings and market data based on lead preferences"
      },
      "typeVersion": 4.3
    },
    {
      "id": "50fd95ce-5504-4140-859b-f4da6129a207",
      "name": "Store Lead in Database",
      "type": "n8n-nodes-base.postgres",
      "position": [
        3184,
        768
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "<__PLACEHOLDER_VALUE__Database table name for leads__>"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": null,
          "mappingMode": "autoMapInputData"
        },
        "options": {}
      },
      "typeVersion": 2.6
    },
    {
      "id": "ad529fbb-fe99-484c-bf87-afd611213842",
      "name": "Notify Slack - High Priority",
      "type": "n8n-nodes-base.slack",
      "position": [
        2240,
        592
      ],
      "parameters": {
        "text": "=High Priority Lead Alert: {{ $json.name }} (Score: {{ $json.conversionScore }})\nAssigned to: {{ $json.assignedAgent.agentName }}\nRationale: {{ $json.routingRationale }}",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "id",
          "value": "<__PLACEHOLDER_VALUE__Slack channel ID for high priority leads__>"
        },
        "otherOptions": {},
        "authentication": "oAuth2"
      },
      "credentials": {
        "slackOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.4
    },
    {
      "id": "f7ab2208-e9c5-4d81-bedd-6af2bdea693d",
      "name": "Send Email - Agent Assignment",
      "type": "n8n-nodes-base.emailSend",
      "position": [
        2240,
        928
      ],
      "parameters": {
        "text": "=You have been assigned a high-priority lead:\n\nName: {{ $json.name }}\nEmail: {{ $json.email }}\nPhone: {{ $json.phone }}\nConversion Score: {{ $json.conversionScore }}\n\nRouting Rationale: {{ $json.routingRationale }}\n\nPlease follow up within {{ $json.followUpWindow }}.",
        "options": {},
        "subject": "=New High-Priority Lead Assignment: {{ $json.name }}",
        "toEmail": "={{ $json.assignedAgent.agentEmail }}",
        "fromEmail": "<__PLACEHOLDER_VALUE__Sender email address__>",
        "emailFormat": "text"
      },
      "typeVersion": 2.1
    },
    {
      "id": "187aee6a-82df-42f3-a5ef-516e0b403dd2",
      "name": "Aggregate Daily Lead Stats",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        3632,
        1248
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData"
      },
      "typeVersion": 1
    },
    {
      "id": "0bcca2c8-488e-4dd6-a457-9948677b279f",
      "name": "Fetch Agent Performance Data",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1280,
        832
      ],
      "parameters": {
        "url": "<__PLACEHOLDER_VALUE__Agent performance API endpoint__>",
        "options": {},
        "sendHeaders": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "<__PLACEHOLDER_VALUE__Agent API Bearer YOUR_TOKEN_HERE>"
            }
          ]
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "5e7f85de-1338-4869-89c0-b226a2be5bfe",
      "name": "Merge Lead with Agent Data",
      "type": "n8n-nodes-base.set",
      "position": [
        1504,
        832
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "id-1",
              "name": "agentPerformanceData",
              "type": "string",
              "value": "={{ $json }}"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "a126842c-37f9-4c6c-9946-5992a21d916c",
      "name": "Check Sentiment Score",
      "type": "n8n-nodes-base.if",
      "position": [
        -48,
        768
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": false,
            "typeValidation": "loose"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "id-1",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $('Lead Sentiment Analysis').item.json.sentimentCategory }}",
              "rightValue": "Negative"
            },
            {
              "id": "id-2",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $('Lead Sentiment Analysis').item.json.sentimentCategory }}",
              "rightValue": "Urgent"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "37909773-76c7-4280-816a-9e9ebf5cb63e",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        0
      ],
      "parameters": {
        "color": 6,
        "width": 576,
        "height": 352,
        "content": "## Prerequisites\nActive AI API accounts (OpenAI/Anthropic), e-commerce platform with webhook support\n## Use Cases\nMulti-channel order fulfillment, subscription box processing, drop-shipping automation\n## Customization\nModify validation rules for business-specific requirements, add custom fraud scoring algorithms\n## Benefits\nReduces order processing time by 85%, eliminates manual validation errors"
      },
      "typeVersion": 1
    },
    {
      "id": "0bdfee37-e626-418d-95a6-e4a5e9449e78",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -576,
        64
      ],
      "parameters": {
        "width": 528,
        "height": 272,
        "content": "## Setup Steps\n\n1. Configure webhook endpoint for e-commerce platform order integration\n2. Set up AI model credentials (OpenAI/Anthropic) for validation agents\n3. Connect inventory management system API in stock checking nodes\n4. Configure fraud detection service integration with API credentials\n5. Set up payment gateway API connections with secure credentials\n6. Integrate shipping carrier APIs for label generation and tracking\n7. Configure e-commerce platform API for order status updates\n8. Connect email service credentials for customer notifications"
      },
      "typeVersion": 1
    },
    {
      "id": "c498aa38-0121-4957-9420-a7f4fc752558",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1568,
        80
      ],
      "parameters": {
        "width": 928,
        "height": 256,
        "content": "## How It Works\nThis workflow automates end-to-end e-commerce order processing from intake through fulfillment by orchestrating multiple AI-powered validation stages and external system integrations. Designed for e-commerce operations managers, customer service teams, and fulfillment centers, it solves the complex challenge of processing orders accurately while managing inventory, fraud detection, payment verification, and shipping coordination across multiple systems. The system receives orders via webhook, validates customer information and order details through AI agents, checks inventory availability, performs fraud screening, processes payments, generates shipping labels, updates order status across platforms, sends customer notifications, and logs all activities for audit compliance. The workflow leverages multiple AI models and specialized tools to ensure each order proceeds through appropriate validation gates before fulfillment."
      },
      "typeVersion": 1
    },
    {
      "id": "d0b85eee-3a14-4188-bdc9-b89f90327a58",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1920,
        384
      ],
      "parameters": {
        "color": 7,
        "width": 1910,
        "height": 1120,
        "content": "## Fulfillment Orchestration and Status Communication\n**Why:** Updates order status across integrated e-commerce platforms, triggers warehouse management systems for picking/packing, sends real-time email notifications to customers with tracking information, logs complete transaction history to compliance database, ensuring coordinated fulfillment and transparent customer communication."
      },
      "typeVersion": 1
    },
    {
      "id": "0d6f22d3-9ee2-4b9b-bcca-f1bb12c3c4d1",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        160,
        400
      ],
      "parameters": {
        "color": 7,
        "width": 1728,
        "height": 1040,
        "content": "\n## Fraud Detection and Payment Processing\n**Why:** Routes orders through fraud screening agents that analyze transaction patterns and risk indicators, processes verified payments through secure gateways, generates appropriate shipping documentation using carrier APIs, preventing fraudulent transactions while enabling legitimate order fulfillment without manual intervention."
      },
      "typeVersion": 1
    },
    {
      "id": "5c240f6d-3844-46dd-bd7e-e49fe1690102",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1680,
        400
      ],
      "parameters": {
        "color": 7,
        "width": 1808,
        "height": 896,
        "content": "## Order Intake and Multi-Stage AI Validation\n**Why:** Captures incoming orders through webhook, deploys AI agents equipped with validation tools to verify customer information accuracy, validate order details against business rules, check product availability through inventory systems, ensuring only valid, complete orders proceed to payment processing."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "availableInMCP": false,
    "executionOrder": "v1"
  },
  "versionId": "85542e54-8ceb-43ca-a3f3-5ab57299cca7",
  "connections": {
    "Loop Over Leads": {
      "main": [
        [
          {
            "node": "Aggregate Daily Lead Stats",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Lead Enrichment Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Workflow Configuration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Lead Scoring Agent": {
      "main": [
        [
          {
            "node": "Agent Routing Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Agent Routing Agent": {
      "main": [
        [
          {
            "node": "High-Priority Lead Filter",
            "type": "main",
            "index": 0
          },
          {
            "node": "Fetch Agent Performance Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Sentiment Score": {
      "main": [
        [
          {
            "node": "Lead Scoring Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Lead Enrichment Agent": {
      "main": [
        [
          {
            "node": "Lead Scoring Agent",
            "type": "main",
            "index": 0
          },
          {
            "node": "Lead Sentiment Analysis",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge All Lead Sources": {
      "main": [
        [
          {
            "node": "Lead Enrichment Agent",
            "type": "main",
            "index": 0
          },
          {
            "node": "Loop Over Leads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Model - Routing": {
      "ai_languageModel": [
        [
          {
            "node": "Agent Routing Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Model - Scoring": {
      "ai_languageModel": [
        [
          {
            "node": "Lead Scoring Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Store Lead in Database": {
      "main": [
        [
          {
            "node": "Loop Over Leads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Workflow Configuration": {
      "main": [
        [
          {
            "node": "Fetch Leads from MLS/Portals",
            "type": "main",
            "index": 0
          },
          {
            "node": "Fetch Leads from CRM/Email/Social",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Lead Sentiment Analysis": {
      "main": [
        [
          {
            "node": "Check Sentiment Score",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Model - Sentiment": {
      "ai_languageModel": [
        [
          {
            "node": "Lead Sentiment Analysis",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Track Engagement Metrics": {
      "main": [
        [
          {
            "node": "Lead Knowledge Base - Insert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "High-Priority Lead Filter": {
      "main": [
        [
          {
            "node": "Prepare High-Priority Lead Data",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Prepare Standard Lead Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Model - Enrichment": {
      "ai_languageModel": [
        [
          {
            "node": "Lead Enrichment Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Text Splitter - Recursive": {
      "ai_textSplitter": [
        [
          {
            "node": "Document Loader - Lead Data",
            "type": "ai_textSplitter",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI - Insert": {
      "ai_embedding": [
        [
          {
            "node": "Lead Knowledge Base - Insert",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Merge Lead with Agent Data": {
      "main": [
        [
          {
            "node": "High-Priority Lead Filter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Standard Lead Data": {
      "main": [
        [
          {
            "node": "Track Engagement Metrics",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Document Loader - Lead Data": {
      "ai_document": [
        [
          {
            "node": "Lead Knowledge Base - Insert",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI - Retrieve": {
      "ai_embedding": [
        [
          {
            "node": "Lead Knowledge Base - Retrieve",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Agent Performance Data": {
      "main": [
        [
          {
            "node": "Merge Lead with Agent Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Leads from MLS/Portals": {
      "main": [
        [
          {
            "node": "Merge All Lead Sources",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Lead Knowledge Base - Insert": {
      "main": [
        [
          {
            "node": "Store Lead in Database",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Notify Slack - High Priority": {
      "main": [
        [
          {
            "node": "Track Engagement Metrics",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Email - Agent Assignment": {
      "main": [
        [
          {
            "node": "Track Engagement Metrics",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Lead Knowledge Base - Retrieve": {
      "ai_tool": [
        [
          {
            "node": "Agent Routing Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output - Lead Score": {
      "ai_outputParser": [
        [
          {
            "node": "Lead Scoring Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Prepare High-Priority Lead Data": {
      "main": [
        [
          {
            "node": "Track Engagement Metrics",
            "type": "main",
            "index": 0
          },
          {
            "node": "Notify Slack - High Priority",
            "type": "main",
            "index": 0
          },
          {
            "node": "Send Email - Agent Assignment",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Leads from CRM/Email/Social": {
      "main": [
        [
          {
            "node": "Merge All Lead Sources",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "HTTP Request Tool - Property Data": {
      "ai_tool": [
        [
          {
            "node": "Agent Routing Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output - Routing Decision": {
      "ai_outputParser": [
        [
          {
            "node": "Agent Routing Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output - Enriched Lead Data": {
      "ai_outputParser": [
        [
          {
            "node": "Lead Enrichment Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    }
  }
}