MMOOZZGG.com

How to build an AI agent

n8n AI agent tutorial: how to build an AI agent on n8n

8 min read21 sources

This n8n AI agent tutorial shows how to build an agent with the mouse from ready-made nodes: a chat input, a model, memory and tools from more than 400 integrations. Below: installation on your own server, building the agent on an open model with Ollama, and the terms of the fair-code license. Each step follows the n8n documentation.

On this page · 5 sections

Build it yourself in a week

What n8n is

n8n builds workflows from nodes. A node does one action: it reads an email, writes a row to a spreadsheet, calls a model. Nodes are linked with arrows on a canvas, and you don’t need to write code.

The company n8n has worked in Berlin since 2019. In October 2025 it raised a $180 million Series C round at a $2.5 billion valuation.

One of the nodes is an AI agent. It connects a model to email, CRM, spreadsheets and messengers, and decides by itself which tool to call for a task.

If a fixed chain of steps with no choices solves the task, you don’t need an agent: a regular automation workflow is enough. We covered how to tell the difference on the page about how an agent differs from a workflow.

Installing on your own server

You need your own installation so that customer data and access keys stay with you. The n8n documentation warns plainly: self-hosting needs skills in setting up and securing servers, and a mistake means lost data and downtime.

For a first try, n8n has the Self-hosted AI Starter Kit. It is a Docker Compose template that installs n8n, Ollama for open models, the Qdrant vector database and PostgreSQL with one command. Docker runs programs in isolated containers, so you don’t need to set up each one by hand.

1. Install Docker Desktop on a Mac or Windows. On a Linux server, install Docker Engine and Docker Compose.

2. Download the kit and create the settings file: git clone https://github.com/n8n-io/self-hosted-ai-starter-kit.git, then cd self-hosted-ai-starter-kit and cp .env.example .env. In the .env file, replace the passwords and secrets with your own.

3. Start the kit with the command docker compose --profile cpu up. On a server with an NVIDIA graphics card, write gpu-nvidia instead of cpu.

4. On a Mac with an M1 chip or newer, you cannot pass the graphics card into Docker. So install Ollama directly on the Mac, start the kit with docker compose up, and set OLLAMA_HOST=host.docker.internal:11434 in the .env file.

5. Open http://localhost:5678 in a browser and complete the initial n8n setup. You do it once.

6. On the first launch, the kit downloads an open model by itself. Until the download is finished, the agent will not answer: you can see the download progress in the Docker log.

n8n itself calls the kit a tool for testing an idea: before work with customers, you need to secure it. The main n8n installation now runs with the command curl -fsSL https://get.n8n.io | sh, and for a team and a production environment the documentation advises replacing the built-in SQLite database with Postgres.

The agent node and the model

An agent in n8n is the “AI Agent” node plus the sub-nodes connected to it: a model, memory and tools. Sub-nodes do not sit in the main chain; they give the agent its abilities.

1. On the “Overview” page, click “Create Workflow”, then “Add first step”, and choose “Chat Trigger”. This node receives messages and starts the agent.

2. Add an “AI Agent” node next. In the “System Message” parameter, write the instruction: the agent’s role, what it may do and what it may not.

3. Connect “Ollama Chat Model” to the model input. In the Ollama credentials, the “Base URL” field defaults to http://localhost:11434. If n8n runs in Docker and Ollama on the same computer, enter http://host.docker.internal:11434.

4. In the “Model” field, choose a model you downloaded in Ollama. An agent needs a model that can call tools: in the Ollama catalog, such models carry the tools tag, for example Qwen 3.

5. Connect “Simple Memory” to the memory input. In the “Context Window Length” field, set how many past messages the agent takes into account. Without memory, it reads each question from a blank page.

6. Connect at least one tool: without it, the agent node does not work. The next section shows how.

7. Open the workflow chat on the canvas and ask a question. To see which steps the agent took before answering, turn on the “Return Intermediate Steps” parameter.

The “Max Iterations” parameter limits the number of model attempts, 10 by default. The limit keeps the agent from repeating a failed step forever.

Each chat message starts the workflow again: a conversation of 10 messages means 10 executions. On your own server this is load on the server, and on the n8n cloud plan it uses up your limit.

Connecting services

A tool in n8n is an app node connected to the agent. The agent decides by itself when to call it: to find an email in Gmail, write a row to Google Sheets, send a message in Telegram, run a query in Postgres, or call any service through HTTP Request.

1. Click the tools input of the “AI Agent” node and choose an app.

2. In the credentials field, choose “Create new credential” and enter an access key or sign in to the service.

3. For Telegram, create a bot: in the chat with BotFather, send the /newbot command, set the bot’s name and address, and paste the token you get into the “Access Token” field.

4. To make the agent answer in Telegram, put “Telegram Trigger” as the first node instead of “Chat Trigger”. In the agent node, choose “Define below” in the “Prompt” field and point it to the text of the incoming message.

5. For actions that change data or write to customers, turn on manual approval in the “Human review” section of the tools panel. The request comes to you in a chat, Slack or Telegram, and the action does not run without your consent.

6. When the agent answers correctly, click “Publish”. Before publishing, the workflow runs only in manual testing.

Telegram accepts a webhook, the address for incoming messages, only over HTTPS. So a bot needs a server with a domain and a certificate, and the public n8n address goes into the WEBHOOK_URL variable. One bot can have only one webhook, so it helps to create a second bot for testing.

MCP is a common way to connect AI to data and services; Anthropic opened the protocol on 25 November 2024. The “MCP Client Tool” node gives the agent the tools of an external MCP server: all of them, only selected ones, or all except excluded ones. Details are on the page about how to connect an MCP server.

If the agent works with the data of customers in Russia, 152-FZ, Russia’s personal data law, applies: the data of Russian citizens is collected and stored in databases in Russia, and before sending data abroad the operator notifies Roskomnadzor, the Russian data regulator. So for such agents, n8n and the model go on a server in Russia. What else to check is collected on the page about data security.

License: what a business may do

n8n is distributed under the Sustainable Use License. This is the fair-code model: the code is open to read and change, but the author limits commercial use. n8n does not call itself open source: by the OSI definition, an open license cannot restrict use.

You may: install n8n on your own server for free and automate your own business. You may build workflows for clients on your own instance, if the clients cannot create and change them, and charge for setup, support and training.

You may not: sell n8n as a cloud service where clients build workflows themselves, release n8n under your own brand, or turn its code into your own automation product. Such cases need a separate agreement with n8n.

The license appeared in 2022. Until 17 March 2022, n8n was distributed under Apache 2.0 with the Commons Clause condition.

The free Community edition has almost all features. Single sign-on (SSO), environments, projects, shared workflows and credentials, external secret stores and version control through Git need a paid plan.

A typical n8n agent is built from ready-made nodes. If someone charges for it as for unique development, ask what the price is made of, and pay for a result by the metric, not for hours.

Sources and fact-checking

Checked by the editors on 16 October 2026.

  1. Wikipedia, 2026 (en.wikipedia.org)
  2. Anthropic, 25 November 2024 (anthropic.com)
  3. Brace Law Firm, 9 July 2023 (brace-lf.com)
  4. n8n Docs, 2026 (docs.n8n.io)
  5. n8n Docs, 2026 (docs.n8n.io)
  6. n8n, GitHub n8n-io/self-hosted-ai-starter-kit, 2026 (github.com)
  7. n8n Docs, 2026 (docs.n8n.io)
  8. n8n Docs, 2026 (docs.n8n.io)
  9. n8n Docs, 2026 (docs.n8n.io)
  10. n8n Docs, 2026 (docs.n8n.io)
  11. n8n Docs, 2026 (docs.n8n.io)
  12. n8n Docs, 2026 (docs.n8n.io)
  13. n8n Docs, 2026 (docs.n8n.io)
  14. n8n Docs, 2026 (docs.n8n.io)
  15. Ollama Library, 2026 (ollama.com)
  16. n8n documentation: Deploy with the AI starter kit, checked 16 October 2026 (docs.n8n.io)
  17. n8n documentation: Build your first workflow, checked 16 October 2026 (docs.n8n.io)
  18. n8n documentation: AI Agent, checked 16 October 2026 (docs.n8n.io)
  19. n8n documentation: Ollama credentials, checked 16 October 2026 (docs.n8n.io)
  20. n8n documentation: Simple Memory, checked 16 October 2026 (docs.n8n.io)
  21. n8n documentation: Telegram credentials, checked 16 October 2026 (docs.n8n.io)

Found a mistake? Tell us

Publications

Contact us