{
  "schema_version": "1.0.0",
  "id": "lead-reply-agent-with-tools",
  "title": "Draft a lead reply with CRM and sheet tools",
  "category": "ai-agents",
  "difficulty": "advanced",
  "featured": true,
  "description": "A model reads a lead email, decides whether it needs the CRM record, the pricing sheet, both, or neither, and drafts a reply from what those lookups return.",
  "tags": [
    "ai-agent",
    "chatgpt",
    "hubspot",
    "google-sheets",
    "gmail",
    "tools"
  ],
  "apps": [
    "Gmail",
    "ChatGPT (OpenAI)",
    "Code by Zapier",
    "Paths by Zapier",
    "HubSpot",
    "Google Sheets"
  ],
  "plan": {
    "minimum": "Professional",
    "reasons": [
      "multi-step Zap: 15 steps after the trigger",
      "Paths by Zapier"
    ]
  },
  "tasks": {
    "typical": 5,
    "max": 6
  },
  "trigger": {
    "app": "Gmail",
    "event": "New Labeled Email",
    "kind": "polling",
    "title": "New email under the Leads label",
    "why": "Fires for each email under the Leads label, which a Gmail filter on your contact-form address can apply.",
    "config": {
      "Label": "Leads"
    },
    "outputs": [
      "message_id",
      "thread_id",
      "from_email",
      "from_name",
      "to",
      "subject",
      "date",
      "body_plain",
      "snippet",
      "labels",
      "attachment_count",
      "attachment_names"
    ],
    "sample": "sample-trigger.json"
  },
  "steps": [
    {
      "key": "plan",
      "kind": "ai",
      "app": "ChatGPT (OpenAI)",
      "event": "Conversation",
      "title": "Decide which tools the reply needs",
      "why": "The model only plans. It returns JSON naming the lookups it wants and what to search for. The tools are ordinary Zapier search steps below; the model never calls an API or sends an email itself.",
      "fields": {
        "User Message": "From: {{trigger.from_name}} <{{trigger.from_email}}>\nSubject: {{trigger.subject}}\n\n{{trigger.body_plain}}",
        "Assistant Instructions": "You plan lookups for a sales assistant. Tools: crm_lookup (find the sender in HubSpot by email: past conversations, lifecycle stage, company) and sheet_lookup (find one plan in the pricing sheet by its exact plan name: Starter, Growth, or Scale). Reply with JSON only, no prose: {\"tools\": [...], \"crm_query\": \"...\", \"sheet_query\": \"...\"}. Use crm_lookup when the sender mentions earlier work or might be an existing client. Use sheet_lookup when they ask about price, plans, or what is included. Use an empty list when neither helps.",
        "Model": "gpt-4o-mini",
        "Memory Key": "(leave blank)"
      },
      "outputs": [
        "response"
      ]
    },
    {
      "key": "parse",
      "kind": "code",
      "app": "Code by Zapier",
      "event": "Run JavaScript",
      "title": "Read the tool plan",
      "why": "Strips code fences, drops tools that are not on the allow list, and returns one `plan` value (crm, sheet, both, none). A malformed plan becomes \"none\" instead of an error.",
      "code": {
        "language": "javascript",
        "module": "parse-tool-call",
        "file": "code/parse-tool-call.js"
      },
      "input_data": {
        "model_text": "{{plan.response}}",
        "allowed_tools": "crm_lookup,sheet_lookup"
      },
      "outputs": [
        "plan",
        "wants_crm",
        "wants_sheet",
        "crm_query",
        "sheet_query",
        "tool_count",
        "valid_json",
        "error"
      ]
    },
    {
      "key": "route",
      "kind": "paths",
      "app": "Paths by Zapier",
      "event": "Split into paths",
      "title": "Run the tools the plan asked for",
      "why": "One path per plan value. Each path runs its lookups, then asks for the reply with only those facts in front of the model.",
      "paths": [
        {
          "name": "CRM only",
          "conditions": [
            [
              {
                "field": "{{parse.plan}}",
                "operator": "(Text) Exactly matches",
                "value": "crm"
              }
            ]
          ],
          "usually": true,
          "steps": [
            {
              "key": "crm_contact",
              "kind": "search",
              "app": "HubSpot",
              "event": "Find Contact",
              "title": "Look the sender up in HubSpot",
              "why": "Searches by the email the plan named, normally the sender's.",
              "fields": {
                "Field to search by": "Email",
                "Search value": "{{parse.crm_query}}",
                "Should this step be considered a \"success\" when nothing is found?": "Yes"
              },
              "outputs": [
                "id",
                "firstname",
                "company",
                "lifecyclestage",
                "hs_lead_status",
                "last_note",
                "_zap_search_was_found_status"
              ]
            },
            {
              "key": "crm_answer",
              "kind": "ai",
              "app": "ChatGPT (OpenAI)",
              "event": "Conversation",
              "title": "Write the reply with the CRM facts",
              "why": "Gets the email plus the CRM record, nothing else.",
              "fields": {
                "User Message": "EMAIL from {{trigger.from_name}}:\n{{trigger.body_plain}}\n\nCRM (found: {{crm_contact._zap_search_was_found_status}}): name {{crm_contact.firstname}}, company {{crm_contact.company}}, stage {{crm_contact.lifecyclestage}}, last note: {{crm_contact.last_note}}\n\nPRICING: not looked up",
                "Assistant Instructions": "You write first replies to sales inquiries for Northwind Studio, a small automation agency. Be warm, specific, and short (under 140 words). Use only the facts given under CRM and PRICING. If a fact you need is missing, say a person will confirm it; never invent prices, dates, or past conversations. End with one clear next step. Write plain text, no subject line, no signature.",
                "Model": "gpt-4o-mini",
                "Memory Key": "(leave blank)"
              },
              "outputs": [
                "response"
              ]
            },
            {
              "key": "crm_draft",
              "kind": "action",
              "app": "Gmail",
              "event": "Create Draft Reply",
              "title": "Save the reply as a Gmail draft",
              "why": "A draft in the same thread, never a sent email. A person reads, edits, and sends it.",
              "fields": {
                "Thread": "{{trigger.thread_id}}",
                "To": "{{trigger.from_email}}",
                "Body Type": "plain",
                "Body": "{{crm_answer.response}}"
              },
              "outputs": [
                "id"
              ]
            }
          ]
        },
        {
          "name": "Pricing only",
          "conditions": [
            [
              {
                "field": "{{parse.plan}}",
                "operator": "(Text) Exactly matches",
                "value": "sheet"
              }
            ]
          ],
          "usually": false,
          "steps": [
            {
              "key": "sheet_price",
              "kind": "search",
              "app": "Google Sheets",
              "event": "Lookup Spreadsheet Row",
              "title": "Look the plan up in the pricing sheet",
              "why": "Finds the row for the plan the model named. The sheet, not the model, is the source of every number.",
              "fields": {
                "Drive": "My Google Drive",
                "Spreadsheet": "Sales",
                "Worksheet": "Pricing",
                "Lookup Column": "plan_name",
                "Lookup Value": "{{parse.sheet_query}}",
                "Should this step be considered a \"success\" when nothing is found?": "Yes"
              },
              "outputs": [
                "row_number",
                "_zap_search_was_found_status",
                "plan_name",
                "monthly_price",
                "annual_price",
                "included",
                "setup_fee"
              ]
            },
            {
              "key": "sheet_answer",
              "kind": "ai",
              "app": "ChatGPT (OpenAI)",
              "event": "Conversation",
              "title": "Write the reply with the price",
              "why": "Gets the email plus one pricing row.",
              "fields": {
                "User Message": "EMAIL from {{trigger.from_name}}:\n{{trigger.body_plain}}\n\nCRM: not looked up\n\nPRICING (found: {{sheet_price._zap_search_was_found_status}}): {{sheet_price.plan_name}} at {{sheet_price.monthly_price}} a month or {{sheet_price.annual_price}} a year, setup {{sheet_price.setup_fee}}. Included: {{sheet_price.included}}",
                "Assistant Instructions": "You write first replies to sales inquiries for Northwind Studio, a small automation agency. Be warm, specific, and short (under 140 words). Use only the facts given under CRM and PRICING. If a fact you need is missing, say a person will confirm it; never invent prices, dates, or past conversations. End with one clear next step. Write plain text, no subject line, no signature.",
                "Model": "gpt-4o-mini",
                "Memory Key": "(leave blank)"
              },
              "outputs": [
                "response"
              ]
            },
            {
              "key": "sheet_draft",
              "kind": "action",
              "app": "Gmail",
              "event": "Create Draft Reply",
              "title": "Save the reply as a Gmail draft",
              "why": "A draft in the same thread, never a sent email. A person reads, edits, and sends it.",
              "fields": {
                "Thread": "{{trigger.thread_id}}",
                "To": "{{trigger.from_email}}",
                "Body Type": "plain",
                "Body": "{{sheet_answer.response}}"
              },
              "outputs": [
                "id"
              ]
            }
          ]
        },
        {
          "name": "CRM and pricing",
          "conditions": [
            [
              {
                "field": "{{parse.plan}}",
                "operator": "(Text) Exactly matches",
                "value": "both"
              }
            ]
          ],
          "usually": false,
          "steps": [
            {
              "key": "both_contact",
              "kind": "search",
              "app": "HubSpot",
              "event": "Find Contact",
              "title": "Look the sender up in HubSpot",
              "why": "Same CRM lookup as the first path.",
              "fields": {
                "Field to search by": "Email",
                "Search value": "{{parse.crm_query}}",
                "Should this step be considered a \"success\" when nothing is found?": "Yes"
              },
              "outputs": [
                "id",
                "firstname",
                "company",
                "lifecyclestage",
                "hs_lead_status",
                "last_note",
                "_zap_search_was_found_status"
              ]
            },
            {
              "key": "both_price",
              "kind": "search",
              "app": "Google Sheets",
              "event": "Lookup Spreadsheet Row",
              "title": "Look the plan up in the pricing sheet",
              "why": "Same pricing lookup as the second path.",
              "fields": {
                "Drive": "My Google Drive",
                "Spreadsheet": "Sales",
                "Worksheet": "Pricing",
                "Lookup Column": "plan_name",
                "Lookup Value": "{{parse.sheet_query}}",
                "Should this step be considered a \"success\" when nothing is found?": "Yes"
              },
              "outputs": [
                "row_number",
                "_zap_search_was_found_status",
                "plan_name",
                "monthly_price",
                "annual_price",
                "included",
                "setup_fee"
              ]
            },
            {
              "key": "both_answer",
              "kind": "ai",
              "app": "ChatGPT (OpenAI)",
              "event": "Conversation",
              "title": "Write the reply with both",
              "why": "Gets the email, the CRM record, and the pricing row.",
              "fields": {
                "User Message": "EMAIL from {{trigger.from_name}}:\n{{trigger.body_plain}}\n\nCRM (found: {{both_contact._zap_search_was_found_status}}): name {{both_contact.firstname}}, company {{both_contact.company}}, stage {{both_contact.lifecyclestage}}, last note: {{both_contact.last_note}}\n\nPRICING (found: {{both_price._zap_search_was_found_status}}): {{both_price.plan_name}} at {{both_price.monthly_price}} a month or {{both_price.annual_price}} a year, setup {{both_price.setup_fee}}. Included: {{both_price.included}}",
                "Assistant Instructions": "You write first replies to sales inquiries for Northwind Studio, a small automation agency. Be warm, specific, and short (under 140 words). Use only the facts given under CRM and PRICING. If a fact you need is missing, say a person will confirm it; never invent prices, dates, or past conversations. End with one clear next step. Write plain text, no subject line, no signature.",
                "Model": "gpt-4o-mini",
                "Memory Key": "(leave blank)"
              },
              "outputs": [
                "response"
              ]
            },
            {
              "key": "both_draft",
              "kind": "action",
              "app": "Gmail",
              "event": "Create Draft Reply",
              "title": "Save the reply as a Gmail draft",
              "why": "A draft in the same thread, never a sent email. A person reads, edits, and sends it.",
              "fields": {
                "Thread": "{{trigger.thread_id}}",
                "To": "{{trigger.from_email}}",
                "Body Type": "plain",
                "Body": "{{both_answer.response}}"
              },
              "outputs": [
                "id"
              ]
            }
          ]
        },
        {
          "name": "No tools",
          "conditions": [
            [
              {
                "field": "{{parse.plan}}",
                "operator": "(Text) Exactly matches",
                "value": "none"
              }
            ]
          ],
          "usually": false,
          "steps": [
            {
              "key": "none_answer",
              "kind": "ai",
              "app": "ChatGPT (OpenAI)",
              "event": "Conversation",
              "title": "Write the reply from the email alone",
              "why": "For greetings, scheduling questions, and anything neither tool helps with.",
              "fields": {
                "User Message": "EMAIL from {{trigger.from_name}}:\n{{trigger.body_plain}}\n\nCRM: not looked up\n\nPRICING: not looked up",
                "Assistant Instructions": "You write first replies to sales inquiries for Northwind Studio, a small automation agency. Be warm, specific, and short (under 140 words). Use only the facts given under CRM and PRICING. If a fact you need is missing, say a person will confirm it; never invent prices, dates, or past conversations. End with one clear next step. Write plain text, no subject line, no signature.",
                "Model": "gpt-4o-mini",
                "Memory Key": "(leave blank)"
              },
              "outputs": [
                "response"
              ]
            },
            {
              "key": "none_draft",
              "kind": "action",
              "app": "Gmail",
              "event": "Create Draft Reply",
              "title": "Save the reply as a Gmail draft",
              "why": "A draft in the same thread, never a sent email. A person reads, edits, and sends it.",
              "fields": {
                "Thread": "{{trigger.thread_id}}",
                "To": "{{trigger.from_email}}",
                "Body Type": "plain",
                "Body": "{{none_answer.response}}"
              },
              "outputs": [
                "id"
              ]
            }
          ]
        }
      ]
    }
  ]
}
