Tools

How to build an AI agent with n8n, the complete tutorial

Six steps to go from an empty canvas to an agent that acts inside your tools, and the safeguards to set before running it in production.

Louis Graffeuil
Louis Graffeuil
Founder Tandem
August 10, 2026Published
11 minread
3D illustration of a robot being assembled and plugged in with a cable

Building an AI agent with n8n takes about ten minutes for a first version. You add a trigger, drop in the AI Agent node, connect a language model, one or more tools and a set of instructions, then test it in the built in chat. That part is not the hard part. The gap sits between a demo that works first try and an agent that runs every day unattended, and this guide covers both.

Tandem builds these agents for small and mid sized companies, from Santiane to Nomination and KparK, and the pattern repeats. Teams build their first agent unaided, then hit memory, infinite loops and write permissions. This tutorial walks through the six build steps, then the six safeguards that are almost always missing. If the platform is new to you, start with our complete guide to n8n, which covers nodes, executions and use cases before agents.

What exactly is an AI agent in n8n?

An AI agent in n8n is a single node, called AI Agent, that receives a request, picks the tools to call on its own and chains those calls until it reaches a result. The artificial intelligence model sitting behind that node carries the decision, and that is what sets it apart from a classic workflow. In a workflow, you decide the order of the steps in advance. In an agent, you describe the goal and the available tools, and the model decides the order at run time.

Diagram of the anatomy of an AI agent in n8n, a trigger connected to the AI Agent node, itself connected to three slots, Chat Model and Tool required, Memory optional
One trigger, one central node, three slots to fill. That is the entire structure of an n8n agent.

Three sub-nodes plug in underneath the AI Agent node. The Chat Model carries the reasoning and is required. Tools define what the agent is allowed to do, and at least one is required. Memory keeps the thread of the conversation and is optional. Since n8n version 1.82.0, every AI Agent node runs in Tools Agent mode, the other agent types having been removed from the interface, as the official documentation states.

What you need before you start

Three prerequisites are enough to build a first agent. You need a reachable n8n instance, an API key from a model provider, and access to the tools the agent will operate. No development skills are required for this first version.

  • An n8n instance, either a cloud account to start within two minutes, or a self hosted install on your own server if your data must not leave. Cost details are in our article on n8n pricing.
  • A model API key, from OpenAI, Anthropic, Mistral or Google. A few euros of credit cover the entire testing phase, an agent under construction generates little traffic.
  • Access to your business tools, a Google Workspace account, a CRM, a Notion or Airtable base. Create a dedicated service account for the agent rather than using your own, you will be glad of it when the time comes to revoke access.
  • A use case written in one sentence, something like "answer availability requests by checking the calendar and offering three slots". An agent without a written goal becomes an expensive chatbot.

On the platform choice itself, our n8n, Make and Zapier comparison covers billing units and data constraints. n8n remains the only one of the three that can be self hosted, which weighs heavily when the agent handles customer data.

Step 1: lay down the skeleton

Open an empty workflow and add the AI Agent node from the right hand panel. n8n automatically places a chat trigger in front of it, which lets you test the agent in the built in conversation window from the very first minute. That trigger can then be swapped for whatever you need, a webhook, an incoming email, a daily schedule or a button inside your internal tool.

The canvas then shows the AI Agent node with three empty slots underneath. That is the complete structure, and it will not change. Everything that follows consists of filling those three slots, then writing the instructions.

I build an n8n AI agent end to end in ten minutes, from adding the node to automatically sending an email.

Step 2: pick the model that drives the agent

Click the Chat Model slot and select your provider. n8n accepts models from OpenAI, Anthropic, Mistral, Google, Azure and Groq, as well as open models served locally through Ollama. Paste your API key into the credential, choose a model and the agent becomes functional.

The useful reflex is to start with a fast, cheap model throughout the build, then move up only if decision quality suffers. An agent that picks the wrong tool is more often fixed by better instructions than by a bigger model. If your data must stay in Europe, check where the API runs before choosing the provider, that criterion is handled at the start and not after go live.

Step 3: connect the tools, and let the agent fill the fields

The Tool slot accepts everything the agent will be allowed to do, sending an email, creating a row in a database, calling an API, running another n8n workflow or reaching an MCP server. The official integration page for the AI Agent node lists 422 connectable apps and services, a figure checked on 10 August 2026. Every tool you add needs a clear description, because that description is what the model reads to decide whether to call it.

Two column comparison of connecting a tool to an n8n agent, on the left the manual mapping of every field, on the right the $fromAI function letting the agent fill the values
Moving from manual mapping to $fromAI completely changes how long an n8n agent takes to build.

The real unlock sits in one function, $fromAI. Every field of a tool connected to the agent carries a button that replaces the value with an expression letting the model decide the content at run time. You describe what the field expects, the agent fills it. n8n documentation covers this function and states its limits, it works neither with the Code node nor with sub-nodes that are not tools.

I summarised the shift in my Optimia newsletter of March 2025, then in a LinkedIn post. Before this function, connecting a tool meant mapping every parameter by hand and formatting values to satisfy the API. Since then, the example fits in one sentence. You ask for an email in HTML, you say so in the field description, and the agent produces the body in the right format with no technical mapping.

Step 4: write the agent instructions

The System Message field carries the agent's standing instructions. It is the parameter that determines output quality, far more than the choice of model. A useful instruction set describes the role, the goal, the available tools and their usage, the accessible data, the expected tone and the cases where the agent must stop and hand back control.

  1. The role and the scope, in one or two sentences. "You are the practice scheduling assistant, you handle appointment requests only."
  2. The tool list, with what each one does and when to call it. The model reads that list before every decision.
  3. Reference data, opening hours, business rules, expected formats. Anything the agent cannot guess must be written down.
  4. Stop conditions, the situations where the agent hands over to a human rather than improvising. This is the most frequently forgotten part and the most profitable one.

My advice on this point is worth repeating. Have a language model draft the first version of the instructions from your description of the process, then correct it. You save an hour and you get a clean structure from the start.

Step 5: add memory, and understand its limit

Without memory, every call starts from scratch. The agent does not remember the previous question, which suits a one off task triggered by a webhook but breaks any conversation. The Memory slot is filled with the Simple Memory node to get started, which stores exchanges directly inside the n8n instance.

Simple Memory is fine in testing and a real problem in production. n8n documentation states that this node does not work in an active workflow when n8n runs in queue mode, because nothing guarantees that two successive calls reach the same worker. As soon as your agent serves several users or runs on a distributed instance, replace it with persistent memory backed by Postgres or Redis. The Context Window Length parameter decides how many exchanges are replayed on each turn, and setting it too high raises cost without improving answers.

Step 6: test, then harden before production

The built in chat window lets you test the agent without leaving the canvas. Every execution is shown node by node, with inputs and outputs, which makes debugging readable. The Return Intermediate Steps option adds the detail of the agent's decisions, and it is the first reflex when a tool call goes sideways.

The six safeguards to set before putting an n8n agent into production, persistent memory, iteration cap, error handling, restricted permissions, human validation and logging
The six checks Tandem runs before switching on an n8n agent at a client.

The Max Iterations parameter deserves a mention of its own. It caps the number of turns the agent allows itself before giving up, and defaults to 10 in the Tools Agent. An agent looping on a failing tool burns tokens on every iteration, and that is the most unpleasant bill to discover. Set that cap deliberately rather than leaving the default.

PointIn a demoIn production
MemorySimple MemoryPostgres or Redis
IterationsDefault value, 10Cap set and monitored
ErrorsExecution stopsRetry and dedicated error branch
PermissionsThe author's accountRestricted service account
Sensitive actionsDirectHuman validation in the loop
MonitoringCanvas historyExported log and alerting
What changes between a demo agent and a production agent

One agent or several sub-agents?

The more tools you give an agent, the more it scatters. That is the limit I flagged back in March 2025, and it has not moved. An agent with twenty tools chooses worse than an agent with five, because every extra description dilutes the decision. The answer is to split the tasks and give a main agent a set of specialised sub-agents, each with a narrow scope.

The advice that comes with that split matters as much as the split itself. Start small. One agent, three tools, one use case. You verify that the automation genuinely adds value before building a layered architecture. Our article on AI agents versus AI workflows covers where the line sits between the two, and why most enterprise gains still come from workflows.

Letting Claude Code build the agent

An interesting variant emerged in early 2026. Rather than configuring the agent by hand on the canvas, you describe the business need to a development agent such as Claude Code, connected to your n8n account through an MCP server. It proposes an architecture, then creates the workflow directly inside your instance.

First page of my Claude Code and n8n guide, showing the goal of the guide and the prerequisites on the tooling side and the n8n side, including the n8n API key to create in the settings
Source: my LinkedIn post of January 2026. It details the MCP setup and the Skills to hand to the development agent.

The point I stress in that post is worth repeating, because it runs against the general expectation. The lever is not the prompt. It is the MCP setup and the Skills, meaning the tools you give the development agent and the procedures you teach it. The human keeps the last mile, reviewing the workflow before activation. This approach speeds up the build, it does not remove the need to understand what was built.

I have Claude Code build n8n workflows and compare the result to what I would have built myself.

What an n8n agent that genuinely runs looks like

Agent demos all look alike. Agents in production, far less so. Koralplay, an 85-person gaming software company, has 70 % of its payment support tickets handled by an automated system, with more than 4,000 executions a week and 616 hours freed every week. The scope is narrow, the volume is high, and the business rule is written down. Those three conditions together make an agent that holds.

Musixmatch illustrates the other model, the agent that serves an internal team. Twenty-seven workflow modules brought the handling of recurring client requests down to fifteen seconds, for 47 engineering days saved in four months. Martino Bonfiglioli, Senior Product Manager, draws a conclusion that applies to your project, the point was to make everybody autonomous, not to build the most impressive system.

How long does an n8n agent take, and what does it cost?

The first version runs in about ten minutes, and the video above shows it end to end. An agent that is genuinely useful internally, tested and documented, takes more like two to three days. An agent in production with the six safeguards, clean permissions and monitoring is counted in weeks, not hours. On licensing, n8n stays free when self hosted and the cloud plan details are in our article on the real cost of n8n.

The variable cost comes from the models, not from the platform. An agent handling a hundred requests a day on a fast model stays within a few tens of euros a month. The same agent wired to a top tier model, with a wide memory window and uncapped iterations, can cost ten times more for a marginal quality gain. That is the first line item to watch after go live.

Should you build your n8n AI agent yourself?

Yes for the first one, without hesitation. Building a simple agent with the AI Agent node, a model and three tools is within reach of a non technical person in a morning, and that experience beats any training course. You learn what the agent handles well, what it misses, and where the real value sits in your processes.

The tipping point comes at production. An agent that writes into the CRM, handles customer data or triggers financial actions needs restricted permissions, human validation on irreversible actions and a usable log. That is where Tandem steps in, on scoping and on hardening. Our autopilot offering covers that transition, and our n8n team takes over the build when the scope outgrows an internal experiment.

A demo impresses. An agent lasts because it has safeguards.

Frequently asked questions

Do you need to code to build an AI agent with n8n?

Not for a first version. The AI Agent node is configured entirely by mouse, and the $fromAI function fills tool fields without writing an expression. A non technical person can build a simple agent in a morning. Code becomes useful again for complex data transformations and for self hosting the instance, two topics that come after the first go live.

What is the difference between an n8n workflow and an n8n AI agent?

In a workflow, you set the order of the steps in advance and n8n runs it identically every time. In an agent, you provide a goal and a list of tools, and the model decides which tools to call and in what order. Workflows win on stable processes because they are predictable and cheap. Agents win when the incoming request varies too much to be scripted.

Which model should you pick for an n8n AI agent?

Start with a fast, inexpensive model from OpenAI, Anthropic, Mistral or Google, and keep it throughout the build. Move up only if the agent keeps picking the wrong tools despite precise instructions. n8n also accepts open models served locally through Ollama, which becomes the default choice when the data being processed must not leave your infrastructure.

How long does it take to put an n8n agent into production?

A first version works in about ten minutes. An agent that is genuinely useful internally, tested and documented, takes two to three days. Going to production adds persistent memory, an iteration cap, error handling, a restricted service account, human validation on irreversible actions and a usable log, which is counted in weeks depending on how critical the process is.

Can you build an n8n AI agent for free?

The platform yes, the agent not entirely. n8n can be downloaded and self hosted with no licence, so the orchestration side only costs you a server. The language model, however, is billed per use by the API provider. An agent in testing stays under a few euros a month. An open model served locally through Ollama removes that line too, at the price of machine power.

Read next

All articles
ToolsClay illustration of a rotating contact card carousel with one coral card raised above the rest, next to a funnel and handshake and database icons

The best AI CRMs, compared on what the AI actually does in them

By Louis Graffeuil
ToolsClay illustration of a desk inbox tray full of slips, one coral slip lifting out of it, next to speech bubble, checkmark and clock icons

The best AI ticketing tools, compared on what a ticket really costs

By Louis Graffeuil
ToolsClay illustration of an open toolbox surrounded by target, envelope and phone icons, standing for an AI sales tool stack

The best AI sales tools, compared on what they actually cost

By Louis Graffeuil