{
  "id": "YAlJiB1cYsqCxewZ",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "AI Email Reasoning Inbox Manager",
  "tags": [
    {
      "id": "CJjuUZBDAaUJU0mz",
      "name": "Example",
      "createdAt": "2025-10-13T19:38:15.318Z",
      "updatedAt": "2025-10-13T19:38:15.318Z"
    }
  ],
  "nodes": [
    {
      "id": "0e71a8c5-ba96-473d-9e7e-ccfce68dc949",
      "name": "Get Label Id's",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -640,
        112
      ],
      "parameters": {
        "resource": "label",
        "returnAll": true
      },
      "typeVersion": 2.1
    },
    {
      "id": "c2466e9e-48fe-4aee-83af-dd8776229bae",
      "name": "Watch Incoming Emails",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        -272,
        -112
      ],
      "parameters": {
        "simple": false,
        "filters": {
          "readStatus": "unread"
        },
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "61e42b53-6c7c-4f8b-9faa-469431d4e5bd",
      "name": "Mark Email As Read",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -32,
        -112
      ],
      "parameters": {
        "messageId": "={{ $json.id }}",
        "operation": "markAsRead"
      },
      "typeVersion": 2.1
    },
    {
      "id": "9f5a4ef6-c8de-48c2-88d5-8347a53a7284",
      "name": "Justify/Reason the Label AI has chosen",
      "type": "@n8n/n8n-nodes-langchain.toolThink",
      "position": [
        256,
        32
      ],
      "parameters": {
        "description": "Use the tool to think about something. It will not obtain new information or change the database, but just append the thought to the log. Use this to justify why you have chosen the label you have and make sure it is indeed the most relevant and accurate label you could put the email under"
      },
      "typeVersion": 1
    },
    {
      "id": "eba6b8a0-90e9-480b-a7d3-8492f3399e45",
      "name": "Select most appropriate Label",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        192,
        -112
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "GPT-4O"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "=You are now a professional email inbox manager for my inbox. \n\nYour job is to select the most relevant label to assign an email to from 1 of the 3 labels clearly defined below: \n\n1. Gumroad Notifications: Label_8633512660150681541\n2. Respond To: Label_6621328525648465499\n3. General: Label_7320308321061690804\n4. Instagram: LABEL ID\n\nThose are the 3 labels\n\nHere are descriptions about each label: \n\n1. Gumroad Notifications:\n\nFor emails that have come from Gumroad (the tool). That's it.\n\n2. Respond To:\n\nThese are emails that would be worthwhile me actually taking a look at and responding to (## NOTE: This excludes people selling me stuff; do NOT put emails in here of people selling me stuff)\n\n3. General: \n\nThis label should include any other email/s that do not meet the requirements of the 2 above specifications for an email qualifiying to the other 2 labels\n\n4. Insagram: \n\nUse this label when a notification comes in from instagram\n\nNow, I want you to take the email message that I have provided below to find and pinpoint the most accurate and relevant label that you think the email should go to: \n\nSubject: {{ $('Watch Incoming Emails').item.json.subject }}\n\nBody: {{ $('Watch Incoming Emails').item.json.text }}\n\n## RULES\n\n\u2022 Only output the label you think is most suited and nothing else\n\u2022 If you choose \"Gumroad Notifications\" output: Label_8633512660150681541\n\u2022 If you choose \"Respond To\" output: Label_6621328525648465499\n\u2022 If you choose \"General\" output: Label_7320308321061690804\n\u2022\u00a0If you choos \"instagram\" output: LABED_ID"
            },
            {
              "role": "system",
              "content": "You are a helpful, intelligent email inbox assistant"
            }
          ]
        }
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "d2ec935e-c6da-4f1c-9646-bb45d51e2d8f",
      "name": "Add Label",
      "type": "n8n-nodes-base.gmail",
      "position": [
        608,
        -112
      ],
      "parameters": {
        "labelIds": "={{ $json.message.content }}",
        "messageId": "={{ $('Watch Incoming Emails').item.json.id }}",
        "operation": "addLabels"
      },
      "typeVersion": 2.1
    },
    {
      "id": "f0192bba-e57f-414d-81a6-1565e172e446",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -768,
        -320
      ],
      "parameters": {
        "color": 5,
        "width": 356,
        "height": 256,
        "content": "## Important Info\n\n### Replace the Labels that are in the Chatgpt prompt with the labels that are in your gmail account. \n\n### Along with the label names you will need to find the Label Id's for each name which you can do using the node in RED Below"
      },
      "typeVersion": 1
    },
    {
      "id": "5de2cb7f-4338-45e7-b213-f065ee392297",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -80,
        -256
      ],
      "parameters": {
        "width": 180,
        "height": 400,
        "content": "## Marks Email As Read In your Account"
      },
      "typeVersion": 1
    },
    {
      "id": "ae40c679-a388-467e-8a2c-2ddf242892dd",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        128,
        -256
      ],
      "parameters": {
        "width": 380,
        "height": 400,
        "content": "## Selects Label to put email under and justify's / reasons as to why it has chosen the label it has. "
      },
      "typeVersion": 1
    },
    {
      "id": "fc0f114b-f149-403e-af13-6a749bb2fc89",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        528,
        -256
      ],
      "parameters": {
        "width": 260,
        "height": 400,
        "content": "## Finally, a label is added to the email"
      },
      "typeVersion": 1
    },
    {
      "id": "f180f376-184d-48e9-a220-c07f475d74f2",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -768,
        -32
      ],
      "parameters": {
        "color": 3,
        "width": 356,
        "height": 300,
        "content": "### Used to find label id's in your email account to put in the prompt of the ChatGPT (OpenAI) Node in the flow"
      },
      "typeVersion": 1
    },
    {
      "id": "a9d7eaf6-f902-4f9b-a19f-bea0a89b8764",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -352,
        -256
      ],
      "parameters": {
        "width": 260,
        "height": 400,
        "content": "## Watches Incoming Emails"
      },
      "typeVersion": 1
    },
    {
      "id": "0a289e3f-1ed7-43b3-9449-8f5bd3f38478",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1808,
        -608
      ],
      "parameters": {
        "color": 5,
        "width": 912,
        "height": 1152,
        "content": "AI inbox labelling manager that has reasoning attached to the ChatGPT inbox manager within n8n. Super simple yet highly effective automation.\n\n## How it works: \n\n\u2022\u00a0Monitors Gmail inbox \u2192 triggers workflow when a new unread email is received.\n\n\u2022\u00a0Fetches email details including subject, body, and sender information.\n\n\u2022\u00a0Sends email content to OpenAI \u2192 uses AI to determine the most relevant label based on predefined rules.\n\n\u2022\u00a0AI uses a think tool \u2192 justifies why it selected that specific label.\n\n\u2022\u00a0Retrieves Gmail label IDs \u2192 matches AI\u2019s choice to correct Gmail label for that email.\n\n\u2022\u00a0Adds the chosen label (e.g., Positive reply, priority email, etc) to the email automatically \u2192 optionally marks it as read/starred.\n\n\u2022 Continues monitoring \u2192 every new email is processed automatically, keeping the inbox organized.\n\n## Set Up Steps\n\n\u2022\u00a0Connect Gmail account to the Gmail Node\n\n\u2022\u00a0Create OpenAI account & API key \u2192 go to OpenAI and sign up or log in. Once logged in, click Dashboard in the top menu. On the left sidebar, find API Keys and click Create new key. Copy this key \u2014 you\u2019ll need it for n8n.\n\nCheck your account balance \u2192 in the top-right, click your profile icon \u2192 Your Profile \u2192 Billing. Make sure your account has funds (e.g., $5 USD is enough for testing) so the API requests can run.\n\n**Do these steps through this link:** https://platform.openai.com/\n\n\u2022\u00a0Retrieve Gmail label IDs \u2192 use the Gmail \u201cget labels\u201d node to fetch IDs for all labels you want the AI to use.\n\n\u2022\u00a0Use OpenAI (ChatGPT) node \u2192 set up system and user prompts with rules describing each label, and include the **label IDs (Important)**.\n\n\u2022\u00a0Test the workflow \u2192 send example emails, check labeling, and refine AI prompt or label rules if needed.\n\n\u2022\u00a0Tip: Pin trigger data for testing (Gmail node \"Watch Incoming Emails\") \u2192 re-use the same email record to speed up testing without sending multiple emails.\n\n## About this automation\n\nHandles multiple labels \u2192 adding new labels only requires updating the AI prompt (no extra nodes).\n\nScales easily \u2192 works for any number of Gmail labels without cluttering the workflow.\n\nFor a complete rundown on how to set this up watch my YouTube tutorial linked below\n\n### See full video tutorial here: \nhttps://www.youtube.com/watch?v=7nda4drHcWw\n\n#### My LinkedIn: https://www.linkedin.com/in/seb-gardner-5b439a260/"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "c3c81590-7766-40ba-9826-63e66eb4ce57",
  "connections": {
    "Mark Email As Read": {
      "main": [
        [
          {
            "node": "Select most appropriate Label",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Watch Incoming Emails": {
      "main": [
        [
          {
            "node": "Mark Email As Read",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Select most appropriate Label": {
      "main": [
        [
          {
            "node": "Add Label",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Justify/Reason the Label AI has chosen": {
      "ai_tool": [
        [
          {
            "node": "Select most appropriate Label",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  }
}