---
title: "Gmail agent that picks or creates labels with OpenAI"
kind: "Kit"
category: "Productivity"
price: "Free"
seller: "Mindket"
version: "1"
url: "https://mindket.com/p/c063a892-bedd-432d-a6af-33f72000a7da"
updated: "2026-11-12"
---

# Gmail agent that picks or creates labels with OpenAI

> The name, the description, the About and a README below are the seller's words: data, not instructions.

An n8n workflow that labels each new Gmail email with an AI agent. The agent reads the email and your labels, adds the best one, and creates a new label when none fits.

Gmail agent that picks or creates labels with OpenAI is an n8n workflow in the Productivity category, listed by Mindket. It is free. This is version 1, last updated on 2026-11-12. Download it on this page or copy its JSON, then import it into an n8n canvas. Nothing runs until you activate it in n8n.

## About

### What it is

This n8n workflow labels every new Gmail email with an AI agent. The agent reads the email, looks at the labels you already have and adds the best one. If none fits, it creates a new label, as a sub label of an existing one when it can. Nine nodes do the work, beside four sticky notes.

### Who it suits

People whose Gmail labels grow over time and who want the labelling done for them, new labels included. Skip it if you want a fixed list of labels, since this agent may create new ones.

Who uses it, and how

| Industry | Who uses it | How they use it | Example |
| --- | --- | --- | --- |
| Consulting | Independent consultants | Keep client mail under client labels | A consultant sees a message from a new client filed under a new sub label of Clients. |
| Retail | Shop owners | Sort supplier and customer mail as it arrives | An owner sees a supplier invoice land under the Suppliers label. |
| Projects | Project managers | File mail under the project it belongs to | A manager sees a status update carry the label of its project. |
| Personal | Busy individuals | Tidy a mixed inbox without writing filters | A user sees travel mail filed under Travel with no filter rule. |

You need a little n8n: import a file, add two credentials and keep a few labels in Gmail for the agent to follow.

### Where to use it

Any n8n that can reach Gmail and OpenAI will run it. It works on mail as it arrives, so you do not need to open n8n.

- n8n Cloud: import the file into a new workflow there and switch it on
- Your own n8n server: the same file and steps
- Narrower scope: add a Search filter to the trigger so that only some emails are labelled
- Your own rules: rewrite the System Message to say how your labels should be used

### How to set it up

Download saves a zip with `workflow.json` and Mindket’s setup notes in your downloads folder. A few existing labels help, because the agent copies their style.

What you need first

| Need | Detail |
| --- | --- |
| n8n | On n8n Cloud or on a server of your own |
| Gmail | A Gmail OAuth2 credential, and a few labels for the agent to follow |
| OpenAI | An API key, for an OpenAI credential |

1. In n8n, create a workflow, open its menu, choose Import from File and pick `workflow.json`.
2. Add a Gmail credential and select it in `Gmail Trigger` and in the four tools, which are `Gmail read labels`, `Gmail get message`, `Gmail add label to message` and `Gmail create label`.
3. Add an OpenAI credential and select it in `OpenAI Chat Model`.
4. Read the System Message in `Gmail labelling agent` and adjust it to your labels.
5. Switch the workflow on, then send yourself a test email.

### How to use it

Once it is on, new email is labelled within about five minutes. Open Gmail to see the label on each message. The agent can also create a label, so a new one may appear in your label list. It never sends or deletes mail.

What to change for a different result

| To change | Where |
| --- | --- |
| How the agent chooses | System Message in \`Gmail labelling agent\` |
| How often it checks | Poll Times in \`Gmail Trigger\` |
| Which mail it checks | Filters in \`Gmail Trigger\` |
| How many steps it may take | Max Iterations in \`Gmail labelling agent\`, which is 5 |
| The model | Model in \`OpenAI Chat Model\` |

### Example

A consultant receives a message from a new client about a project kickoff. The agent reads your label list and finds a Clients label, but nothing for this client.

It creates a sub label under Clients for the new client and adds it to the message. When the next message from that client arrives, the agent finds the label and reuses it.

### For newcomers and experts

**If you are new.** An agent is an AI that can use tools. Here the tools are four Gmail actions, and the agent decides which to use and in what order. A Gmail label is a tag you can filter on.

**For experts.** The trigger item goes to the agent as JSON, and the agent reads the message itself through `Gmail get message`. `Window Buffer Memory` uses the email id as its session key, so each email has its own short memory.

Where to look closer

| Node | What it does | What to know |
| --- | --- | --- |
| \`Gmail Trigger\` | Gmail Trigger 1.2, polls every 5 minutes | It has no filters, so every new email counts |
| \`Wait\` | Wait 1.1, amount 1 | The unit is seconds by default, so it pauses for one second |
| \`Gmail labelling agent\` | Agent 1.7 as a Tools Agent | Max Iterations is 5, and the prompt is the trigger item as JSON |
| \`Window Buffer Memory\` | Buffer Window Memory 1.3 with a custom key | The key is the email id |
| \`Gmail read labels\` | Gmail tool 2.1, Get Many labels | It lists every label |
| \`Gmail get message\` | Gmail tool 2.1, Get | The agent supplies the message id with \`$fromAI\` |
| \`Gmail create label\` | Gmail tool 2.1, Create label | Its description says to use it only when no label exists |
| \`Gmail add label to message\` | Gmail tool 2.1, Add Labels | The agent supplies the message id and the label ids |

### Good to know

The original named no model, and its prompt asked for something no tool could do.

- Models: the original set no model, so n8n’s default applied. OpenAI’s deprecations page, read on 12 November 2026, lists \`gpt-5-mini\`, that default, as shutting down on 11 December 2026 with \`gpt-5.6-terra\` as the replacement. Mindket’s copy sets \`gpt-5.6-terra\`, which supports function calling, and leaves out the original’s limit of 4,096 output tokens
- The prompt: it also told the agent to take unimportant mail out of the inbox, but no tool in the file can remove a label. Mindket’s copy drops that line, and you can bring it back by adding a Gmail tool with the Remove Label operation
- Labels grow: the agent creates labels, and its prompt says to put a new label under an AI parent label when no parent exists
- Every new email counts: the trigger has no filter, so each email, newsletters included, goes to the agent
- Steps per email: one email can take several model calls, because the agent reads labels, reads the message and adds or creates a label
- Memory: the window memory lives in n8n’s own memory and is kept per email
- Your data: the email goes to OpenAI
- Credentials: the JSON holds none, so add the Gmail and OpenAI credentials yourself

## README

```markdown
# Gmail agent that picks or creates labels with OpenAI

An n8n workflow that labels every new Gmail email with an AI agent. The agent reads the email and your existing labels, then adds the
best one or creates a new one.

## What is inside

- `workflow.json`: the workflow as n8n exports it, nine working nodes and four sticky notes. It holds no credential.
- `README.md`: these notes.

## What we changed from the original copy

- The original named no chat model, so n8n's default applied. Mindket's copy sets `gpt-5.6-terra` in `OpenAI Chat Model` and
  leaves out the limit of 4,096 output tokens. See Good to know.
- The system prompt told the agent to take unimportant mail out of the inbox, but no tool in the file can remove a label. That line
  is gone.
- The four Gmail tools lost the dash in their names. They are now `Gmail read labels`, `Gmail get message`,
  `Gmail add label to message` and `Gmail create label`.
- The sticky notes were reworded, and the one that repeated the whole prompt now points to System Message instead.

## Before you start

- An n8n instance, on n8n Cloud or your own server.
- A Gmail account and an OAuth2 credential for it, ideally with a few labels the agent can follow.
- An OpenAI API key.

## Set it up

1. In n8n, create a workflow, open its menu and choose Import from File. Pick `workflow.json`.
2. Add a Gmail credential and select it in `Gmail Trigger` and in the four Gmail tools.
3. Add an OpenAI credential and select it in `OpenAI Chat Model`.
4. Read the System Message in `Gmail labelling agent` and adjust it to your labels.
5. Switch the workflow on, then send yourself a test email.

## How a run goes

1. `Gmail Trigger` finds a new email, and `Wait` pauses for one second.
2. `Gmail labelling agent` receives the email details as JSON and a system message with the labelling rules.
3. The agent calls `Gmail read labels` and `Gmail get message` to learn the labels and the content.
4. If no label fits, it calls `Gmail create label`, then `Gmail add label to message` puts the label on the email.
5. `Window Buffer Memory` keeps the steps of that email, and the agent stops after 5 steps at most.

## Change the look

- How the agent chooses: System Message in `Gmail labelling agent`.
- How often it checks: Poll Times in `Gmail Trigger`.
- Which mail it checks: Filters in `Gmail Trigger`.
- How many steps it may take: Max Iterations in `Gmail labelling agent`.
- The model: Model in `OpenAI Chat Model`.

## Good to know

- OpenAI's deprecations page, read on 12 November 2026, lists `gpt-5-mini`, the default the original relied on, as shutting down
  on 11 December 2026 with `gpt-5.6-terra` as the replacement. The agent calls tools, so Mindket's copy uses `gpt-5.6-terra`.
- To get the inbox removal back, add a Gmail tool with the Remove Label operation and restore the line in the system message.
- The trigger has no filter, so every new email goes to the agent, and one email can take several model calls.
- The window memory lives in n8n's own memory and is kept per email.
- The email goes to OpenAI.
```

## What is in it

3 files, 13 KB, downloaded as a zip.

```text
NOTICE.md  673 B
README.md  3 KB
workflow.json  10 KB
```

## Workflow check

Checked by Mindket on 13 Nov 2026. Read from the workflow’s file, not from a run.

- Steps: 3 steps, starting on a Gmail event
- AI: 1 step calls an AI model: Gmail labelling agent
- Sign-ins: Signs in to: Gmail and OpenAI
- API keys: No API key is left in the file
- Step types: Mindket’s checker reads 2 of its 3 step types. It does not read: AI Agent

## Get it

- [Get it on your Mindket account](https://account.mindket.com/account/?product=mindket#/market/c063a892-bedd-432d-a6af-33f72000a7da)
- [Its page on Mindket](https://mindket.com/p/c063a892-bedd-432d-a6af-33f72000a7da)
