An AI agent in n8n is four nodes on a canvas: a trigger, the AI Agent node, a chat model and at least one tool. That's the whole skeleton. The model decides which tool to call, n8n runs it, and a setting called Max Iterations caps that loop at 10 runs by default.
Building that skeleton takes minutes. Making it answer real users from your own app takes a few settings most tutorials skip: a session ID for memory, a webhook that waits for the answer, and a limit on what the agent can touch.
This guide builds a small order-status assistant from scratch, first in n8n's chat panel and then behind a webhook any website can call. If you want ideas before you build, my list of n8n workflow examples that actually ship is a good warm-up.
Every node name and setting below comes from n8n's official docs. Some links here are affiliate links. They don't change your price.

What is an AI agent in n8n made of?
The AI Agent node is a root node. It does nothing on its own. You plug sub-nodes into the connectors along its bottom edge, and each one gives it a different ability.
n8n's docs put it plainly: you connect a chat model and one or more tools, and the agent decides which tools to call to complete a task. They also say you must connect at least one tool sub-node.
| Part | Node to use | Required? | What it does |
|---|---|---|---|
| Trigger | Chat Trigger or Webhook | Yes | Starts a run with the user's message |
| Brain | AI Agent | Yes | Plans, calls tools, writes the reply |
| Model | OpenAI Chat Model, Anthropic Chat Model and others | Yes | The LLM that does the reasoning |
| Memory | Simple Memory, Postgres Chat Memory, Redis Chat Memory | No, but needed for chat | Keeps earlier messages in context |
| Tools | HTTP Request Tool, Call n8n Workflow Tool, MCP Client Tool, app nodes | At least one | Lets the agent read data or take actions |
| Output parser | Structured Output Parser | No | Forces a fixed JSON shape |
One thing confuses people reading older tutorials: the agent type dropdown is gone. n8n deprecated it in version 1.82.0, and every AI Agent node now works as a Tools Agent.
If a template shows a Conversational Agent or ReAct Agent setting, it's from an older version of the node, and the docs say that version will be removed in n8n 3.0.

What do you need before you start?
You need three things, and one decision.
- An n8n instance. n8n Cloud or a self-hosted Community Edition both have the AI Agent node.
- Access to a chat model. That's usually an API key from a provider such as OpenAI or Anthropic. On n8n Cloud, the OpenAI Chat Model node can also run on Gateway credits, with no OpenAI account.
- One clear job for the agent. "Answer questions about order status" is a job. "Be our AI" is not.
The decision is where n8n runs. As of 20 October 2026, n8n's pricing page lists Starter at €20 a month and Pro at €50 a month, both billed annually, with 2,500 and 10,000 workflow executions. The Community Edition is free to self-host, and I walk through that setup in my guide to self-hosting n8n on a VPS with Docker.
Here's the catch for chat agents. n8n's docs say every message to the Chat Trigger executes the workflow, so a conversation with 10 messages uses 10 executions. A busy chatbot burns through an execution allowance much faster than a nightly sync.
How to build an AI agent in n8n, step by step
The example is an order-status assistant. A customer asks "Where is order 4512?", the agent looks the order up through your API, answers in plain language, and opens a support ticket if something looks wrong.
Swap in your own API and actions. The wiring stays the same.
Step 1: Add a Chat Trigger to test the conversation
Create a new workflow and add the Chat Trigger node. It gives you a chat panel inside the editor, which is the fastest way to test an agent while you build it.
Leave Make Chat Publicly Available turned off for now. n8n recommends keeping it off while you build and turning it on only when you're ready to publish.
The Chat Trigger needs an agent or chain connected after it. That's the next step.
Step 2: Add the AI Agent node and write the system message
Add the AI Agent node after the trigger. With a Chat Trigger in front, leave the Prompt setting on its default. It reads the user's text from a field called chatInput.
Then open Options and add a System Message. n8n describes it as the place to guide the agent's decision-making. In practice, this is where most of your agent's quality comes from.
Here's a system message you can copy and adapt:
Notice what it does. It names the tool, bans guessing and sets a length limit. A vague system message gives you a vague agent.
Step 3: Connect a chat model and add credentials
Click the Chat Model connector under the AI Agent node and pick a model node. n8n's Tools Agent docs list the OpenAI, Anthropic, Groq, Mistral Cloud and Microsoft Foundry chat models among the supported options. Not sure which one? See how to choose an LLM for an AI agent.
Create a credential with your provider's API key. The OpenAI Chat Model node loads the models available to your account, so you pick from a real list, not a guess.
Two options are worth a look:
- Sampling Temperature. n8n's docs warn that a higher temperature increases the risk of hallucinations. For an assistant that reads facts from a tool, keep it low.
- Max Retries and Timeout. They decide what happens when the provider is slow.
Skip the model and the run fails with "A Chat Model sub-node must be connected".
Step 4: Give the agent memory with Simple Memory
Without memory, every message starts fresh. The customer says "And what about my other order?" and the agent has no idea what "other" means.
Click the Memory connector and add Simple Memory. It has two settings: Session Key, which decides whose history to load, and Context Window Length, the number of earlier interactions to keep in context.
With a Chat Trigger, the session ID comes from the trigger automatically. That changes in Step 7, and it's the bug that catches most people.
One more warning from the docs: Simple Memory doesn't work in an active production workflow if n8n runs in queue mode, because n8n can't promise every call reaches the same worker. If you scale out with queue mode, switch to Postgres Chat Memory or Redis Chat Memory.
Step 5: Add tools: HTTP Request, Call n8n Workflow and MCP Client
Tools are where the agent stops talking and starts doing. n8n's docs single out three as especially powerful: the HTTP Request Tool, the Call n8n Workflow Tool and the Custom Code Tool. You can also attach regular app nodes, like Google Sheets, Gmail or Slack, as tools.
For the order assistant, add an HTTP Request Tool and name it get_order. Point it at your order API (a GET request to your own endpoint) and give it a description such as "Look up one order by its order number."
That description matters more than it looks. The model reads it to decide when to call the tool.
To let the model fill in the order number, click the star button next to the field, or write the expression yourself with n8n's $fromAI() function:
The HTTP Request Tool also has an Optimize Response option that only appears when it's attached to an agent. It trims a JSON or HTML response down to the fields you choose, which saves tokens and stops the model getting lost in a huge payload.
For the "open a ticket" action, add a Call n8n Workflow Tool and point it at a separate workflow that creates the ticket. This keeps the risky action in its own small, testable workflow.
One trap: in production, the sub-workflow must be published, or the agent gets the error "Workflow is not active and cannot be executed" as its tool result and may quietly apologise instead of failing loudly.
If a service already runs an MCP server, the MCP Client Tool connects it in one node, and you can expose all its tools, only selected ones, or all except a few. New to the protocol? My plain-English guide to MCP explains what that server is doing.

Step 6: Test in the chat panel and read the intermediate steps
Open the chat panel and ask a real question: "Where is order 4512?" Then ask a follow-up that only makes sense with memory.
Watch the logs as well as the reply. Turn on Return Intermediate Steps in the agent's options to see which tools it called and with what input. If the agent answers without calling get_order, your system message or tool description isn't doing its job.
Two settings help here:
- Max Iterations, 10 by default, caps how many times the model can run while trying to answer. If a loop keeps calling the same tool, lower it and fix the description.
- Force Tool Call on First Iteration, added to the AI Agent node (v3) in n8n 2.40, makes the model call a tool on its first response. n8n says it helps smaller models that tend to answer from thin air.
Step 7: Swap in a Webhook trigger and Respond to Webhook
The chat panel is for testing. Your website or app will call the agent over HTTP, which means a Webhook trigger. If webhooks are new to you, here's how a webhook works under the hood.
Add a Webhook node, set the HTTP Method to POST and give it a readable Path such as order-agent. Under Authentication, pick Header auth so random visitors can't run up your model bill. Set Respond to "Using 'Respond to Webhook' Node".
Now three settings change, because there's no Chat Trigger feeding the agent:
- In the AI Agent node, set Prompt to Define below and point it at the message in the request body.
- In Simple Memory, set Session ID to Define below and build the Session Key from the request. Without it you'll hit the "No sessionId" error the docs describe.
- Add a Respond to Webhook node after the agent and set Respond With to First Incoming Item. The agent's reply sits in a field called output, so your app gets it back as JSON.
The expressions look like this:
And a test call from a terminal:
Click Listen for test event first, and use whatever header name and value you set in the Header auth credential. Send the same sessionId on every message from one customer, and a different one for each customer, or their conversations will bleed into each other.

Step 8: Publish and switch to the production URL
The Webhook node has two URLs. The test URL works after you click Listen for test event, shows the data in the editor, and stays active for 120 seconds. The production URL registers when you publish the workflow, and its runs show up in the Executions tab instead of the editor.
Publish the main workflow and the ticket sub-workflow, then point your app at the production URL. Send one real request and open the execution to confirm every tool call looks right.
Should your agent use the Chat Trigger or a Webhook?
Both start the same agent. The difference is who's on the other end and how much you have to wire yourself.
| Chat Trigger | Webhook + Respond to Webhook | |
|---|---|---|
| Who calls it | n8n's hosted chat, its chat widget, or the editor's chat panel | Any app, site or script that can send HTTP |
| Session ID for memory | Sent automatically | You send it and map it yourself |
| Prompt setting | Default (reads chatInput) | Define below, mapped from the body |
| Access control | None, Basic Auth or n8n User Auth | Basic, Header or JWT auth, plus IP allowlist |
| Reply format | Chat message | Whatever you return: JSON, text, a redirect |
| Best for | Internal assistants, quick demos, a hosted chat page | Your own front end, mobile apps, other systems |
My rule: build with the Chat Trigger, ship with whichever one matches the caller. If a human types into n8n's chat window, keep the Chat Trigger and turn on Make Chat Publicly Available. If your own code calls the agent, use the Webhook.
Both support streaming. The AI Agent's Enable Streaming option is on by default, and it needs a Chat Trigger or a Webhook with its response mode set to streaming.
Which memory node should you use?
Start with Simple Memory. Move to a database-backed memory when you need history to survive restarts or you run more than one worker.
| Memory node | Where history lives | Good for | Watch out for |
|---|---|---|---|
| Simple Memory | Inside n8n | Prototypes, single-instance setups | Not for production in queue mode |
| Postgres Chat Memory | A table in your Postgres database | Production, auditing past chats | Needs Postgres credentials; creates the table if missing |
| Redis Chat Memory | Redis | Fast, multi-worker setups | One more service to run |
Whichever you pick, keep Context Window Length modest. Every earlier message you keep goes back to the model on each turn, and you pay for those tokens again.
How do you get structured JSON out of the agent?
Sometimes the reply isn't for a human. It feeds a CRM, a sheet or another workflow, and free text breaks things.
Turn on Require Specific Output Format in the AI Agent node and connect a Structured Output Parser. You can paste an example and let n8n build the schema, or write a JSON Schema yourself:
When you generate the schema from an example, n8n treats every field as mandatory and ignores the sample values. It doesn't support $ref references in hand-written schemas.
What usually goes wrong, and how do you fix it?
Most agent failures are wiring problems, not AI problems. These come straight from n8n's common-issues pages.
| Error or symptom | What it means | Fix |
|---|---|---|
| No prompt specified | Agent expects chatInput, but no Chat Trigger sent it | Set Prompt to Define below and map your field |
| 400 Invalid value for 'content' | Your prompt expression resolved to null | Check the field path in the expression |
| A Chat Model sub-node must be connected | No model attached | Add a chat model to the Chat Model connector |
| No sessionId | Memory can't tell whose chat this is | Set the Session Key from your request |
| Error in sub-node Simple Memory | Old Window Buffer Memory version from a template | Delete the memory node and add it again |
| Workflow is not active and cannot be executed | Sub-workflow tool isn't published | Publish the sub-workflow |
| Webhook stops responding while testing | Test URL expired after 120 seconds | Click Listen for test event again |
Sub-nodes have one more quirk. An expression inside a sub-node always resolves to the first item, even when five items come in. If you feed the agent a batch, loop over the items or the tools will only ever see the first one.
Those are build-time errors. For failures in production, when nobody is watching the canvas, add an error workflow. My guide to n8n error handling covers retries, error outputs and Slack or email alerts you can put around an agent.
When is an AI agent the wrong tool?
This sounds good on paper, but an agent is the least predictable node you can add to a workflow. The model picks the tools, the order and the wording, and it can pick differently on the next run.
n8n's docs describe the difference well. A chain follows a predetermined sequence, while an agent uses a language model to decide which actions to take, and it runs several times per request: once to plan, once per tool call, once to answer.
So use this rule:
- If the steps are always the same (new form entry, add a row, send an email), build a normal workflow. No model needed.
- If you only need text transformed (summarise, classify, translate), use a Basic LLM Chain or a single model call.
- If the next step depends on what the user asked or what a tool returned, that's when an agent earns its place.
A good "AI workflow" is often mostly regular nodes with one agent in the middle, handling only the part that needs judgement.
How do you keep an n8n agent safe?
An agent with tools can do real things with your accounts. Treat every tool as a permission you're handing to a model.
That risk has a name, and I cover how it works in my guide to prompt injection risks for AI agents. In n8n, four settings do most of the protecting:
- Human review for tool calls. In the AI Agent node's Tools Panel, add a Human review step and connect the risky tools to it. The workflow pauses until someone approves or denies the call in Chat, Slack, Telegram or another channel.
- Webhook authentication. Basic auth, Header auth or JWT auth, plus an optional IP allowlist.
- Narrow tools. With the MCP Client Tool, expose selected tools instead of all of them.
- Short limits. A sensible Max Iterations and a system message that says what the agent must never do.
My take: put human review on anything that sends, deletes or spends. You can remove it later once the logs show the agent behaves.
How much does an n8n AI agent cost to run?
There are two bills. n8n charges per workflow execution with unlimited steps, and its pricing page puts it as paying for full executions, not for each step. Your model provider charges for tokens, unless you use n8n Cloud's Gateway credits.
For a chat agent, the n8n side is simple maths. n8n's own pricing FAQ says to multiply conversations by messages per conversation. 200 conversations a month at 5 messages each is 1,000 executions, inside Starter's 2,500. At 10 messages each, 250 conversations use up the whole Starter allowance.
The model side depends on your provider and on how much you send per turn: the system message, the remembered history and every tool result all count. That's why Optimize Response and a modest memory window are cost settings as much as quality settings.
Self-hosting removes the execution cap but adds a server to look after. If you're weighing it, the self-hosting guide linked earlier shows what that involves.
Frequently asked questions
Start with one job, one tool and the chat panel. Once the agent calls its tool every time, move it behind a webhook, add a session ID and gate the risky actions. That order saves you from debugging five things at once.
Looking for the next job to hand an agent? These n8n use cases for small businesses are good candidates.


