{
  "name": "AI Gmail inbox manager that triages emails by priority and drafts replies with OpenAI and Google Sheets",
  "nodes": [
    {
      "id": "a4b02738-7b5b-41cc-a6b9-1885f1f4f23f",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -608,
        -272
      ],
      "parameters": {
        "width": 480,
        "height": 832,
        "content": "## AI Gmail inbox manager that triages emails by priority and drafts replies with OpenAI and Google Sheets\n\n### How it works\n\nThis workflow monitors Gmail for new incoming emails and enriches each message with user-defined triage settings. It sends the email through an AI agent powered by OpenAI, validates the result against a structured schema, logs the outcome to Google Sheets, and creates a Gmail draft reply when needed.\n\n### Setup steps\n\n- Connect Gmail credentials for both the trigger and draft creation nodes.\n- Connect OpenAI credentials for the GPT-5 Mini language model node.\n- Connect Google Sheets credentials and select the spreadsheet/sheet used as the triage dashboard.\n- Edit the \u201cYour Settings (EDIT ME)\u201d node to set your name, role, email categories, and reply drafting guidance.\n- Verify the structured output schema matches the columns expected by the Google Sheets logging node and the fields used by the reply condition.\n\n### Customization\n\nAdjust the triage categories, priority rules, and draft guidance in the settings node. You can also change the Google Sheets dashboard columns or the IF condition that determines when a draft reply should be created."
      },
      "typeVersion": 1
    },
    {
      "id": "932b9ace-348f-42a5-be1b-7e44946dd997",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -48,
        -176
      ],
      "parameters": {
        "color": 7,
        "width": 480,
        "height": 336,
        "content": "## Capture and configure\n\nStarts when a new Gmail message arrives, then applies the editable user settings such as identity, role, triage categories, and draft guidance before sending the email onward."
      },
      "typeVersion": 1
    },
    {
      "id": "e90277f4-cbc8-48ed-aa13-26f90ce6beb3",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        464,
        -176
      ],
      "parameters": {
        "color": 7,
        "width": 432,
        "height": 592,
        "content": "## AI triage analysis\n\nUses the AI agent with the OpenAI chat model and structured output parser to classify the email, determine priority, and produce a schema-aligned triage result."
      },
      "typeVersion": 1
    },
    {
      "id": "8903c481-b508-48f8-824c-aa87a8d5b3e0",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        928,
        -160
      ],
      "parameters": {
        "color": 7,
        "width": 448,
        "height": 320,
        "content": "## Log and decide\n\nRecords the triage result in Google Sheets as a dashboard entry, then checks whether the email requires a reply."
      },
      "typeVersion": 1
    },
    {
      "id": "479bd2c5-806c-40ae-a758-a400afcd051f",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1424,
        -272
      ],
      "parameters": {
        "color": 7,
        "width": 240,
        "height": 320,
        "content": "## Create Gmail draft\n\nCreates a Gmail draft reply for emails that pass the reply-needed condition."
      },
      "typeVersion": 1
    },
    {
      "id": "g1",
      "name": "When Gmail Email Received",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        0,
        0
      ],
      "parameters": {
        "simple": false,
        "filters": {
          "readStatus": "unread"
        },
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "g2",
      "name": "Set User Email Preferences",
      "type": "n8n-nodes-base.set",
      "position": [
        280,
        0
      ],
      "parameters": {
        "mode": "manual",
        "assignments": {
          "assignments": [
            {
              "id": "a1",
              "name": "yourName",
              "type": "string",
              "value": "Alex"
            },
            {
              "id": "a2",
              "name": "yourRole",
              "type": "string",
              "value": "Founder at Acme"
            },
            {
              "id": "a3",
              "name": "categories",
              "type": "string",
              "value": "Sales, Support, Billing, Recruiting, Newsletter, Personal, Spam"
            },
            {
              "id": "a4",
              "name": "draftGuidance",
              "type": "string",
              "value": "Warm, concise, professional. Sign off with my first name."
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "g3",
      "name": "Email Triage Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        592,
        0
      ],
      "parameters": {
        "text": "=From: {{ $json.from }}\nSubject: {{ $json.subject }}\n\n{{ $json.text }}",
        "options": {
          "systemMessage": "=You are an inbox assistant for {{ $('Set User Email Preferences').item.json.yourName }} ({{ $('Set User Email Preferences').item.json.yourRole }}).\n\nTriage the email below. Return:\n- priority: High, Medium, or Low\n- category: one of {{ $('Set User Email Preferences').item.json.categories }}\n- needsReply: true only if it genuinely needs a personal reply (not newsletters, receipts, no-reply, or spam)\n- summary: one short sentence\n- draftReply: if needsReply is true, write a ready-to-send reply in this style: {{ $('Set User Email Preferences').item.json.draftGuidance }}. If needsReply is false, return an empty string.\n\nNever invent facts. Keep the draft short and human."
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 3.1
    },
    {
      "id": "g4",
      "name": "OpenAI GPT-5 Mini",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        544,
        256
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-5-mini"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "g5",
      "name": "Parse Triage Results",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        768,
        256
      ],
      "parameters": {
        "schemaType": "fromJson",
        "jsonSchemaExample": "{\"priority\": \"High\", \"category\": \"Sales\", \"needsReply\": true, \"summary\": \"Prospect asking if Pro plan includes support\", \"draftReply\": \"Hi Jane, yes \\u2014 the Pro plan includes priority support. Happy to help!\"}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "g6",
      "name": "Append to Triage Dashboard",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        976,
        0
      ],
      "parameters": {
        "columns": {
          "value": {
            "Date": "={{ $now.toFormat('yyyy-MM-dd HH:mm') }}",
            "From": "={{ $('When Gmail Email Received').item.json.from }}",
            "Subject": "={{ $('When Gmail Email Received').item.json.subject }}",
            "Summary": "={{ $('Email Triage Agent').item.json.output.summary }}",
            "Category": "={{ $('Email Triage Agent').item.json.output.category }}",
            "Priority": "={{ $('Email Triage Agent').item.json.output.priority }}",
            "Needs Reply": "={{ $('Email Triage Agent').item.json.output.needsReply }}"
          },
          "mappingMode": "defineBelow"
        },
        "options": {},
        "resource": "sheet",
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": ""
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "g7",
      "name": "Check Reply Necessity",
      "type": "n8n-nodes-base.if",
      "position": [
        1248,
        0
      ],
      "parameters": {
        "conditions": {
          "options": {
            "version": 2,
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $('Email Triage Agent').item.json.output.needsReply }}",
              "rightValue": true
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "g8",
      "name": "Draft Email Reply in Gmail",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1472,
        -112
      ],
      "parameters": {
        "message": "={{ $('Email Triage Agent').item.json.output.draftReply }}",
        "options": {
          "sendTo": "={{ $('When Gmail Email Received').item.json.from }}",
          "threadId": "={{ $('When Gmail Email Received').item.json.threadId }}"
        },
        "subject": "=Re: {{ $('When Gmail Email Received').item.json.subject }}",
        "resource": "draft",
        "emailType": "text",
        "operation": "create"
      },
      "typeVersion": 2.2
    }
  ],
  "connections": {
    "OpenAI GPT-5 Mini": {
      "ai_languageModel": [
        [
          {
            "node": "Email Triage Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Email Triage Agent": {
      "main": [
        [
          {
            "node": "Append to Triage Dashboard",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Triage Results": {
      "ai_outputParser": [
        [
          {
            "node": "Email Triage Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Check Reply Necessity": {
      "main": [
        [
          {
            "node": "Draft Email Reply in Gmail",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "When Gmail Email Received": {
      "main": [
        [
          {
            "node": "Set User Email Preferences",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append to Triage Dashboard": {
      "main": [
        [
          {
            "node": "Check Reply Necessity",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set User Email Preferences": {
      "main": [
        [
          {
            "node": "Email Triage Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}