September 27, 2026 · 12 min read

How to Build an AI Agent in n8n: Step-by-Step Guide With Memory, Tools and MCP

Build a working AI agent in n8n 2.x from an empty canvas: chat trigger, system message, memory that survives production, tools filled by the model, human approval before risky actions, MCP in both directions, and what each run really costs.

Editor, StackLedge

Most "build an AI agent in n8n" tutorials were written for a version of n8n that no longer exists. The agent type dropdown is gone. The Active toggle became a Publish button in n8n 2.0. Tools can now stop and ask a person before they run, and since April 2026 n8n speaks MCP in both directions. Follow last year's guide and you will lose an evening wondering why the live chat never answers.

This guide builds one working agent from an empty canvas on current n8n 2.x. The example is deliberately ordinary: an order assistant for a small online shop that looks orders up in a Google Sheet, checks delivery status through a courier's API, and writes customer emails that a person approves before they go out. Swap the sheet for your CRM and it is the same build.

One warning first. An agent is the most expensive and least predictable way to automate anything in n8n. It earns its place when the input is messy human language and the next step depends on what the person meant.

What is an AI agent in n8n, exactly?

It is one node, the AI Agent node, with sub-nodes plugged in underneath. The agent receives a message, asks the model what to do, runs whichever tool the model picks, hands back the result, and repeats until it has an answer.

Sub-nodeRequired?What it doesSensible first choice
Chat modelYesThe LLM that reads, reasons and picks toolsA tool-calling model from OpenAI, Anthropic, Google or OpenRouter
ToolsYes, at least oneWhat the agent can do: read a sheet, call an API, run a workflowGoogle Sheets, HTTP Request, Call n8n Workflow
MemoryNoEarlier messages in the same conversationSimple Memory for testing, Postgres Chat Memory for production
Output parserNoForces the answer into a fixed shape, such as JSONStructured Output Parser, only when another node reads the answer

Older guides ask you to choose between a Conversational Agent, a ReAct Agent and others. That setting was deprecated in n8n 1.82.0, and every AI Agent node now works as a Tools Agent.

What do you need before you start?

  • n8n on version 2.x. Cloud or self-hosted. Self-hosters should update first.
  • An API key for a model provider. OpenAI, Anthropic, Gemini, Mistral and OpenRouter all have chat model nodes. Ollama runs local models, though small ones choose tools noticeably worse.
  • Something to work on. Here, a Google Sheet called Orders with order number, customer name, email, status and tracking number. Ten made-up rows will do.

How do you build an AI agent in n8n, step by step?

Step 1. Add a Chat Trigger.

Start a new workflow with the trigger "When chat message received". It gives you a chat panel for testing and, later, a public chat page or embeddable widget. Each message comes out with two fields that matter: chatInput, what the person typed, and sessionId, which identifies the conversation. Leave "Make Chat Publicly Available" off for now.

Step 2. Add the AI Agent node.

Connect an AI Agent node and leave Prompt on "Take from previous node automatically", so it reads chatInput. If a form or a Telegram message feeds the agent later, switch to "Define below" and point it at the right field.

Step 3. Connect a chat model.

Click the Chat Model connector, add a credential and choose a model. For tool use, pick a current mid-sized model rather than the cheapest on the list. Tool calling is where small models fail first: they choose the wrong tool, invent parameters, or skip the tool and guess. Keep temperature low, around 0.2, so the same question produces the same lookup.

Step 4. Write the system message.

Add a System Message under the agent's options. Most agents succeed or fail here, and the usual mistake is writing a personality instead of working rules. This is the one for the order assistant:

System message:
You are the order assistant for Hollow Oak Candles, a small online shop. Staff ask you about customer orders.
Always look the order up in the Orders sheet before saying anything about it. If it is not there, say so and ask for the order number.
For delivery questions, call the tracking tool with the tracking number from the sheet. Never guess a delivery date.
Only email a customer when staff ask you to. Every email is reviewed by a person first. If a review is denied, say so and ask what to change.
Today is {{ $now.toFormat('yyyy-MM-dd') }}.
Keep answers under 120 words.

It names each tool by its job, says when to use it and what to do when nothing turns up. It also mentions human review, which n8n's documentation recommends so the agent handles a refusal sensibly. The date line matters more than it looks, because models do not know what day it is and "was this sent over a week ago?" is exactly what staff ask.

Step 5. Add memory.

Without memory every message starts from zero, so "and her other order?" means nothing. Add Simple Memory under the Memory connector. With a Chat Trigger connected, it keys the conversation on sessionId automatically. Context Window Length sets how many past exchanges go back to the model. The starting value of 5 suits a staff assistant. Raising it to 20 makes every single message more expensive, because the whole window travels with each request.

Simple Memory is fine for building and a trap later. n8n's docs state that on an instance running in queue mode it does not work in an active production workflow, since a follow-up can land on a worker that never saw the conversation. Before going live, swap it for Postgres Chat Memory or Redis Chat Memory.

Step 6. Give the agent tools.

Add a Google Sheets tool under the Tools connector, set to get rows from Orders filtered on the order number column. Leave the filter value empty and click the small star icon at the end of the field instead, which lets the model fill it. Behind it n8n writes a $fromAI() expression that you can edit to add a hint, such as $fromAI('order_number', 'The order number, like HO-1042', 'string'). The model reads that hint, so write it for the model.

Then change the tool description from "Set Automatically" to "Set Manually" and write one plain sentence: "Look up a single order by its order number. Returns status, customer email and tracking number." Models choose tools almost entirely from these descriptions. Vague ones get mixed up. Precise ones rarely do.

Add an HTTP Request tool pointed at your courier's tracking API, with the tracking number filled by the model the same way, and a Gmail tool set to send a message, with recipient, subject and body left to the model.

Keep the toolbox small. Every tool adds its description and parameters to every model request, so each extra one costs tokens and invites wrong picks. An agent that seems to need more than eight or ten tools usually wants splitting.

Step 7. Put a human in front of the email tool.

An agent that emails customers unsupervised will eventually email the wrong one. Open the Tools panel, find the Human review section, and choose where approvals go: n8n Chat, Slack, Discord, Telegram, Microsoft Teams, Gmail, Outlook, Google Chat or WhatsApp Business Cloud. Apply it to the Gmail tool only. Reading an order is harmless. Sending an email is not.

When the agent tries to send, the run pauses and the reviewer sees the tool and its parameters: address, subject, body. Approve and it runs exactly as written. Deny and it never runs. Approvals can go to a different channel from the chat, so staff talk to the agent in n8n while the owner approves from Slack.

Step 8. Test, read the log, publish.

Ask the awkward questions: an order that does not exist, two questions in one message, "email her" with no order named. After each answer, open the execution log and check what the agent did, not what it said. The most common fault in a new agent is a confident answer that never touched a tool.

If a run stops at the iteration limit, the agent went in circles. Max Iterations defaults to 10, which is plenty. Raising it hides the problem; a clearer tool description or stopping rule fixes it.

Then publish. Since n8n 2.0, Save keeps a draft and only Publish changes what runs in production, so editing never breaks the live agent. Turn on Make Chat Publicly Available, choose Hosted Chat for a ready-made page or Embedded Chat for your own front end, and set authentication to Basic Auth or n8n User Auth. A public agent with no authentication is an open tab on your model bill.

How do you connect an n8n agent to MCP?

MCP, the Model Context Protocol, is a common standard for AI apps and tools to talk to each other. n8n supports it three ways, and the names make them easy to confuse.

FeatureDirectionUse it to
MCP Client ToolYour agent uses someone else's toolsPlug an external MCP server into the agent's Tools connector
MCP Server TriggerOther AI apps use tools you builtTurn a workflow into an MCP server Claude, Cursor or another agent can call
Instance-level MCPAI apps work inside your n8nLet Claude, ChatGPT or Cursor search, run, create and edit workflows

The MCP Client Tool is the one most people want first. Give it a server URL and credentials and the agent gets that server's tools at once. Include only the ones you need.

The MCP Server Trigger works the other way. Start a workflow with it, connect tool nodes, publish, and n8n gives you a URL that clients reach over SSE or streamable HTTP, protected by bearer or header auth. Claude Desktop usually connects through the mcp-remote package. Self-hosters with several webhook replicas should note n8n's warning: route every /mcp request to one dedicated replica, or connections keep dropping.

Instance-level MCP arrived in April 2026 and sits outside any workflow. Turn it on under Settings, then Instance-level MCP, and opt in each workflow separately. Only published workflows with a webhook, form, schedule or chat trigger qualify. The docs describe this layout from n8n 2.33.0, on Cloud and self-hosted. It is a fast way to build, and connecting a client is close to handing out admin access, so treat it that way.

What does it cost to run an AI agent in n8n?

Two bills, and the forgotten one is usually bigger.

The first is n8n. Cloud charges by execution, and an execution is one run of the whole workflow, however many steps it takes. An agent making six model calls and three tool calls is still one execution. But with a Chat Trigger every message is a new run, so an eight-message conversation is eight executions.

n8n planPrice, billed annuallyExecutions a monthConcurrent executionsChecked
Community Edition, self-hostedFree, plus your serverNo capWhatever your server handles27 September 2026
Cloud Starter€20 a month2,500527 September 2026
Cloud Pro€50 a month10,0002027 September 2026
Cloud Business€667 a month40,000See the pricing page27 September 2026

A small self-hosted instance runs on a €4 to €12 VPS. Forty staff messages a working day comes to about 880 executions a month, well inside Starter. Put the same agent on a public site and Pro becomes likely.

The second bill is the model provider. Every model call carries the system message, the memory window, every tool description, the user's message and any tool results so far. A question needing two tool calls means three model calls, each carrying all of it, which is why short memory and fewer tools are cost advice too. Watch token counts in the execution log for a week before estimating a monthly figure, and set a spending cap with the provider from day one.

For the non-agent side of your automation, n8n vs Make vs Zapier compares pricing across the three.

What usually goes wrong with n8n agents?

  • It answers without using its tools. Tighten the system message and check the log, not the reply.
  • It picks the wrong tool. The descriptions overlap. Make each one say what it returns and when to use it.
  • It remembers in testing and forgets in production. Simple Memory on a queue-mode instance. Switch to Postgres or Redis.
  • Nothing happens once it is live. It was saved but not published, or something still calls the test URL.
  • Replies arrive in one lump. Streaming needs a trigger that supports it: a Chat Trigger set to stream, or a Webhook with a streaming response mode.
  • Costs creep up. Long memory, too many tools, or an expensive model on a cheap job. The log shows which.

When should you split one agent into several?

When the system message reads like three job descriptions stapled together. The AI Agent Tool node lets one agent call another as a tool, each with its own model, prompt and tools. A front-desk agent can pass order questions to an orders agent and refunds to a refunds agent, each carrying only the tools it needs. Build the single agent first, though, and split only where it actually gets confused.

And sometimes the answer is no agent at all. If the steps never change, a normal workflow does the job in milliseconds for no tokens. A strong middle ground is a plain workflow with one AI step, such as a Text Classifier that sorts incoming email before ordinary nodes act on it. The same scepticism is worth applying to AI products you buy, which telling AI wrappers from real infrastructure covers.

Frequently asked questions about building AI agents in n8n

Is n8n good for building AI agents? Yes, especially when the agent has to act on other business tools, because n8n already connects to hundreds of them and almost any connection can become a tool. A code framework gives you finer control over the reasoning loop, but for most small business agents that loop is not the hard part.

Can I build an AI agent in n8n for free? Yes. The self-hosted Community Edition is free with no execution cap, so you pay only for the server and the model. A local model through Ollama removes the model bill too, at the cost of weaker tool use.

Does an AI agent use more n8n executions than a normal workflow? No. An agent that loops five times within one run is still one execution. The looping shows up on your model provider's bill instead.

How do I give an n8n agent long-term memory? Use Postgres or Redis Chat Memory with a stable session key, such as the customer's email or a Telegram chat ID, instead of the chat session. For facts rather than conversations, store them in a table or vector store and give the agent a tool to search it.

What is the difference between the AI Agent node and the Basic LLM Chain? The Basic LLM Chain sends one prompt and returns one answer. The AI Agent calls tools, reads the results and decides what to do next, in a loop. Use the chain for summarising or classifying, and the agent when the next step depends on what it finds.

Where to go next

The n8n section of StackLedge has agent workflows worth pulling apart, including Chat with a database using AI and Angie, a Telegram assistant. If you run your own instance, read self-hosting n8n in production before this agent meets real users, and if you are still weighing n8n against hosted AI tools, Gumloop alternatives compares six on price.

Built an agent workflow or community node other people could use? Submit it to StackLedge. You do not need a website to list a workflow, and a person reads every submission.


Built something worth listing? Submit it to the directory — tools, n8n workflows and community nodes all welcome.

Keep reading