{
  "name": "Human In The Loop Lead Responder",
  "nodes": [
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "authentication": "airtableTokenApi",
        "baseId": {
          "__rl": true,
          "value": "RECONNECT_AIRTABLE_BASE_ID",
          "mode": "id"
        },
        "tableId": {
          "__rl": true,
          "value": "RECONNECT_AIRTABLE_TABLE_ID",
          "mode": "id"
        },
        "triggerField": "Instance",
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.airtableTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ],
      "id": "74c51c41-525f-4e52-97ad-1d70d75130bc",
      "name": "Airtable Trigger"
    },
    {
      "parameters": {
        "operation": "search",
        "base": {
          "__rl": true,
          "value": "RECONNECT_AIRTABLE_BASE_ID",
          "mode": "list",
          "cachedResultName": "Human in the loop",
          "cachedResultUrl": ""
        },
        "table": {
          "__rl": true,
          "value": "RECONNECT_PROJECTS_TABLE_ID",
          "mode": "list",
          "cachedResultName": "Projects",
          "cachedResultUrl": ""
        },
        "options": {}
      },
      "type": "n8n-nodes-base.airtableTool",
      "typeVersion": 2.2,
      "position": [
        320,
        304
      ],
      "id": "32f5cbcf-ca5a-4f6d-8df2-358449e7d0e4",
      "name": "Project DB"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "a42b8379-72d1-4f56-a7aa-fde0d6f2bac7",
              "name": "subject",
              "value": "={{ $json.output.subject }}",
              "type": "string"
            },
            {
              "id": "866c7bf8-2c39-4473-93d7-31103eb7d918",
              "name": "email",
              "value": "={{ $json.output.email }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.5,
      "position": [
        592,
        -16
      ],
      "id": "1296b3bb-d987-4fc0-ae89-22654c671e3b",
      "name": "Edit Fields"
    },
    {
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"subject\": {\n      \"type\": \"string\",\n      \"description\": \"The subject line of the email\"\n    },\n    \"email\": {\n      \"type\": \"string\",\n      \"description\": \"The body content of the email\"\n    }\n  },\n  \"required\": [\"subject\", \"email\"]\n}\n",
        "autoFix": true
      },
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.3,
      "position": [
        464,
        368
      ],
      "id": "39956b8d-e316-46e9-9979-1e6eb25a4105",
      "name": "Structured Output Parser"
    },
    {
      "parameters": {
        "model": "gpt-oss:120b",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOllama",
      "typeVersion": 1,
      "position": [
        800,
        320
      ],
      "id": "1ae96313-f0a5-4aa1-a722-08261c4b5c55",
      "name": "Ollama Chat Model"
    },
    {
      "parameters": {
        "model": "gpt-oss:120b",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOllama",
      "typeVersion": 1,
      "position": [
        464,
        544
      ],
      "id": "3a7fab4d-5759-45ea-a8f6-cc3f7cbbf4b2",
      "name": "Ollama Chat Model1"
    },
    {
      "parameters": {
        "operation": "sendAndWait",
        "sendTo": "your-email@example.com",
        "subject": "=APPROVAL REQUIRED - New Lead ({{ $('Airtable Trigger').item.json.fields.Name }})",
        "message": "={{ $('Airtable Trigger').item.json.fields.Name }} from {{ $('Airtable Trigger').item.json.fields.CompanyName }} is looking for {{ $('Airtable Trigger').item.json.fields.Intent }}. Their budget is {{ $('Airtable Trigger').item.json.fields.Budget }} with a specific timeline of {{ $('Airtable Trigger').item.json.fields.Timeline }}.\n\nPlease approve or decline the sending of this message generated by Mike, our Sales AI Agent.\n\nSubject: {{ $json.subject }}\n\nEmail: {{ $json.email }}",
        "responseType": "freeText",
        "options": {}
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.2,
      "position": [
        816,
        -16
      ],
      "id": "c5ce51f8-bc50-4870-bb60-892c17faab1a",
      "name": "gmail- get feedback"
    },
    {
      "parameters": {
        "inputText": "={{ $json.data.text }}",
        "categories": {
          "categories": [
            {
              "category": "approved",
              "description": "=The email has been reviewed and accepted as-is. The human explicitly or implicitly expresses approval, indicating that no changes are needed. \n\nExample phrases include:\n\n\"Looks good.\"\n\"Go ahead and send it.\"\n\"This works for me.\"\n\"Approved.\"\n\"No changes needed.\"\n\"Good\"\n\"Go ahead.\""
            },
            {
              "category": "decline",
              "description": "=The email has been reviewed, but the human requests modifications before it is sent like tweaks, removing parts, rewording, etc. This could include suggested edits, rewording, or major revisions. \n\nExample phrases include:\n\n\"Can we tweak this part?\"\n\"Needs some changes.\"\n\"I’d like to reword this.\"\n\"Not quite right—let’s revise it.\"\n\"Can you adjust this before sending?\"\n\"Don't mention that we can't do that.\""
            }
          ]
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.textClassifier",
      "typeVersion": 1.1,
      "position": [
        1040,
        -16
      ],
      "id": "95a503b3-f4fd-419b-bf61-0602eb87b8b9",
      "name": "Text Classifier"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Email: {{ $('Edit Fields').item.json.email }}\n\nFeedback: {{ $('gmail- get feedback').item.json.data.text }}",
        "hasOutputParser": true,
        "options": {
          "systemMessage": "=# Overview\nYou are an expert email writer. Your job is to take an incoming email and revise it based on the feedback the human submitted.\n\n## Rules\nSign off emails as Toyo, CEO Uptimelabz\nHere is the current date/time: {{ $now }}\n"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [
        1408,
        112
      ],
      "id": "12051f8e-5827-48b0-b87e-2475f91e5f25",
      "name": "Revision agent"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Incoming Lead\n\nName: {{ $json.fields.Name }}\n\nEmail: {{ $json.fields.Email }}\n\nIntent: {{ $json.fields.Intent }}\n\nBudget: {{ $json.fields.Budget }}\n\nCompany Name: {{ $json.fields.CompanyName }}\n\nProject Description: {{ $json.fields['Project Description'] }}\n\nTimeline: {{ $json.fields.Timeline }}\n\nInstance (Time created): {{ $json.fields.Instance }}\n\nDo not include any em-dashes at all.",
        "hasOutputParser": true,
        "options": {
          "systemMessage": "=# Overview\nYou are an expert salesperson for an agency that delivers AI solutions. Your job is to respond to incoming leads by addressing their needs in a professional manner. You will receive information like the lead's project description and timeline, and your goal is to convince them that we are the best AI agency on the market.\n\n# Tools\nProject Database – Use this tool to search through previous projects we have completed.\n\n# Rules\nYou will receive information about a lead, and you need to craft a concise, professional email.\n\n# Main objective\nConvince the lead to book a second call. Make them believe that we can deliver their project and exceed expectations.\n\nRetrieve information about relevant past projects to include as proof of capability. Mention the client outcome or result we helped them achieve.\n\nInclude a link to book a call using this link: https://cal.com/toyo-ntewo\n\nEmail Signature\nSign off emails as: \nToyo, CEO at UptimeLabz\n\nHere is the current date/time: {{ $now }}"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [
        224,
        -16
      ],
      "id": "fbceac1d-2e20-4451-9625-0b4c6ba543b5",
      "name": "Sales Agent"
    },
    {
      "parameters": {
        "sendTo": "={{ $('Airtable Trigger').item.json.fields.Email }}",
        "subject": "={{ $('Sales Agent').item.json.output.subject }}",
        "emailType": "text",
        "message": "={{ $('Edit Fields').item.json.email }}",
        "options": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.2,
      "position": [
        1408,
        -112
      ],
      "id": "bf9f8404-10f2-4cff-ba08-b2fd0422f63c",
      "name": "Send a message"
    }
  ],
  "connections": {
    "Airtable Trigger": {
      "main": [
        [
          {
            "node": "Sales Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Project DB": {
      "ai_tool": [
        [
          {
            "node": "Sales Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Sales Agent",
            "type": "ai_outputParser",
            "index": 0
          },
          {
            "node": "Revision agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Ollama Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Sales Agent",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "Text Classifier",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "Revision agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Ollama Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "Structured Output Parser",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "gmail- get feedback",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "gmail- get feedback": {
      "main": [
        [
          {
            "node": "Text Classifier",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Text Classifier": {
      "main": [
        [
          {
            "node": "Send a message",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Revision agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sales Agent": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate"
  },
  "pinData": {}
}
