Build Your First AI Agent With n8n (No Coding)

Illustration for build ai agent with n8n: Build Your First AI Agent With n8n (No Coding)

To build AI agent with n8n, you connect three things on one canvas: an AI Agent node that makes decisions, a chat model that does the thinking, and tool nodes that let it act. This tutorial builds an inbox-triage agent that reads each new Gmail message, labels it, and drafts a reply for the ones that need one, with you approving every draft before it's saved. No coding is needed, and the whole build fits in an hour.

What you'll build and how long it takes

A plain automation follows fixed rules: "if the subject contains invoice, add label Finance". An agent gets a goal and a set of tools and picks what to do for each email. For triage that matters, because real emails don't follow keyword rules.

Your agent will:

  • Read every new email.
  • Apply one label: Reply needed, FYI or Low priority.
  • For "Reply needed", write a draft reply in your Drafts folder, which you approve first.
  • Never send anything on its own.

Expect 45 to 60 minutes the first time. If you've never used n8n, do our n8n tutorial for beginners first; it covers the account setup and Gmail connection in more detail.

Setup: accounts and tools (n8n, OpenAI)

  • n8n Cloud. n8n's docs describe a 14-day trial with 1,000 executions. Self-hosting works too but adds server setup.
  • Gmail. Create three labels in Gmail first: Reply needed, FYI, Low priority.
  • A chat model. An OpenAI API key, or on n8n Cloud the Use Gateway credits option that n8n's OpenAI docs describe as a way to run without your own key.

Build AI agent with n8n: step-by-step walkthrough

n8n: trigger and agent

  1. Create a new workflow called "Inbox triage agent".
  2. Add a Gmail Trigger. n8n's docs say it polls Gmail for new messages at the poll time you choose; every 5 or 10 minutes is plenty for triage. Leave Simplify on so the agent gets the sender, subject and snippet instead of the raw API response.
  3. Add an AI Agent node after it. n8n's docs state the agent needs a chat model and at least one tool connected; it won't run without a tool.
  4. In the agent's prompt, pass the email. Drag the From, Subject and snippet fields from the trigger's output into the prompt box.
  5. Open Options and add a System Message. This is the job description:

> You triage email for a small business owner. For each email, call the label tool exactly once with one of: Reply needed, FYI, Low priority. Only if the label is Reply needed, call the draft tool with a short, polite reply in plain English. Never promise refunds, prices or dates. If a tool call is denied, stop and do nothing else.

That last line matters later. n8n's human-review docs say the system prompt should tell the agent how to handle denied tool calls.

OpenAI: the chat model

Click the Chat Model connector under the agent and add OpenAI Chat Model. Choose your credential and a small model. Triage is a short classification task, so a "mini" class model is usually enough and keeps per-email cost low. See our breakdown of AI automation cost for token prices.

Tools: what the agent is allowed to do

Click the Tool connector and add two Gmail tool nodes. n8n's Gmail docs note the node can be used as an AI agent tool, with parameters filled in by the AI.

  1. Label tool. Resource Message, operation Add Label. Set the message ID from the trigger, and let the model choose the label.
  2. Draft tool. Resource Draft, operation Create. Let the model fill the message body; set the subject and thread from the trigger.

Give each tool a clear description such as "Adds one triage label to the current email". The agent reads these descriptions to decide what to call.

Deliberately leave out the Send operation. An agent that can only label and draft cannot email a customer by mistake.

Put a human review on the draft tool

n8n supports human review for AI tool calls. Per n8n's docs, you open the tools panel on the AI Agent node, choose a review channel (options include n8n Chat, Slack, Gmail, Microsoft Teams, Telegram, Discord, WhatsApp Business Cloud, Google Chat and Outlook), then connect the tools that need approval to that review step. When the agent tries to call the tool, the workflow pauses and sends you the tool name and parameters. Approve and it runs; deny and the call is cancelled.

Use the `$tool.name` and `$tool.parameters` variables in the review message so you can read the draft before approving it. Keep the label tool unreviewed; a wrong label costs nothing. For more on approval patterns across tools, see our guide to human-in-the-loop AI automation.

Testing and fixing common errors

Memory

You don't need memory for this agent. Each email is a separate task, and carrying earlier emails into the next one can confuse labels. Memory is for chat-style agents. If you add the Simple Memory node to a chat agent later, note n8n's warning that it doesn't work in an active production workflow when your instance uses queue mode.

Gmail

  • Agent labels nothing. The tool description is vague or the label names don't exactly match Gmail. Copy the names exactly into the system message.
  • Agent calls the label tool three times. Add "exactly once" to the system message, and lower the agent's Max Iterations option, which n8n's docs say defaults to 10.
  • Drafts land outside the thread. Map the thread ID from the trigger into the draft tool instead of letting the model guess it.
  • Credential errors. Reconnect your Google credential with the same account the trigger watches.

Test with five emails you write yourself: a customer question, a newsletter, an invoice, a complaint and a spam-like offer. Check every label and draft before you publish.

Making it reliable day to day

  • Read the Executions list daily for a week. Each run shows which tools the agent called and with what inputs.
  • Add an error workflow so failures email you.
  • Exclude sensitive mail with a Gmail filter that skips the trigger for banking, payroll or medical senders.
  • Review before widening. Only give the agent new tools, such as a calendar or CRM, after it has labelled correctly for a couple of weeks. Each new tool is a new way to be wrong.

If you later want the same agent to reach tools outside n8n, look into MCP (Model Context Protocol), the protocol many AI tools now use to connect to apps. For where n8n sits among the main automation platforms, see the Zapier vs Make vs n8n comparison.

FAQ

Can I build an AI agent without coding?

Yes. In n8n you connect an AI Agent node to a chat model and tool nodes on a canvas and describe the job in plain English. You may type a few short expressions, but they can be dragged in from the data panel.

What is an AI agent in n8n?

It's the AI Agent node: a step that uses a chat model to decide which connected tools to call, and in what order, to finish a task. n8n's docs say it needs a chat model and at least one tool.

How much does running an agent cost?

You pay for n8n (one execution per workflow run on Cloud plans) plus the AI model's tokens. As of October 2026, n8n Cloud Starter is listed from EUR 20 a month billed annually, and small OpenAI models cost fractions of a cent per short email.

Conclusion

Build the label-only version first and run it for three days. When the labels look right, connect the draft tool behind human review. Only once you trust its drafts should you consider letting it do more, and keep sending in human hands.

Sources and methodology

Desk research of official documentation; no hands-on test results are claimed. Last reviewed 7 October 2026.

  • n8n AI Agent node: https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.agent/
  • n8n human review for AI tool calls: https://docs.n8n.io/advanced-ai/human-in-the-loop-tools/
  • n8n Gmail node and Gmail Trigger: https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.gmail/
  • n8n Simple Memory: https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.memorybufferwindow/
  • n8n OpenAI node: https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-langchain.openai/
  • n8n pricing and Cloud trial: https://n8n.io/pricing/ and https://docs.n8n.io/deploy/use-n8n-cloud/start-your-free-trial/
  • OpenAI API pricing: https://developers.openai.com/api/docs/pricing