AI Agents

n8n AI Agent Tutorial: Build Your First AI Agent (Step by Step)

Learn how n8n AI agents work and build one step by step: chat trigger, model, memory, tools, then RAG and MCP. Plus the best free n8n AI agent tutorials to go further.

By the n8n Academy team · Updated · 5 min read

n8n AI Agent Tutorial: Build Your First AI Agent (Step by Step)

AI agents are the reason n8n went from "self-hosted Zapier" to one of the most talked-about tools in automation. A normal workflow follows the path you drew. An agent gets a goal, looks at the tools you gave it, and decides which ones to use and in what order. That makes it far more flexible, and far easier to get wrong.

This tutorial explains how the n8n AI Agent node fits together, walks through building a first agent, and then points you to the best free agent tutorials in the n8n Academy library for going further.

How an n8n AI agent works

The AI Agent node is the brain, but on its own it does nothing. You attach sub-nodes to it, and each one has a job:

PartWhat it doesTypical choice
TriggerStarts the agent with a messageChat Trigger, Webhook, Telegram, Gmail
Chat modelThe language model that reasons and decidesOpenAI, Anthropic Claude, Google Gemini, local models
MemoryRemembers earlier messages in the conversationSimple Memory, Postgres or Redis chat memory
ToolsActions the agent may takeGoogle Sheets, Gmail, HTTP Request, Calculator, another workflow
Output parser (optional)Forces a structured answerStructured Output Parser

When a message arrives, the model reads it along with the system message you wrote and the descriptions of every tool. It either answers directly or calls a tool, reads the result, and repeats until it has an answer. Tool descriptions matter more than people expect: they are the only way the model knows when a tool should be used.

Build your first n8n AI agent in 6 steps

  1. Add a Chat Trigger. Create a new workflow and add the "When chat message received" trigger. It gives you a built-in chat window for testing.
  2. Add the AI Agent node and connect it to the trigger.
  3. Attach a chat model. Click the Chat Model connector, pick a provider (OpenAI, Anthropic, Gemini) and add your API key as a credential.
  4. Attach memory. Add Simple Memory so the agent remembers the conversation. Without it, every message is the first message.
  5. Write a system message. In the agent's options, describe its role, what it should and should not do, and how to answer. Be specific: "You are a support assistant for a bakery. Only answer questions about orders, opening hours and products."
  6. Add one tool and test. Connect a Google Sheets tool that reads your product list, describe it clearly ("Use this to look up product names and prices"), then ask the agent about a product in the chat window. Open the execution log to see the exact tool call it made.

The most common mistake

Adding five tools at once. When the agent misbehaves you cannot tell which tool confused it. Add one tool, test it until it is reliable, then add the next.

Start here: first-agent tutorials

Level 2: RAG (answering from your own documents)

Retrieval-augmented generation, or RAG, lets an agent answer from your documents instead of only from what the model was trained on. In n8n you load documents into a vector store (Supabase, Pinecone, Qdrant, Postgres with pgvector, or the in-memory store for testing), then give the agent a vector store tool. When a question comes in, the agent searches the store, reads the most relevant chunks and answers from them. This is the foundation of most customer-support and internal-knowledge agents businesses pay for.

Recommended tutorials from the library

Level 3: Voice agents and real projects

Once text agents are reliable, the same pattern extends to voice (n8n connected to a voice platform such as Vapi or Retell) and to multi-step systems: a sales coach that analyses call recordings, or a newsletter agent that researches and drafts every week. These are the builds that turn into paid client work.

Recommended tutorials from the library

Level 4: Claude, MCP and building agents faster

The newest shift is AI building the workflows themselves. n8n supports the Model Context Protocol (MCP), so tools like Claude can connect to your n8n instance, and n8n agents can use MCP servers as tools. Builders now use Claude to draft and debug workflows, then refine them in the canvas. It does not replace understanding n8n, but it makes an experienced builder much faster.

Recommended tutorials from the library

Tips for agents that do not break in production

  • Prefer a normal workflow when the steps are fixed. If the path is always the same, you do not need an agent; a plain workflow is cheaper and more predictable.
  • Give tools narrow jobs and descriptive names. "lookup_order_by_email" beats "Google Sheets".
  • Set a max iterations limit so a confused agent cannot loop and burn API credits.
  • Use guardrails to check inputs and outputs for things you never want to send.
  • Log every execution and read them. The execution log shows exactly what the agent decided and why.

Go deeper with a full course

All courses are included in one $12.99 payment. See every course

Frequently asked questions

What is an AI agent in n8n?

An n8n AI agent is a workflow built around the AI Agent node, where a language model decides which tools to use to complete a task. You attach a chat model, optional memory and tools such as Google Sheets or HTTP requests, and the model chooses which to call.

Which AI models can I use with n8n agents?

n8n supports the major providers, including OpenAI, Anthropic Claude, Google Gemini, Mistral and Groq, as well as local models through Ollama. You add the provider as a chat model sub-node on the AI Agent and switch models without rebuilding the workflow.

Can I build n8n AI agents for free?

n8n itself is free to self-host, so the only cost is the AI model. You can test with free tiers from some providers or run a local model through Ollama for zero API cost, then switch to a paid model when a client needs better quality.

What is the difference between an AI agent and an AI workflow in n8n?

An AI workflow follows fixed steps you design and calls a model at specific points. An AI agent decides its own steps by choosing tools. Use a workflow when the process is predictable and an agent when the right action depends on the input.