{
  "name": "Inbound Lead Response w Human In Loop Demo",
  "nodes": [
    {
      "parameters": {
        "formTitle": "Contact Us",
        "formFields": {
          "values": [
            {
              "fieldLabel": "What is your name?",
              "placeholder": "Enter Your Name.",
              "requiredField": true
            },
            {
              "fieldLabel": "What is your email?",
              "fieldType": "email",
              "placeholder": "Enter your email address.",
              "requiredField": true
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.2,
      "position": [
        80,
        0
      ],
      "id": "1665b031-82b9-4e0e-941f-ecc4aedd9bda",
      "name": "On form submission",
      "webhookId": "273272cf-2db6-4adb-a84e-e5d3e80f993b"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        540,
        580
      ],
      "id": "1538494d-41ad-422d-9e56-55fb46a35317",
      "name": "OpenAI Chat Model",
      "credentials": {
        "openAiApi": {
          "id": "MzIepidaRw9ZqcPB",
          "name": "OpenAi account Credentials"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "1a7a06d7-f78a-40e3-87f2-cceff050abda",
              "name": "subject",
              "value": "={{ $json.output.subject }}",
              "type": "string"
            },
            {
              "id": "cc5d97f1-5b02-4408-b073-987796123c5c",
              "name": "body",
              "value": "={{ $json.output.body }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        540,
        0
      ],
      "id": "1f8f26c0-ea71-407b-92ba-a5dcb65e98d8",
      "name": "Set Email"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Subject:\n{{ $('Set Email').item.json.subject }}\n\nEmail Body:\n{{ $('Set Email').item.json.body }}\n\nFeedback from Human:\n{{ $('Send Approval Email').item.json.data.text }}\n",
        "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\n- Sign off emails as Kris\n- Here is the current date/time: {{ $now }}\n"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 2,
      "position": [
        1160,
        180
      ],
      "id": "0d8c6bf8-3db7-4867-95e9-732ce233f919",
      "name": "Email Revision Agent"
    },
    {
      "parameters": {
        "sendTo": "={{ $('On form submission').item.json['What is your email?'] }}",
        "subject": "={{ $('Sales AI Agent').item.json.output.subject }}",
        "message": "={{ $('Sales AI Agent').item.json.output.body }}",
        "options": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        1240,
        -180
      ],
      "id": "6dfb1719-9abf-4977-a10a-3d6c4a414c2e",
      "name": "Send Email",
      "webhookId": "d3be7cb7-29af-427d-ab49-ed14aa541299",
      "credentials": {
        "gmailOAuth2": {
          "id": "xmp6P6qtAw4JgOCe",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "jsonSchemaExample": "{\n  \"subject\": \"Helping You Deliver AI Faster – Let's Chat\",\n  \"body\": \"Hi [Lead Name],\\n\\nThanks for reaching out about your project. Based on what you shared, it sounds like a great fit for what we do at Dunder AI.\\n\\nWe've helped companies like [Previous Client] deliver [similar outcome] ahead of schedule using tailored AI workflows. I’d love to show you how we could do the same for your team.\\n\\nAre you available for a quick follow-up call this week?\\n\\nBest regards,  \\nJim  \\nDunder AI\"\n}\n"
      },
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.3,
      "position": [
        900,
        540
      ],
      "id": "a9382dca-6166-4d7f-aa74-9ec8e3f3560b",
      "name": "Email Structured Output Parser"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Incoming Lead:\n\nName:  {{ $json[\"What is your name?\"] }}\n\nEmail: {{ $json[\"What is your email?\"] }}",
        "hasOutputParser": true,
        "options": {
          "systemMessage": "=## Overview\nYou are an expert sales person from 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 done.\n\n## Rules\n- You will receive information about a lead, and you need to craft a professional email. Keep it concise, nobody wants to read a huge email.\n- Your main objective is to convince the lead to book in a second call. Your job is to make them believe that we can deliver the project they have described and exceed their expectations.\n- Retrieve information about previous projects to share with the lead to prove that our team is capable of handling their project. Find a similar project we have done to share with the lead. Share the result of how we helped the client.\n\n## Final Notes\nSign off emails as Kris\nHere is the current date/time: {{ $now }}\n"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 2,
      "position": [
        220,
        0
      ],
      "id": "84abf363-1b75-4a98-bf04-692fc102b006",
      "name": "Sales AI Agent"
    },
    {
      "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.  Example phrases include:  \"Good\", \"Looks good.\"  \"Go ahead and send it.\"  \"This works for me.\"  \"Approved.\"  \"No changes needed.\""
            },
            {
              "category": "Rejected",
              "description": "The email has been reviewed and rejected. The human has provided feedback indicating that the message is not ready to be sent and requires revision before approval.  Example phrases include:  \"Can we make this clearer?\"  \"This doesn't sound right.\"  \"Needs more detail.\"  \"Too generic — rewrite.\"  \"I wouldn’t send this yet.\""
            }
          ]
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.textClassifier",
      "typeVersion": 1.1,
      "position": [
        840,
        0
      ],
      "id": "33d30b66-e022-44c0-b2d1-8835d7b738d4",
      "name": "Response Classifier"
    },
    {
      "parameters": {
        "operation": "sendAndWait",
        "sendTo": "kris@r3d.ai",
        "subject": "=APPROVAL REQUIRED for New Lead: {{ $('On form submission').item.json[\"What is your name?\"] }} ({{ $('On form submission').item.json[\"What is your email?\"] }})",
        "message": "=Lead Details\nName: {{ $('On form submission').item.json[\"What is your name?\"] }}\nEmail: {{ $('On form submission').item.json[\"What is your email?\"] }}\n\nPlease provide feedback on this message generated by Jim, our AI Sales Agent.\nSubject:\n{{ $json.subject }}\n\nEmail Body:\n{{ $json.body }}",
        "responseType": "freeText",
        "options": {}
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        680,
        0
      ],
      "id": "b491f6b9-a661-46b1-8ccb-214c33835e71",
      "name": "Send Approval Email",
      "webhookId": "f9acea51-76ec-4e5e-954b-2aba858a4efa",
      "credentials": {
        "gmailOAuth2": {
          "id": "xmp6P6qtAw4JgOCe",
          "name": "Gmail account"
        }
      }
    }
  ],
  "pinData": {},
  "connections": {
    "On form submission": {
      "main": [
        [
          {
            "node": "Sales AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Sales AI Agent",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "Response Classifier",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "Email Revision Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Set Email": {
      "main": [
        [
          {
            "node": "Send Approval Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Email Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Sales AI Agent",
            "type": "ai_outputParser",
            "index": 0
          },
          {
            "node": "Email Revision Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Email Revision Agent": {
      "main": [
        [
          {
            "node": "Set Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sales AI Agent": {
      "main": [
        [
          {
            "node": "Set Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Response Classifier": {
      "main": [
        [
          {
            "node": "Send Email",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Email Revision Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Approval Email": {
      "main": [
        [
          {
            "node": "Response Classifier",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "1f33d538-66e5-44be-920c-9f0346ebf15c",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "4aabc0aa2e160dafa4f9d9bcedde563b5af29598cd16960f637ae2fb99aea720"
  },
  "id": "aArojVSytB9mXitD",
  "tags": []
}