Mindket

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

A black banner with the n8n logo and the words "n8n course" over "Your first workflow, webhooks, an AI agent and self-hosting".

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.

In this lesson

  • 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.
All courses
On this page
  1. Before you start
  2. Build an agent that can look things up and do sums
  3. What each part of the agent does
  4. Why one message can run the agent three times
  5. Agent, chain or something else
  6. What n8n's team says about agent memory and its new agents
  7. Common mistakes
  8. Try it yourself
  9. What to learn next
  10. Check yourself
  11. Frequently asked questions
  12. Sources

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 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 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:

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 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 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 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 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. A tutorial that asks you to pick an agent type predates that change.

From the AI Agent and Tools Agent pages.
Sub-nodeWhat it gives the agentRequired?
Chat model, such as OpenAI Chat ModelThe language model that reads the message and decides what to doYes
Tool, such as Calculator or WikipediaAn add-on the agent can call for information or an actionAt least one
Memory, such as Simple MemoryThe chat history, so a follow-up question has contextNo
Output parserA fixed output format, when Require Specific Output Format is onNo

Why one message can run the agent three times

n8n's page on 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 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 says chains have no persistent memory, so they can't refer to earlier context.

AI Agent node or Basic LLM Chain
AI Agent nodeBasic LLM Chain
Uses memoryYesNo
Uses toolsYesNo
Chooses which tool to callYesNo
Follows a fixed sequence of callsNoYes

Sources: n8n Docs: Agents vs chains (read November 4, 2026), n8n Docs: What agents do (read November 4, 2026)

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

On 1 September 2026 the n8n team posted on X 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, 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 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 (read November 5, 2026)
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.
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.
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 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 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 explains the protocol. To see an agent inside a complete workflow before you build your own, Mindket's n8n workflows 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?

    Show answer

    C. Simple Memory 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?

    Show answer

    B. The agent runs more than once per message, for setup, a tool call and the reply 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?

    Show answer

    A. Click + Chat Model under the agent and pick one 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?

    Show answer

    D. When the job needs tools or a conversation history 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 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 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 says every message runs your workflow, so a ten-message conversation uses ten executions.

Sources

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

Share this lesson

See an agent inside a finished workflow

Open an n8n workflow on Mindket to see its agent node and the sub-nodes plugged into it, drawn live before you download.

Browse n8n workflows

This lesson as Markdown · n8n course for beginners · All courses