NewWant your AI tool to stand out? Join 2K+ tools already promoted
n8n
AI Agents
Automation
Tutorials

How to Build an AI Agent in n8n (Step-by-Step Tutorial)

Timidlly iTools Team

Editorial Team

December 06, 2026

An n8n AI agent is a workflow built around n8n's AI Agent node: you give it a chat model to think with, memory so it remembers the conversation, and tools it is allowed to use, and it decides for itself which tools to call to complete a request. You can build a working one in under an hour without writing code.

This tutorial builds a simple chat agent you can test in the editor, then turns it into something useful, such as an email assistant. It explains what each piece does, so you can adapt the pattern rather than copy it blindly.

n8n's interface changes regularly, so button labels may differ slightly from what you see. The concepts, and the node names used here, are the stable part.

Quick answer: what you need

  • An n8n instance, either n8n Cloud or self-hosted with Docker or npm.
  • An API key for a model provider such as OpenAI, Anthropic or Google Gemini, or a local model served through Ollama.
  • Four building blocks: a trigger, the AI Agent node, a chat model sub-node, and optionally memory and tool sub-nodes.
  • A clear job for the agent. "Answer questions about our refund policy and log each request" works. "Be helpful" does not.

n8n explained in two minutes

If you are wondering what n8n is (or searching "n8n kya hai"), it is a workflow automation tool. You connect nodes on a canvas: a trigger node starts the workflow, and each following node does one thing, such as reading a spreadsheet, calling an API or sending a message. It competes with Zapier and Make, and we compare them in n8n vs Zapier vs Make.

What makes n8n popular for AI work is its set of AI nodes. Rather than treating a language model as one more step that returns text, n8n lets you build agents that reason about which steps to take. If you have never used n8n, skim our beginner's guide to n8n first, then come back.

How the n8n AI Agent node works

The AI Agent node is a root node with slots underneath it for sub-nodes. That structure is the key thing to understand.

  • Chat Model (required). The language model the agent uses to reason and write replies, for example OpenAI Chat Model, Anthropic Chat Model, Google Gemini Chat Model or Ollama Chat Model.
  • Memory (optional). Stores recent messages so the agent can follow a conversation. Simple Memory keeps them inside n8n; there are also options backed by databases such as Postgres or Redis.
  • Tools (optional but the whole point). Things the agent may do: run a calculation, search Wikipedia, call an API, read a Google Sheet, send an email, or run another n8n workflow.
  • Output Parser (optional). Forces the final answer into a structured format, useful when a later node expects specific fields.

When a message arrives, the agent sends it to the model along with the descriptions of every connected tool. The model either answers directly or asks to use a tool. n8n runs the tool, hands the result back, and the loop continues until the model produces a final answer. That loop, not the model itself, is what makes it an agent.

Before you start: installing n8n

People often search for an "n8n AI agent download", but there is nothing separate to download. The AI Agent node ships with n8n itself. You need one of these:

  • n8n Cloud: sign up and you get a hosted editor with no installation.
  • Docker: the most common self-hosted route, and the one to use on a home server or NAS. On Unraid, for example, people typically run n8n as a Docker container.
  • npm: run n8n directly with Node.js, which is fine for trying it out locally.

Self-hosting is free for your own use under n8n's licence, but you are responsible for updates and backups. Then get an API key from your model provider and keep it handy.

n8n AI agent tutorial: build a chat agent step by step

This first agent is a general assistant that can do maths and look things up on Wikipedia. Neither tool needs extra credentials, so it is the quickest way to see the agent loop working.

  1. Create a new workflow from the n8n dashboard and give it a name.
  2. Add a chat trigger. Add the trigger called "When chat message received" (the Chat Trigger node). This lets you talk to the workflow from a chat panel inside the editor.
  3. Add the AI Agent node and connect it after the trigger. By default the agent takes the user's message from the connected chat trigger, so you do not need to map the input manually.
  4. Connect a chat model. Click the Chat Model slot under the AI Agent node and choose your provider. Create a new credential, paste your API key, save it, and pick a model from the list.
  5. Add memory. Click the Memory slot and choose Simple Memory. Its context window length setting controls how many recent exchanges are kept. When used with the chat trigger, the conversation's session ID is picked up automatically, so each chat keeps its own history.
  6. Add tools. Click the Tool slot and add the Calculator tool, then add the Wikipedia tool the same way.
  7. Write a system message. In the AI Agent node's options, add a system message. Something like: "You are a concise research assistant. Use the Calculator for any arithmetic. Use Wikipedia for factual questions and say when you could not find an answer. Never make up facts."
  8. Test it. Open the chat panel and ask something that needs both tools, such as the population of two cities added together. Then open the execution log or the agent's output to see which tools it called and what came back.
  9. Save and activate. When you are happy, save the workflow. The Chat Trigger has options for making the chat available outside the editor, such as a public chat page; check the node's current settings for how to publish and secure it.

That is a complete n8n AI agent. Every agent you build from here follows the same shape.

Give the agent real tools

The value comes from connecting tools that touch your actual work. Most of n8n's app nodes can be attached to the agent as tools, along with a few dedicated tool nodes.

  • App tools: Gmail, Google Sheets, Google Calendar, Slack, Notion and many others can be added in the Tool slot, so the agent can read or write data in those apps.
  • HTTP Request tool: lets the agent call any API you describe to it.
  • Call n8n Workflow tool: turns a separate workflow into a tool. This is the cleanest way to give an agent a complex, multi-step capability while keeping the logic predictable.
  • MCP Client tool: connects the agent to tools exposed by an MCP server. If that acronym is new, read our MCP explainer.

Two settings matter more than anything else here. First, the tool description: the model decides whether to use a tool based on its name and description, so write them plainly ("Look up a customer's order status by order number"). Second, parameters: n8n lets you mark a field as filled by the model (using the "let the model define this parameter" option, which inserts a $fromAI() expression), so the agent can supply things like a search query or an email subject at run time while you fix everything else.

n8n email automation example: an inbox assistant

Here is a more practical n8n AI agent example: triaging incoming email.

  1. Trigger: use the Gmail Trigger to start the workflow when a new email arrives. For Outlook, use the Microsoft Outlook trigger.
  2. Agent input: in the AI Agent node, switch the prompt from the chat trigger to a prompt you define, and pass in the sender, subject and body from the trigger.
  3. System message: explain the categories you care about (sales enquiry, support request, invoice, newsletter) and what to do with each.
  4. Tools: a Gmail tool that can add labels, a Gmail tool that creates a draft reply rather than sending, and a Google Sheets tool that logs each email and its category.
  5. Safety: keep the agent drafting, not sending, until you have reviewed a few weeks of results.

What about n8n with Yahoo Mail? There is no dedicated Yahoo node, but the generic Email Trigger (IMAP) node can watch a Yahoo inbox and the Send Email node can send through Yahoo's SMTP server. Yahoo generally requires an app password for third-party apps, so generate one in your Yahoo account security settings rather than using your normal password.

More n8n AI agent workflows to try

Once the pattern clicks, these are common next projects.

  • Customer support FAQ agent: add a vector store tool that searches your help docs, so answers are grounded in your own content. Our guide to RAG for beginners explains how that retrieval works.
  • Meeting prep assistant: reads tomorrow's calendar, looks up each attendee's company, and sends you a briefing.
  • CRM updater: takes rough notes from a sales call and updates the right fields in your CRM.
  • Research agent: searches the web through an API, summarises findings and saves them to a document.

You do not need to start from scratch for any of these. Our n8n templates library includes many agent workflows you can import and adapt.

Making your agent reliable

Agents fail in predictable ways. A few habits prevent most of it.

  • Keep the tool list short. Every extra tool is another chance for the model to pick the wrong one. Three well-described tools beat twelve vague ones.
  • Be explicit in the system message. Say what the agent must never do, when it should ask for clarification, and what format the answer should take.
  • Limit iterations. The AI Agent node has a maximum iterations option. Keep it modest so a confused agent cannot loop and run up costs.
  • Put a human in the loop for anything irreversible. Sending emails, issuing refunds and deleting records should go through an approval step. Several messaging nodes, Slack and Gmail among them, have a send-and-wait option that pauses the workflow until someone responds.
  • Use workflows for the predictable parts. If a step should always happen the same way, build it as a normal workflow and give the agent a single tool to trigger it.
  • Watch the logs. Executions show every tool call and are the fastest way to find a bad tool description.

How to choose: agent or plain workflow?

Not every automation needs an n8n AI agent, and using one where a normal workflow would do adds cost and unpredictability.

Use a plain workflow, perhaps with a single AI step to classify or summarise, when the steps are always the same. Use an agent when the right next step depends on the content: a request that might need a lookup, a calculation, or nothing at all.

For the model, pick based on the job. Stronger hosted models handle tool-calling more reliably, which matters when the agent has several tools. Local models through Ollama keep data on your own hardware but may struggle with complex tool use.

n8n training: where to learn more

The best free n8n training is n8n's own documentation, which includes structured beginner and intermediate courses plus a section on its AI nodes. The community forum is active and good for specific errors. Importing an existing template and reading how it is wired is often the fastest way to learn.

FAQ

Is the n8n AI agent free to use?

The AI Agent node is part of n8n, so it is free if you self-host the community edition. You still pay your model provider for usage, unless you run a local model through Ollama. n8n Cloud is a paid service, so check its current plans.

What is the n8n AI Agent node?

It is a root node that combines a chat model, optional memory, optional tools and an optional output parser. It sends each request to the model, runs whichever tools the model asks for, and returns a final answer once the model is done.

Can I build an n8n AI agent without coding?

Yes. Everything in this tutorial uses the visual editor and plain-English instructions. Code becomes useful later, for example in a Code node to reshape data before it reaches the agent, but it is not required to get started.

Can n8n agents use local models?

Yes. The Ollama Chat Model sub-node connects the agent to models running on your own machine or server. This keeps data local, but smaller models can be less reliable at choosing and using tools.

Can n8n work with Yahoo Mail?

Yes, through the generic Email Trigger (IMAP) and Send Email (SMTP) nodes rather than a dedicated integration. Use an app password generated in your Yahoo account settings, and check Yahoo's current server settings.

Start building

The fastest route from this tutorial to a useful n8n AI agent is to pick one recurring task, give the agent two or three well-described tools, and keep a human approving anything irreversible. For a head start, browse our n8n templates and adapt an agent workflow that is already close to what you need.