This n8n AI agent tutorial shows you how to build an agent that can call tools, remember a conversation, and ask a person for approval before it does anything risky. You do not need to write code for the main build. You only need a working n8n instance and one API key for a language model.

An agent that can only chat is easy to trust. An agent that can send emails, update records or call your APIs is not. So this guide builds the agent in the safest order: first a simple agent, then tools, then memory, then a human approval step, and last limits for loops and cost.

n8n AI agent tutorial: what you will build

By the end you will have one workflow with these parts:

  • A Chat Trigger that receives messages
  • An AI Agent node that decides what to do
  • A chat model that does the thinking
  • Two tools: one that only reads data, one that changes data
  • Memory so the agent can follow a conversation
  • A human review step that must approve the tool that changes data

You can follow the same pattern later for a WhatsApp, Slack or Telegram agent. Only the trigger and the approval channel change.

What is an n8n AI agent, and how is it different from a normal workflow?

A normal n8n workflow follows a fixed path: step one, then step two, then step three. An AI agent chooses its own path. You give it a goal, a set of tools and some rules, and the model decides which tool to use and when.

In n8n this is done by the AI Agent node (the Tools Agent). It connects a chat model to tools, and the model decides which tool to call for each request. If you want the basic idea first, read What Is an AI Agent? A Simple Guide With Real Examples. The glossary also explains AI agent and n8n in plain words.

The key point: because the model chooses the path, you must control what it is allowed to do. That is what the rest of this guide is about.

What you need before you start

  • An n8n instance (cloud or self hosted) where you can create workflows
  • An API key for one supported chat model. The n8n docs list OpenAI, Groq, Mistral Cloud, Anthropic and Microsoft Foundry for the Tools Agent
  • One safe test system for the tools, such as a Google Sheet with fake data
  • About 30 to 45 minutes

Use fake data for your first build. Never connect a new agent to real customer records on the first day.

Step 1: Add the Chat Trigger and the AI Agent node

  1. Create a new workflow.
  2. Add a Chat Trigger node. This gives you a built in chat window for testing.
  3. Add an AI Agent node and connect it after the trigger.
  4. In the AI Agent node, keep the prompt source as "Take from previous node automatically". The Chat Trigger sends the user message as chatInput, and the agent reads it from there.
  5. Click the Chat Model connector on the AI Agent node and add your chat model. Select your credentials.

Open the chat window and send "hello". If the agent answers, the base is working. Do not add anything else until this works.

Step 2: Write a clear system message

The system message is the first instruction the agent sees. Open the AI Agent node, go to Options, and add a System Message.

A good system message is short and has three parts: the role, the rules, and what to do when it is not sure. Here is a simple example you can adapt:

You are a support assistant for a small online shop.
You can look up order status with the order lookup tool.
You can issue a refund only with the refund tool.
Never guess an order number. If you are missing information, ask the user.
If a tool is denied or fails, tell the user and offer another option.

Keep it specific. A vague message like "be helpful" gives the model too much freedom.

Step 3: Add tools (start with one that only reads)

Tools are what make an agent useful. Click the Tools connector on the AI Agent node and add tools one at a time. The n8n docs list more than 100 tools for the Tools Agent, including Call n8n Workflow, Code, HTTP Request and Calculator.

Start with two:

  1. A read tool. For example, an HTTP Request tool or a Google Sheets lookup that returns order status. It cannot change anything.
  2. A write tool. For example, a tool that creates a refund request or sends an email. Add it now, but do not trust it yet. Step 5 puts a person in front of it.

Two rules for every tool:

  • Give it a clear name and description. The model reads the description to decide when to use the tool. "Get order status by order number" is better than "orders".
  • Keep each tool small. One tool should do one job. If you need a long process, put it in a separate workflow and expose it with the Call n8n Workflow tool.

Test each tool by asking the agent a question that needs it. Check the execution log to see which tool was called and with what input.

Step 4: Add memory so the agent can follow a conversation

Without memory, every message is treated as a new conversation. The agent will forget the order number you gave one message ago.

  1. Click the Memory connector on the AI Agent node.
  2. Add the Simple Memory node.
  3. Set the Session Key. This is the key used to store the conversation, so each user or chat should have its own key.
  4. Set the Context Window Length. This is the number of previous interactions the agent considers.

Three things to know, all from the n8n docs:

  • Simple Memory keeps chat history inside the workflow. The Tools Agent page says memory does not persist between sessions.
  • The docs warn against using Simple Memory in an active production workflow if your n8n runs in queue mode, because n8n cannot guarantee that every call goes to the same worker.
  • n8n also has memory nodes backed by Postgres, Redis and MongoDB. If you need history to survive restarts or to work across workers, look at those instead.

A larger window gives better context but sends more text to the model on every message, so it costs more. Start small, for example the last few interactions, and raise it only if the agent loses track.

Step 5: Add a human approval step before risky tools

This is the most important step. n8n has a feature called human in the loop for tools. It pauses the workflow and asks a person to approve a tool call before it runs.

To set it up:

  1. Click the Tools connector on the AI Agent node to open the Tools Panel.
  2. In the Human review section, choose an approval channel and set its credentials.
  3. Connect the tools that need approval to the human review step.

According to the n8n docs, you can require review for all tools on an agent or only for selected ones. Supported channels include n8n Chat, Slack, Discord, Telegram, Microsoft Teams, Gmail, WhatsApp Business Cloud, Google Chat and Microsoft Outlook. The approval channel can be different from the channel where users chat. For example, customers can chat in one place while approvals go to your team in Slack.

The reviewer sees which tool the agent wants to use and the values it chose. They can approve, and the tool runs with that input. Or they can deny, and the action is cancelled and the agent is told about the rejection. In the review message you can show the tool name with $tool.name and the chosen values with $tool.parameters.

A simple rule to follow:

Tool typeExampleApproval needed?
Read onlyLook up order statusUsually no
Changes dataUpdate a recordYes
Sends messages outsideEmail a customerYes
Money or deletionRefund, deleteAlways yes

The docs also recommend describing the approval setup in the system prompt. Tell the agent which tools need approval and how to behave when one is denied, such as telling the user and suggesting another option. Add a line like this to your system message:

The refund tool needs human approval. If approval is denied, tell the user
that the request was not approved and suggest contacting support.

The docs do not describe what happens if nobody answers a review request, so test that case yourself before you go live. For more patterns on approvals, see Human in the Loop AI: Approval Steps for Automation.

Step 6: Limit loops, handle errors and control cost

An agent can call the model several times for one question. Set limits so a mistake does not become a long loop or a big bill.

  • Max Iterations. In the AI Agent options, Max Iterations sets how many times the model runs to produce an answer. The default is 10. Lower it if your tasks are simple.
  • Retries on tool nodes. In the Settings of a node you can turn on Retry On Fail and set the number of tries, so a short network problem does not break the run.
  • An error workflow. Use an Error Trigger workflow to alert you when something fails. The guide on self-healing n8n workflows shows retry and alert patterns in detail.
  • Cost limits. Use a small model for simple steps, keep prompts short, and keep the memory window small. See How to Control AI Costs in Automation Projects.

Common mistakes with n8n AI agents

  1. Adding too many tools at once. The more tools an agent has, the more chances it picks the wrong one. Start with two or three.
  2. Vague tool descriptions. The model cannot choose well if the description does not say when to use the tool.
  3. Letting write tools run without approval. Anything that changes data, sends messages or moves money should go through human review.
  4. Not testing the denial path. Many people test only the "approve" case. Also test what the agent says when you deny.
  5. Using Simple Memory in queue mode. The docs warn about this. Use a database backed memory node instead.
  6. Expecting memory to last forever. Simple Memory does not persist between sessions. Plan for that.
  7. No limits. Leave Max Iterations and the memory window at sensible values and watch the first runs closely.

Test checklist before you go live

  • The agent answers a plain question without calling any tool
  • The read tool is called when it should be, and not when it should not
  • The write tool always triggers a human review request
  • Approve works and the action runs once
  • Deny cancels the action and the agent explains it to the user
  • The agent keeps the context across two or three messages
  • A failed tool call gives a clear message and an alert
  • You checked the execution log and the cost of a few runs

Where to go next

Once this pattern works, you can reuse it for other channels. Moving a WhatsApp AI chatbot from n8n to FastAPI shows what changes when a chatbot grows. If you want your agent to use shared tools through a standard protocol, read What Is MCP in AI?. And if your agent needs to answer from your own documents, the production RAG pipeline guide is the next step.

FAQ

What is an n8n AI agent?

An n8n AI agent is a workflow node that connects a chat model to tools and lets the model decide which tool to call for each request. You build it with the AI Agent node, a chat model, tools and optional memory.

Do I need to code to build an n8n AI agent?

No. The main build uses nodes and settings. You may write small code only if you add a Code tool or a custom API call.

How do I stop an n8n AI agent from doing something risky?

Use the human review step for tools. The workflow pauses, a person sees the tool and the values, and the action runs only if they approve. Also keep the tool list small and write clear rules in the system message.

Does n8n AI agent memory last between sessions?

Not with Simple Memory. The n8n docs say it does not persist between sessions, and they advise against it in queue mode. For longer lived memory, use a database backed memory node such as Postgres or Redis.

NEXT IN SERIES

Human-in-the-Loop AI: How to Add Approval Steps to Your Agents and Automations

Agents are moving into real work, and control is the big question. Here is when to put a human in the loop, five patterns that work, and the mistakes that make approvals useless.

Continue Reading