{
  "name": "AI Email Triage & Reply Agent (with Knowledge + Slack Approval)",
  "nodes": [
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "simple": false,
        "filters": {
          "readStatus": "unread"
        },
        "options": {}
      },
      "id": "0280aa41-d55c-47e4-b99b-03b4c7c9e4e7",
      "name": "New Email Trigger",
      "type": "n8n-nodes-base.gmailTrigger",
      "typeVersion": 1.3,
      "position": [
        48,
        -32
      ],
      "credentials": {
        "gmailOAuth2": {
          "id": "xmp6P6qtAw4JgOCe",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "operation": "addLabels",
        "messageId": "={{ $json.id }}",
        "labelIds": "={{ $fromAI('Label_Names_or_IDs', `Array of Gmail label ids to add. Use the id field from the \"Get all labels\" tool`, 'string') }}"
      },
      "id": "a5e4168b-1ce7-4cfe-ae6d-a1a4ab9b96df",
      "name": "Add Label",
      "type": "n8n-nodes-base.gmailTool",
      "typeVersion": 2.1,
      "position": [
        192,
        192
      ],
      "webhookId": "e7289911-d937-45bd-9e91-410a0dc959f8",
      "credentials": {
        "gmailOAuth2": {
          "id": "xmp6P6qtAw4JgOCe",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "Use this tool to get all existing labels from Gmail",
        "resource": "label",
        "returnAll": true
      },
      "type": "n8n-nodes-base.gmailTool",
      "typeVersion": 2.1,
      "position": [
        320,
        192
      ],
      "id": "79ee166d-4443-45c6-84e1-8820299cf2de",
      "name": "Get all Labels",
      "webhookId": "291b9995-7ae1-4f65-9ffb-ba62c980b829",
      "credentials": {
        "gmailOAuth2": {
          "id": "xmp6P6qtAw4JgOCe",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4.1-mini",
          "mode": "list",
          "cachedResultName": "gpt-4.1-mini"
        },
        "options": {}
      },
      "id": "1fda1d78-a669-4be1-9aba-56c0abb7c247",
      "name": "Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        64,
        176
      ],
      "credentials": {
        "openAiApi": {
          "id": "MzIepidaRw9ZqcPB",
          "name": "OpenAi account Credentials"
        }
      }
    },
    {
      "parameters": {
        "operation": "sendAndWait",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "value": "C09H6M87YPJ",
          "mode": "list",
          "cachedResultName": "help-n8n"
        },
        "message": "=📩 New Email Received for Approval\n\nFrom: {{ $('New Email Trigger').item.json.from.value[0].address }}\nName: {{ $('New Email Trigger').item.json.from.value[0].name }}\nSubject: {{ $('New Email Trigger').item.json.headers.subject }}\n\nContent:\n{{ $('New Email Trigger').item.json.text }}\n\n✅ Approval Request\n\nProposed Subject: {{ $json.output.subject }}\nProposed Email: {{ $json.output.email }}",
        "options": {}
      },
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.3,
      "position": [
        800,
        -160
      ],
      "id": "17e69d46-9bf9-4f4b-9124-0e738f4c95e2",
      "name": "Send message and wait for response",
      "webhookId": "b2b121a2-527e-4f93-92bb-8af931b0d756",
      "credentials": {
        "slackApi": {
          "id": "KMkFQmc4r1CU08xl",
          "name": "Slack account 2"
        }
      }
    },
    {
      "parameters": {
        "jsonSchemaExample": "{\n  \"subject\": \"\",\n  \"email\": \"\",\n  \"label\": \"\"\n}"
      },
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.3,
      "position": [
        608,
        320
      ],
      "id": "885e76e1-6f7f-47a9-a008-84292b6a37a3",
      "name": "Structured Output Parser"
    },
    {
      "parameters": {
        "operation": "get",
        "documentURL": "https://docs.google.com/document/d/19_fdwLow4JjyRzuWfxnxhOPX5LRYsgCYaLxOAbOe7Uw/edit?usp=drive_web&ouid=112352690743602538594",
        "simple": false
      },
      "type": "n8n-nodes-base.googleDocsTool",
      "typeVersion": 2,
      "position": [
        448,
        192
      ],
      "id": "54a710dc-03f3-44fe-bac7-f43a1c8f818e",
      "name": "Get a document in Google Docs",
      "credentials": {
        "googleDocsOAuth2Api": {
          "id": "qziHwPuC4VDliHwf",
          "name": "Google Docs account"
        }
      }
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Categorize this email:\n\n**From:** {{ $json.from.value[0].address }}\n**Name** {{ $json.from.value[0].name }}\n**Subject:** {{ $json.subject }}\n**Content:** \n{{ $json.html }}\n\nPlease analyze this email and apply appropriate labels using the available tools.\nUse the Get a document in Google Docs tool to get info from the Company's Knowledge Base.\n\nAnd then daft an email reply.",
        "hasOutputParser": true,
        "options": {
          "systemMessage": "=You are an email categorization assistant. Your task is to analyze emails and apply appropriate labels to help organize the user's inbox.\n\nYou have access to the following tools:\n1. **Get all Labels** - Retrieves available email labels\n2. **Add Labels** - Applies labels to emails\n3.** Google Docs*** - Use this tool to answer the Question from the Company's Knowledge Base\n\n### Instructions:\n- First, always use \"Get all Labels\" to see available categories\n- Analyze email content for: subject, sender, keywords, and context\n- Apply 1-3 most relevant labels per email\n- Be consistent in categorization patterns\n- If unsure between labels, choose the most specific one\n- Always Use the Get a document in Google Docs tool to get info from the Company's Knowledge Base.\n- drat an email \n### Response Format:\nDraft an email response (do not include any other commentary or text), sign off as regards, Kris\n\nOutput must be in this format:\n\n{\n  \"subject\": \"\",\n  \"email\": \"\",\n  \"label\": \"\"\n}"
        }
      },
      "id": "a4dccc7a-008e-40c5-90dd-c91090a144fd",
      "name": "Email Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 2.2,
      "position": [
        256,
        -32
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "a12f125c-15d4-43f2-86c4-02cd440c0b58",
              "leftValue": "={{ $json.output.label }}",
              "rightValue": "Support",
              "operator": {
                "type": "string",
                "operation": "contains"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        608,
        -32
      ],
      "id": "0cc9d262-458a-42ce-bb31-533853183d54",
      "name": "Support Email?"
    },
    {
      "parameters": {
        "operation": "reply",
        "messageId": "={{ $('New Email Trigger').item.json.id }}",
        "emailType": "text",
        "message": "={{ $('Email Agent').item.json.output.email }}",
        "options": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        1008,
        -176
      ],
      "id": "ba1017b6-2844-43d4-9998-f6fd72b08365",
      "name": "Reply to a message",
      "webhookId": "a48854a7-1613-4a0d-8f25-893d57670102",
      "credentials": {
        "gmailOAuth2": {
          "id": "xmp6P6qtAw4JgOCe",
          "name": "Gmail account"
        }
      }
    }
  ],
  "pinData": {},
  "connections": {
    "New Email Trigger": {
      "main": [
        [
          {
            "node": "Email Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add Label": {
      "ai_tool": [
        [
          {
            "node": "Email Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Get all Labels": {
      "ai_tool": [
        [
          {
            "node": "Email Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Model": {
      "ai_languageModel": [
        [
          {
            "node": "Email Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Email Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Send message and wait for response": {
      "main": [
        [
          {
            "node": "Reply to a message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get a document in Google Docs": {
      "ai_tool": [
        [
          {
            "node": "Email Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Email Agent": {
      "main": [
        [
          {
            "node": "Support Email?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Support Email?": {
      "main": [
        [
          {
            "node": "Send message and wait for response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "36c0a9e3-e75f-4386-aae1-ded89938655a",
  "meta": {
    "templateId": "email_triage_agent_with_gmail",
    "templateCredsSetupCompleted": true,
    "instanceId": "4aabc0aa2e160dafa4f9d9bcedde563b5af29598cd16960f637ae2fb99aea720"
  },
  "id": "Do7QOpYwwW5dcXBM",
  "tags": []
}