# n8n AI agent: build one with the AI Agent node, memory and tools

> An n8n AI agent is the AI Agent node with a chat model plugged in and at least one tool. It reads a message, decides which tool to call, and answers. Add a Simple Memory sub-node and it keeps the conversation going. This lesson builds one from a Chat Trigger, an OpenAI chat model, memory, a Calculator and Wikipedia.

Mindket editors · Published 2026-11-04 · Updated 2026-11-05 · https://mindket.com/learn/n8n/n8n-ai-agent

## In short

- Wire a chat model, memory and tools into one AI Agent node.
- Chat with the agent and watch it pick a tool.
- Read why the agent node can run several times in one execution.
- Tell the AI Agent node apart from a Basic LLM Chain and from n8n's separate Agents feature.

## Before you start

You need an n8n instance and an API key for one chat model provider. This lesson uses OpenAI. The [Tools Agent page](https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.agent/tools-agent) lists OpenAI, Groq, Mistral Cloud, Anthropic and Microsoft Foundry as supported chat models, so you can swap in another. On n8n Cloud, the OpenAI credential field also offers **Use Gateway credits**, which runs the node without your own OpenAI account.

Every message you send is a model call, and models count their work in tokens, as [what are tokens in AI](https://mindket.com/blog/what-are-tokens-in-ai) explains.

## Build an agent that can look things up and do sums

The agent below has a Wikipedia tool for facts, a Calculator for arithmetic and a memory for the conversation. Step 6 asks you to paste this into its **System Message** option. The text is our own sample, so change it freely:

````text
You are a helpful assistant. Use the Wikipedia tool for facts about people, places and topics, and the Calculator tool for arithmetic. If a tool returns nothing useful, say so.
````

1. Create a workflow and add a **Chat Trigger** node. Leave **Make Chat Publicly Available** off while you build, as n8n advises. The chat then works only through the manual chat interface.
2. Add an **AI Agent** node after it. By default the agent reads the user's message from the previous node, which is what the Chat Trigger gives it. The [Tools Agent page](https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.agent/tools-agent) calls the expected field `chatInput`.
3. Click **+ Chat Model** under the agent and pick **OpenAI Chat Model**. Create a credential with your API key, then choose a **Model**. n8n [loads the models](https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.lmchatopenai) your OpenAI account can use.
4. Connect a memory sub-node and pick **Simple Memory**. Its **Context Window Length** sets how many previous interactions the agent considers, as the [Simple Memory page](https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.memorybufferwindow) describes.
5. Connect two tool sub-nodes, **Calculator** and **Wikipedia**. n8n requires at least one tool on the agent, and the docs list no parameters for either of these two.
6. Open the agent's options, add **System Message** and paste the text from the code above.
7. Open the manual chat interface and send "Please show me a Wikipedia article about cats". Then send "What was my last question?". These are the two test queries in n8n's own agents and chains example. The first needs the Wikipedia tool and the second needs the memory.
8. Open the execution and look at the agent node. One message can run it more than once, as the next section explains.

## What each part of the agent does

The AI Agent node is the root, and everything else hangs under it as a sub-node. That is why the canvas draws the chat model, memory and tools below the agent and not in the main line. [What is n8n](https://mindket.com/blog/what-is-n8n) shows the same shape inside a finished workflow.

There is one Agent node. Since n8n 1.82.0 every one works as a Tools Agent, and the agent type setting is [deprecated](https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.agent). A tutorial that asks you to pick an agent type predates that change.

| Sub-node | What it gives the agent | Required? |
| --- | --- | --- |
| Chat model, such as OpenAI Chat Model | The language model that reads the message and decides what to do | Yes |
| Tool, such as Calculator or Wikipedia | An add-on the agent can call for information or an action | At least one |
| Memory, such as Simple Memory | The chat history, so a follow-up question has context | No |
| Output parser | A fixed output format, when Require Specific Output Format is on | No |

## Why one message can run the agent three times

n8n's page on [what agents do](https://docs.n8n.io/build/integrate-ai/understand-ai-components/what-agents-do) says that when you run a workflow with an agent, the agent runs multiple times. Its example has three passes, shown below. In the executions list, expect several runs of the agent node for a single message.

The **Max Iterations** option caps how many times the model runs to generate an answer, and it defaults to 10. Memory has limits of its own. The Tools Agent page says memory doesn't persist between sessions. The [Simple Memory page](https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.memorybufferwindow) adds that it doesn't work in an active production workflow on a queue-mode instance, since n8n can't guarantee that every call lands on the same worker.

**The three passes in n8n's example**

1. First pass. The agent does its initial setup.
2. Second pass. The agent runs again to call a tool.
3. Third pass. The agent evaluates the tool's response and replies to the user.

## Agent, chain or something else

A chain follows a predetermined sequence of calls. An agent uses the language model to choose what to do next. n8n's [agents versus chains page](https://docs.n8n.io/build/integrate-ai/understand-ai-components/agents-vs-chains) says chains have no persistent memory, so they can't refer to earlier context.

> **Two things n8n calls agents**
>
> n8n also has a separate Agents feature, still labeled Preview in its docs. It has its own builder, and an instance owner or admin can turn it off under Settings, Agents. That setting doesn't affect the AI Agent node in this lesson. A workflow can call one of those agents with the Message an Agent node.

**AI Agent node or Basic LLM Chain**

| | AI Agent node | Basic LLM Chain |
| --- | --- | --- |
| Uses memory | ✓ Yes | ✗ No |
| Uses tools | ✓ Yes | ✗ No |
| Chooses which tool to call | ✓ Yes | ✗ No |
| Follows a fixed sequence of calls | ✗ No | ✓ Yes |

Sources: [n8n Docs: Agents vs chains](https://docs.n8n.io/build/integrate-ai/understand-ai-components/agents-vs-chains) (read 2026-11-04), [n8n Docs: What agents do](https://docs.n8n.io/build/integrate-ai/understand-ai-components/what-agents-do) (read 2026-11-04)

## What n8n's team says about agent memory and its new agents

On 1 September 2026 the n8n team [posted on X](https://x.com/n8n_io/status/2094757236811636762) that LLMs are stateless by default, so every call starts cold. Step 4's Simple Memory node exists for exactly this. Without it, the agent has no answer to "What was my last question?"

n8n's [guide to agent memory](https://blog.n8n.io/ai-agent-memory/), by Yulia Dmitrievna and the n8n team, says Simple Memory with a session ID works out of the box on a single instance. In queue mode it sends you to Postgres or Redis Chat Memory, which keep each session apart across workers. Swap the memory sub-node before you move this agent to a queue-mode instance.

Before that, on 24 August 2026, the team [said on X](https://x.com/n8n_io/status/2091838324163940766) that agents no longer have to live inside workflows. Each one is now an object of its own, the post says, used across an instance or an organization through native chat. That is the separate Agents feature from the callout above, not the AI Agent node you built. n8n's docs suggest it for work too open-ended for a fixed workflow.

> LLMs are stateless by default. Every call starts cold, a real problem for agents running multi-step workflows.
>
> n8n.io, n8n's official account, [X](https://x.com/n8n_io/status/2094757236811636762) (read 2026-11-05)

[![n8n.io (@n8n_io) on X, 1 September 2026. LLMs are stateless by default. Every call starts cold, a real problem for agents running multi-step workflows. New guide: agent memory types, storage, retrieval, and how to build it in n8n.](https://mindket.com/blog/shots/x-n8n-io-llms-stateless.webp?v=6a80fb1ffe4e)](https://x.com/n8n_io/status/2094757236811636762)

n8n.io on X, 1 September 2026

[![n8n.io (@n8n_io) on X, 24 August 2026, on n8n's new agents. This is not for building workflows, this is to BE your agent. Agents used to live inside workflows. Now they're their own object: one agent, one set of capabilities, usable across your instance or org through native chat.](https://mindket.com/blog/shots/x-n8n-io-agent-harness.webp?v=124784c38ad1)](https://x.com/n8n_io/status/2091838324163940766)

n8n.io on X, 24 August 2026

> Screenshots of X's own embeds of the posts, taken on 5 November 2026, with the time in UTC. Select a screenshot to open the post on X.

## Common mistakes

- Leaving the agent without a model or a tool. With no model, the node errors with "A Chat Model sub-node must be connected", so click **+ Chat Model** and pick one, as the [common issues page](https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.agent/common-issues) says. A tool sub-node is needed too.
- Starting from a trigger that does not give the agent a prompt. The error "No prompt specified" means the agent expects one from the previous node. Set **Prompt** to **Define below** and build it from static text or expressions.
- Passing a null prompt. The error "400 Invalid value for 'content': expected a string, got null" means an expression in the prompt resolved to nothing, so check each field it reads.
- Copying an old template with a Simple Memory node that errors. Remove it and add it again. Templates can hold the older version, once called Window Buffer Memory.
- Relying on Simple Memory in production on a queue-mode instance. n8n lists Redis Chat Memory and Postgres Chat Memory among its other memory options.
- Making a chat public with no authentication. With **Make Chat Publicly Available** on and authentication set to None, anyone can use the chat.

## Try it yourself

- Turn on **Return Intermediate Steps** in the agent's options and read the extra output.
- Set **Context Window Length** to a small number, chat past it, then ask about your first question.
- Swap the OpenAI Chat Model for another model the Tools Agent supports and keep everything else.
- Add an **HTTP Request Tool** so the agent can call an API, or a **Call n8n Workflow Tool** so it can run another workflow of yours.

## What to learn next

The agent runs wherever n8n runs, and [lesson 4](https://mindket.com/learn/n8n/self-host-n8n-docker) puts n8n on your own machine with Docker. For agents that talk to outside tools, the MCP Client Tool node connects one to an MCP server, and [what is MCP](https://mindket.com/blog/what-is-mcp) explains the protocol. To see an agent inside a complete workflow before you build your own, [Mindket's n8n workflows](https://mindket.com/automations/n8n) draw every node, including the sub-nodes, on the page.

## Check yourself

1. Which sub-node gives the agent the chat history, so a follow-up question has context?

   A. Calculator
   B. OpenAI Chat Model
   C. Simple Memory
   D. Output parser

   Answer: C. Memory is the sub-node that keeps the chat history, and without it the agent cannot answer "What was my last question?".

2. One chat message makes the agent node run three times in the execution. Why?

   A. The workflow is broken and needs a fix
   B. The agent runs more than once per message, for setup, a tool call and the reply
   C. Every word in the message starts a run
   D. Memory copies the message twice

   Answer: B. n8n says an agent runs multiple times, and its example has three passes: initial setup, a tool call, then evaluating the result and replying.

3. The agent node errors with "A Chat Model sub-node must be connected". What do you do?

   A. Click + Chat Model under the agent and pick one
   B. Turn on Return Intermediate Steps
   C. Set Max Iterations to 10
   D. Add a Wikipedia tool

   Answer: A. The error means the agent has no chat model, and the common issues page says to click + Chat Model and pick one.

4. When is the AI Agent node a better fit than a Basic LLM Chain?

   A. When the job is a single fixed step
   B. When you want a chain with no chat model
   C. When the sequence of calls must never change
   D. When the job needs tools or a conversation history

   Answer: D. A chain follows a predetermined sequence and supports neither memory nor tools, while an agent lets the model choose what to do next.

## Frequently asked questions

### Can I use Anthropic's Claude instead of OpenAI?

Yes, Anthropic's models work through a node of their own. Remove the OpenAI one, click **+ Chat Model** on the agent and pick the Anthropic node instead. The memory and tools stay connected. n8n's [AI overview](https://docs.n8n.io/build/integrate-ai) names Google among the providers too.

### Does an n8n AI agent remember earlier messages?

Only with a memory sub-node. Simple Memory keeps a chosen number of previous interactions for the current session, and the [memory page](https://docs.n8n.io/build/integrate-ai/understand-ai-components/how-memory-works) says an AI chain can't use memory at all.

### Should I use the AI Agent node or a Basic LLM Chain?

Use the agent when the job needs tools or a conversation history. A chain supports chatting with a connected model, but not memory or tools, so it fits a single fixed step.

### Can the agent return structured data instead of text?

Yes. Turn on **Require Specific Output Format** and connect an Auto-fixing Output Parser, an Item List Output Parser or a Structured Output Parser. The Tools Agent passes the parser to the model as a formatting tool.

### Can an n8n agent use MCP servers?

Yes. The AI Agent page lists MCP servers as a way to give an agent tools, and a registry server connects in one click. The guide on what n8n is covers the MCP Client Tool and the MCP Server Trigger in more detail.

### Can I make the agent ask a person before it runs a tool?

Yes. n8n lets you require approval before specific tools run, and the request goes through a channel such as Chat, Slack or Telegram. Its docs have a human-in-the-loop example for tools.

### Is every chat message one execution?

Yes. The [Chat Trigger page](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-langchain.chattrigger) says every message runs your workflow, so a ten-message conversation uses ten executions.

## Sources

- [n8n Docs: AI Agent node](https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.agent) (read 2026-11-04)
- [n8n Docs: Tools Agent](https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.agent/tools-agent) (read 2026-11-04)
- [n8n Docs: AI Agent common issues](https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.agent/common-issues) (read 2026-11-04)
- [n8n Docs: What agents do](https://docs.n8n.io/build/integrate-ai/understand-ai-components/what-agents-do) (read 2026-11-04)
- [n8n Docs: Agents vs chains](https://docs.n8n.io/build/integrate-ai/understand-ai-components/agents-vs-chains) (read 2026-11-04)
- [n8n Docs: How memory works](https://docs.n8n.io/build/integrate-ai/understand-ai-components/how-memory-works) (read 2026-11-04)
- [n8n Docs: How tools work](https://docs.n8n.io/build/integrate-ai/understand-ai-components/how-tools-work) (read 2026-11-04)
- [n8n Docs: Chat Trigger node](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-langchain.chattrigger) (read 2026-11-04)
- [n8n Docs: Simple Memory node](https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.memorybufferwindow) (read 2026-11-04)
- [n8n Docs: OpenAI Chat Model node](https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.lmchatopenai) (read 2026-11-04)
- [n8n Docs: Calculator node](https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.toolcalculator) (read 2026-11-04)
- [n8n Docs: Wikipedia node](https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.toolwikipedia) (read 2026-11-04)
- [n8n Docs: Build and manage agents](https://docs.n8n.io/build/build-and-manage-agents) (read 2026-11-05)
- [n8n Docs: Integrate AI](https://docs.n8n.io/build/integrate-ai) (read 2026-11-04)
- [n8n Blog: AI agent memory, types, storage and how to implement it](https://blog.n8n.io/ai-agent-memory/) (read 2026-11-05)
- [n8n.io on X: LLMs are stateless by default, 1 September 2026](https://x.com/n8n_io/status/2094757236811636762) (read 2026-11-05)
- [n8n.io on X: n8n is now an agent harness, 24 August 2026](https://x.com/n8n_io/status/2091838324163940766) (read 2026-11-05)

[Browse n8n workflows](https://mindket.com/automations/n8n)
