{
  "id": "7cOjPX3NNkUhhUhV",
  "meta": {
    "builderVariant": "mcp",
    "aiBuilderAssisted": true
  },
  "name": "Triage and answer inbound support emails with multi-agent AI",
  "tags": [],
  "nodes": [
    {
      "id": "a0560672-985d-4e6d-bf4a-ee3099ad220a",
      "name": "Gmail Trigger",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        368,
        128
      ],
      "parameters": {
        "simple": false,
        "filters": {
          "readStatus": "unread"
        },
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.4
    },
    {
      "id": "de2d67c6-ff8b-480d-beb9-4286405f7033",
      "name": "Normalize Email",
      "type": "n8n-nodes-base.set",
      "position": [
        656,
        128
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "a1",
              "name": "customerEmail",
              "type": "string",
              "value": "={{ JSON.stringify($json.from).match(/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}/)?.[0] }}"
            },
            {
              "id": "a2",
              "name": "subject",
              "type": "string",
              "value": "={{ $json.subject }}"
            },
            {
              "id": "a3",
              "name": "body",
              "type": "string",
              "value": "={{ $json.text }}"
            },
            {
              "id": "a4",
              "name": "threadId",
              "type": "string",
              "value": "={{ $json.threadId }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "17c616fc-823f-4a7b-9900-5906cdfe39b8",
      "name": "Support Orchestrator",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1024,
        128
      ],
      "parameters": {
        "text": "=From: {{ $json.customerEmail }}\nSubject: {{ $json.subject }}\n\n{{ $json.body }}",
        "options": {
          "systemMessage": "=You are the Support Triage Orchestrator for a SaaS company's customer support inbox. You receive ONE inbound customer email at a time. Your job is NOT to answer the customer yourself. Instead:\n1. Read the email and decide which ONE specialist should handle it.\n2. Call exactly one specialist tool, passing it the full email text plus any context it needs.\n3. Take the specialist's drafted reply and return the final structured result.\n\nYou have three specialist tools:\n- Billing_Specialist: refunds, duplicate or incorrect charges, invoices, failed payments, pricing/plan-cost questions.\n- Technical_Specialist: bugs, error messages, how-to / product usage, integrations or API help, login/access problems.\n- Account_Specialist: plan upgrades/downgrades, cancellations, seat changes, renewal dates, profile/account-data updates.\n\nRouting rules:\n- Choose the single best-fit specialist. If the email spans two areas, pick the one that blocks the customer most.\n- If the request is abusive, legal, a security incident, or you are not confident any specialist fits, set needs_human to true and explain why in 'reason'.\n- Never invent policy. The actual answer comes from the specialist's reply.\n\nSet 'priority' to one of low | normal | high (high = customer blocked, churn risk, or money at stake). Always answer through the required structured output format."
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 3.1
    },
    {
      "id": "a653c036-3af6-4044-a175-bc5281b9e92f",
      "name": "Orchestrator Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        944,
        352
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini",
          "cachedResultName": "gpt-4.1-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "1e2e439b-5f80-4e0b-9349-d4b193102c3f",
      "name": "Billing Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        496,
        768
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini",
          "cachedResultName": "gpt-4.1-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "8edd8534-ea13-4093-9f20-b0f2ef9f6981",
      "name": "Technical Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        992,
        768
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini",
          "cachedResultName": "gpt-4.1-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "4ce91b21-73a3-4ba8-9b5f-14ab5e18f108",
      "name": "Account Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1408,
        768
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini",
          "cachedResultName": "gpt-4.1-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "f8b2d38d-1d5b-4e4d-b812-b62358f5ae1d",
      "name": "Reply Schema",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        1408,
        368
      ],
      "parameters": {
        "jsonSchemaExample": "{\n  \"category\": \"billing\",\n  \"priority\": \"normal\",\n  \"draft_reply\": \"Hi Jane, thanks for reaching out about the duplicate charge...\",\n  \"needs_human\": false,\n  \"reason\": \"Routine refund request handled by the Billing specialist.\"\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "dba15093-75c5-45c1-b0ba-01dd38f7e836",
      "name": "Create Draft Reply",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1552,
        128
      ],
      "parameters": {
        "message": "={{ $json.output.draft_reply }}",
        "options": {
          "sendTo": "={{ $('Normalize Email').item.json.customerEmail }}",
          "threadId": "={{ $('Normalize Email').item.json.threadId }}"
        },
        "subject": "=Re: {{ $('Normalize Email').item.json.subject }}",
        "resource": "draft"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "d6b9a485-5020-41be-b690-3ba2065b1794",
      "name": "Sticky Note 166e6e8c",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -160,
        -32
      ],
      "parameters": {
        "width": 440,
        "height": 932,
        "content": "## Triage & answer inbound support emails (multi-agent)\n\nAn **orchestrator agent** reads each incoming support email, decides which **specialist agent** should handle it, and the specialist drafts the reply. The reply is saved as a **Gmail draft** so a human can review before sending.\n\n### How it works\n1. **Gmail Trigger** fetches new unread emails.\n2. **Normalize** extracts sender, subject and body.\n3. **Support Orchestrator** routes the email to ONE specialist via the AI Agent Tool: Billing, Technical, or Account.\n4. The specialist writes the reply; a **Structured Output Parser** returns category, priority, draft_reply and needs_human.\n5. **Create Draft Reply** saves it in the same Gmail thread.\n\n### Setup\n- Add your **OpenAI** credential to each Chat Model node.\n- Connect your **Gmail** account on the Trigger and the Draft node.\n- (Optional) edit the Gmail Trigger filter (e.g. `label:support`).\n\n### Customization\n- Edit each specialist's **system prompt** and **tool description** for your domain.\n- Swap the Gmail Trigger for a Webhook or Form trigger.\n- Route `needs_human = true` to Slack or a human-review queue."
      },
      "typeVersion": 1
    },
    {
      "id": "55d1ca8e-05ee-49c5-ac26-d743c7d19a9c",
      "name": "Sticky Note f77de6eb",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        304,
        -32
      ],
      "parameters": {
        "color": 7,
        "width": 568,
        "height": 328,
        "content": "## 1. Receive & normalize\nFetch new support emails and extract sender, subject and body."
      },
      "typeVersion": 1
    },
    {
      "id": "35d7f696-8fc6-486f-ac8a-54b3f5189863",
      "name": "Sticky Note 8e3bcf0a",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        896,
        -32
      ],
      "parameters": {
        "color": 7,
        "width": 572,
        "height": 328,
        "content": "## 2. Orchestrator routes\nThe orchestrator agent reads the email and delegates to ONE specialist tool, then returns structured JSON."
      },
      "typeVersion": 1
    },
    {
      "id": "8009d085-ffa2-47d5-adf7-7bf0d9dee477",
      "name": "Sticky Note 1d4bd4f5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        320,
        464
      ],
      "parameters": {
        "color": 7,
        "width": 1468,
        "height": 440,
        "content": "## 3. Specialist agents (AI Agent Tool)\nEach specialist has its own prompt + model. They draft the reply for their domain only."
      },
      "typeVersion": 1
    },
    {
      "id": "97d0a833-b3e7-40d9-a57f-ed977c5c7d7a",
      "name": "Sticky Note d6126acc",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1488,
        -32
      ],
      "parameters": {
        "color": 7,
        "width": 300,
        "height": 328,
        "content": "## 4. Draft the reply\nSave the drafted answer in the same Gmail thread for a human to review before sending."
      },
      "typeVersion": 1
    },
    {
      "id": "083f38f4-d2c4-4ba8-ab6d-25077235d2aa",
      "name": "Billing_Specialist",
      "type": "@n8n/n8n-nodes-langchain.agentTool",
      "position": [
        496,
        592
      ],
      "parameters": {
        "text": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('customer_email', 'The full customer email text plus any context the specialist needs to draft a reply') }}",
        "options": {
          "systemMessage": "You are a Billing Support specialist for a SaaS company. You write the reply that will be sent to the customer about a billing matter (refunds, duplicate charges, invoices, failed payments, pricing). Be warm, concise, and specific about the next step. Apologize once if the company made an error. Do not promise refunds you cannot verify; instead explain the process and timeline (e.g. 5-7 business days). Never ask for full card numbers. Output ONLY the reply text, no preamble."
        },
        "toolDescription": "Handles billing and payment issues: refunds, duplicate or incorrect charges, invoices and receipts, failed payments, and pricing/plan-cost questions. Input: the full customer email text. Returns a ready-to-send, empathetic reply stating the next step. Does NOT handle technical bugs, login problems, or plan upgrades/cancellations."
      },
      "typeVersion": 3
    },
    {
      "id": "67bc0420-d99b-4bdb-9de4-45df38528c09",
      "name": "Technical_Specialist",
      "type": "@n8n/n8n-nodes-langchain.agentTool",
      "position": [
        992,
        592
      ],
      "parameters": {
        "text": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('customer_email', 'The full customer email text plus any context the specialist needs to draft a reply') }}",
        "options": {
          "systemMessage": "=You are a Technical Support specialist for a SaaS product. You write the reply sent to a customer reporting a bug, error, or how-to question. Give clear, numbered troubleshooting steps when useful, ask for the minimum diagnostic info you need (e.g. browser, exact error message, screenshot), and set expectations on follow-up. Be friendly and avoid jargon. Output ONLY the reply text, no preamble."
        },
        "toolDescription": "Handles technical issues: product bugs, error messages, how-to and usage questions, integrations/API help, and login or access problems. Input: the full customer email text. Returns a clear troubleshooting reply with concrete steps. Does NOT handle refunds/billing or plan changes/cancellations."
      },
      "typeVersion": 3
    },
    {
      "id": "428aaf6f-504b-40b4-9f7a-4cf1c3c935bf",
      "name": "Account_Specialist",
      "type": "@n8n/n8n-nodes-langchain.agentTool",
      "position": [
        1408,
        592
      ],
      "parameters": {
        "text": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('customer_email', 'The full customer email text plus any context the specialist needs to draft a reply') }}",
        "options": {
          "systemMessage": "You are an Account Management specialist for a SaaS company. You write the reply sent to a customer about upgrades, downgrades, cancellations, seat changes, or account/profile updates. Confirm what you understood, state exactly what will happen and when, and mention one retention-friendly option without being pushy. Output ONLY the reply text, no preamble."
        },
        "toolDescription": "Handles account and subscription changes: plan upgrades/downgrades, cancellations, seat/user changes, renewal dates, and profile or account-data updates. Input: the full customer email text. Returns a reply confirming the change or the exact steps to make it. Does NOT handle billing disputes/refunds or technical bugs."
      },
      "typeVersion": 3
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "availableInMCP": true,
    "executionOrder": "v1"
  },
  "versionId": "37676dd4-c431-4bf8-9374-0db012d02623",
  "nodeGroups": [],
  "connections": {
    "Reply Schema": {
      "ai_outputParser": [
        [
          {
            "node": "Support Orchestrator",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Account Model": {
      "ai_languageModel": [
        [
          {
            "node": "Account_Specialist",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Billing Model": {
      "ai_languageModel": [
        [
          {
            "node": "Billing_Specialist",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Gmail Trigger": {
      "main": [
        [
          {
            "node": "Normalize Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Email": {
      "main": [
        [
          {
            "node": "Support Orchestrator",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Technical Model": {
      "ai_languageModel": [
        [
          {
            "node": "Technical_Specialist",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Account_Specialist": {
      "ai_tool": [
        [
          {
            "node": "Support Orchestrator",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Billing_Specialist": {
      "ai_tool": [
        [
          {
            "node": "Support Orchestrator",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Orchestrator Model": {
      "ai_languageModel": [
        [
          {
            "node": "Support Orchestrator",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Support Orchestrator": {
      "main": [
        [
          {
            "node": "Create Draft Reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Technical_Specialist": {
      "ai_tool": [
        [
          {
            "node": "Support Orchestrator",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  }
}