The n8n AI Agent node lets a language model decide which tools to call, and in what order, to answer a request. To build one you add a Chat Trigger, an AI Agent node, a chat model sub-node, an optional memory sub-node, and at least one tool sub-node, then test it in the built-in chat. This tutorial builds a small working agent that can do arithmetic and look up data through a sub-workflow, and explains each setting that matters.
Who this is for and what you will build
This is for people who already know the n8n canvas and want to move from fixed workflows to an agent that chooses its own steps. You can use n8n Cloud or a self-hosted instance (see n8n self-host with Docker if you need one). You also need an API key for a chat model provider.
By the end you will have:
- A chat-triggered workflow with an AI Agent node.
- A chat model and Simple Memory attached.
- Two tools: a Calculator and a Call n8n Workflow Tool that fetches records for the agent.
- A system message that sets the agent's rules, and a checklist for debugging it.
If you are still deciding between automation platforms, n8n vs Make vs Zapier compares them.
How the AI Agent node works
The AI Agent node is a root node in n8n's cluster-node model. It takes a prompt, sends it to a chat model with a description of the tools available, and lets the model request tool calls until it has an answer. The documentation puts it as an agent that uses a chat model and one or more tools and decides which tools to call to complete a task.
Three types of sub-node attach to it:
| Sub-node | Required | Purpose |
|---|---|---|
| Chat model | Yes | The LLM that reasons. The documentation lists OpenAI, Groq, Mistral Cloud, Anthropic and Microsoft Foundry chat models for this node. |
| Tools | At least one | Capabilities the model can call, such as Call n8n Workflow, Code, HTTP Request, Calculator, Vector Store, or app nodes. |
| Memory | No | Keeps earlier messages for multi-turn chats. |
When Require Specific Output Format is on, you also connect an output parser: Auto-fixing, Item List or Structured.
Agent types are gone
Older tutorials show an Agent Type dropdown with options such as Conversational or ReAct. The documentation says the agent type setting is deprecated as of n8n 1.82.0, that all AI Agent nodes now operate as a Tools Agent, and that version 1 of the node (the one with that setting) will be removed in n8n 3.0. If you import an old template, update the node to the latest version.
Prerequisites
- An n8n instance you can sign in to.
- An API key for a supported chat model provider. This tutorial uses the Anthropic Chat Model; the OpenAI Chat Model works the same way.
- A second, simple workflow to act as the tool. It can return sample data for now.
Keep the Chat Trigger's Make Chat Publicly Available option off while you build; the documentation says to turn it on only to publish the chat.
Step 1: Add the Chat Trigger and AI Agent
- Create a new workflow and add the Chat Trigger node.
- Add the AI Agent node and connect the trigger to it.
- In the AI Agent node, leave Prompt on its automatic option (Take from previous node automatically, shown as Connected Chat Trigger Node in some versions), which takes the
chatInputfield from the previous node. The Chat Trigger provides that field.
If you later feed the agent from a different trigger, such as a webhook, change Prompt to Define below and put an expression in the Prompt (User Message) field.
Step 2: Attach a chat model
Select the Chat Model connector on the AI Agent node and choose your provider's chat model node. Create the credential with your API key and pick a model from the list. Use a model that supports tool calling; if your chosen model can't call tools, the agent can't act on its tool list. Check the provider's model documentation for tool support.
Step 3: Add a system message
Open the AI Agent node, add the System Message option and write rules. The documentation describes it as a message sent to the agent before the conversation starts to guide its decisions. A useful pattern is to state the role, the tools, and the limits:
You are an assistant for the contoso.com operations team.
Use the Calculator tool for any arithmetic; never calculate in your head.
Use the Order Lookup tool to answer questions about orders. If the order
number is missing, ask the user for it before calling the tool.
If a tool returns no data, say so. Do not guess order details.Keep the instructions short and specific. A system message that names the tools and says when to use each one is more reliable than a general description.
Step 4: Add memory
Select the Memory connector and add Simple Memory (its URL still says Window Buffer Memory). It has two settings:
- Session Key: the key under which the conversation is stored in workflow data.
- Context Window Length: how many previous interactions are sent as context.
Two cautions from the documentation. First, memory attached to the agent doesn't persist between sessions. Second, don't use Simple Memory in an active production workflow on an instance running queue mode, because n8n can't guarantee that each call reaches the same worker. For production chat history, look at the other memory sub-nodes n8n offers that store history in an external system, and test them with your own volume.
If you want the chat window to reload earlier messages, the Chat Trigger has a Load Previous Session option under Options. Any value other than Off requires a memory sub-node connected to both the Chat Trigger and the agent, and n8n recommends using the same memory node for both.
Step 5: Add tools
Calculator
Add the Calculator tool from the Tools connector. It needs no configuration. It exists because models are unreliable at arithmetic, and the system message above tells the agent to use it.
Call n8n Workflow Tool
Add the Call n8n Workflow Tool. This is the most flexible tool, because any workflow becomes a capability. Configure:
- Description: custom text that tells the agent when to use the tool. The agent relies on it to decide whether to call the tool, so state the purpose and the input it expects, for example: "Call this tool to look up an order by order number. Input: orderNumber."
- Source: choose Database to select a workflow from a list or enter its ID, or Define Below to paste workflow JSON.
- Workflow Inputs: if the sub-workflow defines a Workflow Input Schema, select Refresh to load its fields. Each input can be a fixed value, an expression, a value the model fills in, or a
$fromAI()expression.
The sub-workflow must be published for production runs. Otherwise the tool returns the error "Workflow is not active and cannot be executed" to the agent, which can be easy to miss inside a long reply. If the agent says it couldn't get data, check that the sub-workflow is published and that its execution list shows runs.
Letting the model fill parameters with $fromAI
For parameters you want the model to choose, use $fromAI() inside the tool's field:
{{ $fromAI('orderNumber', 'The order number the user asked about', 'string') }}The documented signature is a required key plus optional description, type and defaultValue. Supported types are string, number, boolean and json, and the type defaults to string. The key must be 1 to 64 characters of letters, numbers, underscores or hyphens. The arguments are hints for the model rather than references to existing values.
Two limits to remember: $fromAI() works only with tools connected to the Tools Agent, and it doesn't work with the Code tool or other non-tool sub-nodes. You can mix fixed text with a model-generated value in one field, such as Generated by AI: {{ $fromAI("subject") }}.
HTTP Request Tool
To let the agent call an API, add the HTTP Request Tool. When attached to an agent it offers Optimize Response, which reduces what is passed to the model. For JSON you can select or exclude fields, for HTML you can use a CSS selector, and for text you can truncate, with a default limit of 1000 characters. Trimming responses keeps token use down and reduces the chance of the model being confused by large payloads.
Agent options worth knowing
| Option | What it does |
|---|---|
| Max Iterations | Number of times the model runs to generate an answer. Default 10. |
| Return Intermediate Steps | Includes the agent's tool calls and results in the output, useful for debugging. |
| Automatically Passthrough Binary Images | Passes binary images to the agent as image messages. |
| Enable Streaming | Sends output in real time. On by default, and needs a trigger that supports it, such as Chat Trigger or a Webhook set to Streaming response mode. |
| Require Specific Output Format | Lets you connect an output parser for structured output. |
Turn on Return Intermediate Steps while you develop so you can see which tool was called with which arguments.
Step 6: Test the agent
Open the workflow's chat panel, send a message and watch the execution. Try three prompts:
- "What is 18% of 2,450?" The agent should call Calculator rather than answer directly.
- "What is the status of order 1042?" It should call the lookup tool with
1042. - "What about the one before it?" This checks memory; with Simple Memory attached, the agent can use the earlier turn, though it may ask for clarification if the reference is ambiguous.
If a tool wasn't called when it should have been, the cause is almost always the tool description or the system message, not the node settings. Reword them and retest.
Every chat message runs your workflow, so each test counts toward your execution allowance on n8n Cloud.
Troubleshooting
| Error or symptom | Cause and fix |
|---|---|
| "A Chat Model sub-node must be connected" | The agent ran without a model. Click the Chat Model connector, pick a model and credential. |
| "No prompt specified" | The agent expects the prompt from the previous node, often a Chat Trigger. Change Prompt from the automatic option to Define below and build the prompt from your own data. |
| "Internal error: 400 Invalid value for 'content': expected a string, got null." | The prompt contains null. Check that your expressions resolve to real values, or remove nulls from chatInput. |
| "Error in sub-node Simple Memory" | Usually an old version of the node (formerly Window Buffer Memory) from a template. Delete it and add it again. |
| "Workflow is not active and cannot be executed" | The Call n8n Workflow Tool points to an unpublished workflow. Publish it. |
| Agent loops and stops without a good answer | Check Max Iterations (default 10), tighten the tool descriptions, and use Return Intermediate Steps to see what it tried. |
Production checklist
- Write each tool description as an instruction that states purpose and input.
- Give the agent the narrowest set of tools it needs; each tool is something it can misuse.
- Put rules about what the agent must never do in the system message, and enforce hard limits inside the tool workflows, not only in the prompt.
- Treat tool inputs from the model as untrusted: validate them in the sub-workflow before querying or writing.
- Do not rely on Simple Memory for production history on queue mode.
- Add authentication to the Chat Trigger before publishing it; the options are None, Basic Auth and n8n User Auth.
- Trim API responses with Optimize Response to control token cost.
For a code-first view of the same loop, Claude tool use with a Python agent loop shows what the node does behind the scenes.
Comments
Questions and tips are welcome. Comments are checked by the EpiFive team before they appear; please do not share passwords, phone numbers or other private details.