Guide
n8n AI Agent Tutorial: Build Your First Agent
n8n's AI Agent node lets you build a working AI agent visually — no glue code — by wiring a chat model, memory, and tools onto one node. This tutorial walks through building your first agent end to end: the trigger, the AI Agent node, attaching a model, adding memory so it remembers the conversation, giving it tools, and testing it in chat. Steps follow n8n's official AI documentation (read 2026-06-20).
Before you start
- An n8n instance — n8n Cloud or a self-hosted instance (both support the AI Agent node)
- An API key for a chat model provider (e.g. OpenAI, Anthropic, Google) to attach to the agent
- Basic familiarity with the n8n canvas (adding nodes and connecting them)
- Optional: credentials for any tool you want the agent to use (e.g. a search or HTTP tool)
Steps
- 01
Create a workflow and add a Chat Trigger
In n8n, create a new workflow. Add a Chat Trigger node so you have a chat interface to talk to your agent. This trigger gives you the 'Chat' button on the canvas that opens a local chat window for testing. (You can swap the trigger later — e.g. a webhook or schedule — once the agent works.)
# On the n8n canvas: # 1. New workflow # 2. Add node -> 'Chat Trigger' - 02
Add the AI Agent node
Add the 'AI Agent' node — it is the core of adding AI to your workflow. In n8n the AI agent is represented as a node with some extra connection points underneath it (called sub-nodes) for a chat model, memory, and tools. Connect the Chat Trigger's output into the AI Agent node.
# Add node -> 'AI Agent' # Connect: Chat Trigger -> AI Agent - 03
Attach a Chat Model (required)
AI agents require a chat model to be attached to process the incoming prompts. Under the AI Agent node, add a chat model sub-node for your provider (for example an OpenAI or Anthropic chat model), and set its credentials. Without a model attached, the agent cannot run.
# Under the AI Agent node, add the chat model sub-node: # AI Agent -> (Chat Model) -> e.g. 'OpenAI Chat Model' # Set the provider credential (your API key) - 04
Add memory so the agent remembers the conversation
Out of the box the model answers each message in isolation — tell it your name, and a few messages later it has forgotten. Attach a memory sub-node (for example 'Simple Memory') to the AI Agent so it retains conversation context across turns. After adding memory, repeat the conversation and the agent will remember earlier details like your name.
# Under the AI Agent node, add the memory sub-node: # AI Agent -> (Memory) -> 'Simple Memory' # (Simple Memory keeps recent turns; other memory types exist for longer context) - 05
Give the agent tools
Tools are what turn a chatbot into an agent — they let it take actions, not just talk. Attach one or more tool sub-nodes to the AI Agent (for example a search tool, an HTTP request tool, or another n8n node exposed as a tool). The agent decides when to call each tool based on the user's request. Start with one tool, confirm it works, then add more.
# Under the AI Agent node, add a tool sub-node: # AI Agent -> (Tool) -> e.g. an HTTP Request tool or a search tool # Add only the tools the agent needs for the task - 06
Test your agent in chat
Click the 'Chat' button near the bottom of the canvas. This opens a local chat window on the left and the AI agent's execution logs on the right, so you can watch which model calls and tool calls happen for each message. Send a message, confirm the agent responds, remembers context, and calls tools when appropriate. Iterate on the model, memory, and tools until it behaves the way you want.
# Click 'Chat' on the canvas -> send a test message # Left: chat window Right: agent logs (model + tool calls)
Troubleshooting
- The AI Agent node errors that no chat model is connected
- An agent cannot run without a chat model. Under the AI Agent node, add a chat model sub-node for your provider and set valid credentials. Confirm the credential is selected and the model name is one your account can access.
- The agent does not remember earlier messages
- Without a memory sub-node, each message is handled in isolation. Attach a memory sub-node (e.g. Simple Memory) to the AI Agent node. If it still forgets, check that memory is connected to the same agent and that you are using a trigger/session that preserves a conversation id.
- The agent never calls a tool you attached
- Make sure the tool sub-node is connected to the AI Agent's tool connection (not the main flow), and that the tool has a clear name/description so the model knows when to use it. Too many tools can also confuse the agent — start with one, confirm it is called, then add more.
- Node names or UI do not match this guide exactly
- n8n's AI features evolve between versions, so exact node names, sub-node labels, and the canvas UI can differ from this walkthrough. Use n8n's official Advanced AI documentation for your version as the source of truth; the structure (AI Agent + chat model + memory + tools) is stable even when labels change.
Our AI agents
From the team behind AI Coding Hub — agents that pick up where the code ends:
- AI document agentDraftlizeTurn rough notes, specs and transcripts into clean, structured docs with an AI doc agent.Try Draftlize →
- AI presentation agentDecklizeGenerate editable slide decks from a prompt or an existing doc with an AI presentation agent.Try Decklize →
- AI data agentTablizeQuery, clean and chart spreadsheets and CSVs in plain English with an AI data agent.Try Tablize →
FAQ
- What is the AI Agent node in n8n?
- It is the node that adds an AI agent to your workflow. Unlike a plain LLM call, the AI Agent node has extra connection points (sub-nodes) for a chat model, memory, and tools — so it can hold a conversation, remember context, and take actions by calling tools. It is the core building block for agents in n8n.
- How do I add memory to an n8n AI agent?
- Attach a memory sub-node — such as 'Simple Memory' — to the AI Agent node. Without memory, the agent answers each message in isolation; with it, the agent remembers earlier turns (like your name) across the conversation. Different memory types trade off how much context they retain; start with Simple Memory and adjust if you need longer recall.
- Do I need to self-host n8n to build an AI agent?
- No. The AI Agent node works on both n8n Cloud and self-hosted n8n. Self-hosting gives you more control and can be cheaper at scale; Cloud is faster to start. Either way you supply your own chat model API key for the agent to use.
- What can n8n AI agents do with tools?
- Tools let the agent take actions instead of only chatting — for example searching the web, making HTTP requests, querying a database, or triggering other n8n nodes. The agent decides when to call each tool based on the user's request. Attach only the tools the task needs; too many at once can degrade the agent's decisions.
- Is this the same as a coding agent like Claude Code?
- No. n8n's AI Agent is a visual, workflow-based agent for automation — connecting models, memory, and tools on a canvas. Coding agents like Claude Code or OpenCode run in your terminal and edit code directly. They solve different problems; many teams use n8n for automation and a coding agent for development.
Related