You have 40 unread emails, three of them matter, and you cannot tell which until you open every one. You have probably already built a simple n8n workflow or two. Now you want the part everyone talks about: an agent that makes small decisions for you.
This n8n tutorial for an AI agent builds one specific thing: an inbox triage agent. It reads each new email, decides what kind it is, looks up the sender in your own client list when that helps, and leaves a draft reply for you to check. It never sends anything on its own. If you have not built an agent before, start with our first n8n agent walkthrough. This one is the second step: structured output, a tool that is a workflow of your own, and a way to see what the agent did.
Prefer a simpler flow without an agent? The n8n email follow-up workflow uses seven plain nodes to catch unanswered emails and draft the reminder.
No password needed – your reset opens instantly.
No password. Just your email, and you’re in.
What you are building
Four pieces, in this order:
- Gmail Trigger starts the workflow when a new email arrives.
- AI Agent node with a chat model reads the email and decides what to do.
- Structured Output Parser forces the answer into fixed fields (category, urgency, draft).
- Gmail, create draft saves the reply as a draft so you stay in charge.
The agent also gets one tool: a small sub-workflow that looks up the sender in a sheet of your clients. That tool is what makes it an agent and not a plain prompt. The model decides when it needs the lookup.
Looking for a first use case for this agent? Our AI agent for internal workflow automation guide shows a team-inbox example with a human check.
Before you start
You need an n8n account (cloud or self-hosted), a Gmail account connected to n8n, and an API key for a chat model such as OpenAI, Claude or Gemini. If you have never opened n8n, do our n8n tutorial for beginners first. It takes about an hour and covers the credentials.
Also prepare a simple Google Sheet with three columns: email, name, current project. Ten rows is enough to test.
Step 1: Build the lookup tool as its own workflow
Create a new workflow and start it with an Execute Workflow Trigger. Add a Google Sheets node that looks up a row where the email column matches the address you pass in. Return the name and current project. Save it as “client_lookup”.
Keeping the tool as a separate workflow has a practical benefit. You can test it alone with a sample address before the agent ever touches it, so when something breaks later you know the lookup is not the cause.
Step 2: Add the trigger and the agent
In your main workflow add the Gmail Trigger, set to poll for new messages. Connect it to an AI Agent node. Under the agent, connect your chat model. The AI Agent node needs at least one tool connected, which is what step 3 does (n8n docs: AI Agent node).
In the agent’s prompt field, pass the email in with an expression, for example the sender, the subject and the text body from the trigger. Put your rules in the system message, not in the user prompt. This is the system message I would start with:
You triage incoming email for a freelance consultant. Read the email and return only the requested fields. Categories: new_lead, client_question, invoice, scheduling, other. Urgency: high only if the sender names a deadline within 2 days. If the category is client_question or new_lead, call the client_lookup tool with the sender's email address first. Never invent a project, price or date. If the lookup returns nothing, say so in the draft and ask one clarifying question. Write the draft reply in my voice: short, warm, no jargon.
Notice what it does. It names the allowed categories, gives a concrete rule for “high” urgency, says when to use the tool, and forbids inventing facts. Vague instructions such as “be helpful and prioritise” give you vague triage.
Step 3: Connect the lookup as a tool
On the agent, add the Call n8n Workflow Tool and select “client_lookup”. Give it a clear name and a one-line description such as “Finds a client by email address and returns their name and current project”. The model reads that description to decide when to call the tool, so write it like a note to a new colleague (n8n docs: Call n8n Workflow Tool).
Step 4: Make the answer a fixed shape
Free text is hard to route. In the AI Agent node, switch on the option that requires a specific output format, then attach a Structured Output Parser and give it an example like this:
{
"category": "client_question",
"urgency": "low",
"summary": "Asks if the report can move to Friday",
"draft_reply": "Hi Sam, Friday works. I will send it by noon."
}
Now every run returns the same four fields, and the next node can use them. The parser is documented in the n8n Structured Output Parser docs.
Step 5: Save a draft, never send
Add a Gmail node after the agent and choose the action that creates a draft. Reply text is the draft_reply field. Put the category and urgency in a Gmail label if you like, so your inbox sorts itself.
Keep this step as a draft for at least the first two weeks. A wrong draft costs you ten seconds to fix. A wrong sent email to a client costs much more. Our guide to drafting reply emails faster with ChatGPT covers how to review drafts quickly.
Step 6: Test with five emails you already have
Do not wait for live mail. Pin a real old email to the trigger and run the workflow. Use five different ones: a new enquiry, a question from a known client, an invoice, a scheduling request and a newsletter. Check the same three things every time:
- Is the category right?
- Did it call the lookup when it should, and not when it should not?
- Does the draft contain only facts that are in the email or the lookup result?
When one fails, change one line of the system message and run the same email again. Changing three things at once tells you nothing.
Reading what the agent actually did
When an answer looks wrong, open the run in the executions list and click the AI Agent node. You can see the input, the output and the sub-steps the agent took, including which tool it called and what came back (n8n docs: executions). Most failures show up here as one of two things: the tool was never called because its description was unclear, or it was called with the wrong input.
Four things that go wrong in a first triage agent
- The agent calls the tool for every email. Say in the system message exactly when to use it.
- Urgency is “high” for everything. Replace “important” with a rule you can check, such as a named deadline within two days.
- The draft promises something. Add “never agree to a price, date or deliverable” to the system message.
- The model costs more than expected. Long email threads mean more text for the model on every run. Pass in only the latest message, not the full thread.
When you should not use an agent here
If your rule is “anything from my accountant goes to a folder”, a normal filter does that for free and never gets it wrong. Use the agent only where the decision needs reading comprehension. Our n8n workflow automation examples show where a plain workflow is the better pick.
Questions people ask
Do I need to code to build an n8n AI agent?
No. Every step above uses nodes and expressions. The most “technical” part is the example JSON for the output parser, and you can copy the one above.
Which chat model should I use?
Any model that supports tool calling in n8n works. Start with the one you already have an API key for, run your five test emails, and only switch if the results are poor.
Can the agent reply to emails on its own?
It can if you connect a send action, but I would not for client mail. Drafts first, then decide after you have seen two weeks of real results.
Is this better than a Gmail filter?
For fixed rules, no. A filter is simpler and exact. The agent earns its place when the email has to be read to know what it is.
Build yours this week
Pick your noisiest inbox, build the lookup tool first, and test on five old emails before you go live. If you want more practical AI workflows like this one for your own work, join the free Launchpad at RobotsHelp.
No password needed – your reset opens instantly.
No password. Just your email, and you’re in.
Sources
- n8n docs: AI Agent node
- n8n docs: Call n8n Workflow Tool
- n8n docs: Structured Output Parser
- n8n docs: Executions
Once the email triage agent runs, see which n8n AI agent skills are worth adding next.
Want the agent to answer from your own documents instead of guessing? Try n8n AI agent RAG.