How to Build an AI Agent with n8n: A Beginner’s Step-by-Step Guide

Published On: 20 October 2026.By .
AI & Automation/Beginner tutorial/16 min
INPUT customer question AI AGENT decides what to do next looks it up in the FAQ writes a draft answer flags what it is unsure of
FIG 00  The assistant you are about to build. Schematic, not a screenshot.
The short answer

You build an AI agent in n8n by adding one AI Agent node to a workflow, connecting a chat model that supports tool calling, and giving the agent a tool it can choose to use. In this guide you build a small support assistant that reads a question, searches a demonstration FAQ, writes a draft answer, and flags anything uncertain for a person. The easiest first setup is n8n Cloud with a low-cost hosted model such as gpt-4o-mini, and a working version takes roughly 30 to 60 minutes. Everything it produces is a draft. Nothing reaches a customer automatically.

What matters most
  1. An agent is not a chatbot with a nicer prompt. It becomes an agent when the model can decide to take an action, such as searching your FAQ, before it answers.
  2. The model you pick must support tool calling. This is the single most common reason a first build quietly fails.
  3. Forcing a structured JSON output is what lets the workflow route an uncertain answer to a human instead of guessing from free text.
  4. Cost splits four ways: the n8n plan, model usage, hosting, and your time. Self-hosting is free software, not a free setup.

A support inbox on a Monday has forty messages in it, and maybe thirty of them have been answered before in almost the same words. Where is my order. Do you ship here. What is the return window.

Someone still opens each one, remembers the policy, and types it out again. That repetition is the obvious thing to hand to software, and it is also the thing people get wrong first. The usual attempt is to point a language model at the inbox and let it write replies. It works for a while, and then it confidently invents a refund policy your company has never offered.

The fix is not a cleverer model. It is giving the model a way to look things up, and a way to say "I do not know this one, a person should take it." That gap, between a thing that writes and a thing that checks before it writes, is the difference between a text generator and an agent. It is also what you are about to build.

01

What an AI agent actually is

An AI agent is a program that uses a language model to decide what to do, not just what to say. A chatbot takes your text and writes a reply in one step. An agent can choose to take an action first, such as searching a document, and then use what it found to answer. n8n's documentation describes an agent as something that "uses a language model to decide which actions to take," making the model the decision-maker rather than just the writer.

Six words come up repeatedly. Here is what each means in practice.

TermWhat it means here
NodeOne block in a workflow that does a single job, such as "run the AI agent" or "check a condition." You join nodes with lines to pass data along.
TriggerThe node that starts a workflow. Here it is where a sample question enters.
CredentialA saved, encrypted login such as an API key, so n8n can talk to another service. Set it once, reuse it.
APIHow two programs talk to each other. When n8n uses a model, it talks to that model's API.
Tool callingThe model's ability to say "I want to use this tool now, with this input." The model does not run the tool. n8n runs it and hands back the result. Only some models can do this, which matters a lot later.
MemoryAn optional add-on so the agent remembers earlier messages. n8n notes this memory does not persist between sessions.
An honest definition

If you only ask a model to write an answer from a prompt, with no tool and no decision, that is a text generator, however it is labelled. The build below is a genuine agent because the model chooses whether to call the FAQ tool, chooses what to search for, and decides whether a human is needed. It is also deliberately not autonomous. A person reviews anything uncertain, and that is a design choice, not a missing feature.

For the background on how agents reason, the types of agents, and the safety thinking behind them, our explainer on what AI agents are and how they work is the companion to this hands-on guide.

02

What you will build

An internal first-draft support assistant. A question goes in, the agent searches a small FAQ, and a draft comes out with a flag on it saying whether a person needs to look before it goes anywhere.

01 TRIGGER Question sample message in 02 AI AGENT AI Agent reads, decides, drafts CALLS RETURNS TOOL FAQ lookup agent picks the query structured JSON draft 03 TEST needs_human_review == true ? the one fixed rule in the whole workflow FALSE TRUE Draft ready still a draft, not sent Human review with the agent's notes
FIG 01  The full workflow. Only the agent block makes decisions. Everything else is fixed.

That distinction matters more than anything else in this guide, so it is worth naming directly.

Fixed / you build it

The trigger that brings the question in, the test on the review flag, and the two steps that store the result. These run identically every time.

Decided / the agent chooses

Whether and when to call the FAQ tool, what to search for, how to word the draft, whether something is missing, and whether a person should take over.

03

Before you start: Cloud or self-hosting?

For a first agent, use n8n Cloud. It removes server setup and networking, which is where most first builds die. Self-hosting is a good option once you want privacy or a local model, but it adds moving parts that are easy to get wrong on day one.

n8n CloudSelf-host, your machineSelf-host, Docker or server
Setup effortLowest. Sign up and buildMedium. Install and run itHigher. Container, server, upkeep
Maintained byn8nYouYou
Cost shapeMonthly subscriptionFree software, you pay for the machineFree software, you pay for the server
Reach a model on your laptop?No. It runs on n8n's serversYes, with the right addressYes, with the right address
Best forA first working agent, fastLocal testing and learningA durable, private setup

You also need a chat model that supports tool calling. The simplest choice is an OpenAI account with a small amount of API credit. You do not need a database, a website, or any real customer data. The FAQ is fictional sample data that lives inside the workflow.

Common failureWhy "localhost" is a trap if you self-host

Beginners point n8n at a model running on their own computer using localhost, then get a connection refused error. Every environment has its own idea of what localhost means. n8n Cloud cannot reach your laptop at all, because it runs on n8n's servers. And when n8n runs inside Docker, localhost means "inside this container," not your computer. Full address table in section 08.

Blueprint-style illustration of an automated workflow drawn as connected technical panels
ILLUSTRATION  Six steps, one agent. The build starts here.
04

Building it, step by step

Open n8n and create a new, empty workflow. Each step says what to do and how to tell it worked.

  1. Add a trigger and a sample question

    Click the + on the canvas, search for Manual Trigger, and add "When clicking 'Execute workflow'." This is just a start button for testing. Then add an Edit Fields node (also called Set) after it and rename it to "Sample question." Add one field called question, type String, set to a fictional message such as "Do you ship to Canada and how long does it take?" Click Execute step.

    PASS the node outputs question with your text in it
  2. Add the AI Agent node

    Add a node after "Sample question" and search for AI Agent. In current n8n versions this node runs as a Tools Agent, which is what lets it call tools. Set Source for Prompt to "Define below," then put {{ $json.question }} in the Prompt (User Message) field so the sample question feeds in.

    PASS the node shows connector points underneath for a chat model, memory, tool and output parser. A warning until you attach a model is expected
  3. Connect the brain

    Click the Chat Model connector under the agent and add OpenAI Chat Model. Under "Credential to connect with" choose Create new credential and paste your API key. Never paste a real key into a screenshot or a shared doc. Set Model to gpt-4o-mini, which is low cost and supports tool calling.

    PASS no credential error. A 401 means the key is wrong or billing is not set up
  4. Give the agent a tool

    This is the step that turns a chatbot into an agent. Click the Tool connector and add a Custom Code Tool. Name it faq_lookup. The description matters more than people expect, because the model reads it to decide when to use the tool. Use: "Search the company FAQ for an answer. Input: a short search phrase describing what the customer is asking about. Returns matching FAQ entries, or an empty list if nothing matches." Then paste the code below.

    PASS the tool is on the agent's Tool port with a name and description
  5. Give it instructions and a fixed output shape

    In the agent node open Options and add a System Message, using the instructions in section 05. Then turn on Require Specific Output Format. A new Output Parser connector appears. Click it, add a Structured Output Parser, and give it the JSON example below so every answer returns in the same shape.

    PASS the agent now has a model, a tool and an output parser attached
  6. Route uncertain answers to a human

    Add an IF node after the agent. Add one Boolean condition with the value {{ $json.output.needs_human_review }} and the operator "is true." On the true branch add an Edit Fields node called "Needs human review" setting status to review. On the false branch add one called "Draft ready" setting status to ready.

    PASS two clean branches leave the IF node
FAQ lookup toolpaste into Custom Code Tool › Code
// Demonstration FAQ (fictional sample data). Replace with your own later.
const faq = [
  { id: "SHIP-INTL", q: "international shipping countries and time",
    a: "We ship to the US, Canada, the UK, and Australia. International orders arrive in 7 to 12 business days." },
  { id: "RETURNS", q: "returns refund policy window",
    a: "Items can be returned within 30 days of delivery for a full refund, if unused and in original packaging." },
  { id: "ORDER-TRACK", q: "track order tracking number status",
    a: "A tracking link is emailed when an order ships. Customers can also see status under Account, then Orders." },
  { id: "PAYMENT", q: "payment methods cards accepted",
    a: "We accept Visa, Mastercard, and American Express. We do not accept cash on delivery." }
];

// The agent's search text arrives as the tool input (the `query` variable).
const text = (query || "").toLowerCase();
const words = text.split(/\s+/).filter(Boolean);

const matches = faq.filter(item => {
  const haystack = (item.q + " " + item.a).toLowerCase();
  return words.some(w => haystack.includes(w));
});

return JSON.stringify(matches.length ? matches : [{ note: "No FAQ match found." }]);
Label this one honestly

The snippet above is illustrative and was not run on a live instance for this article. How the Custom Code Tool exposes the agent's input can vary by n8n version. Check it on your own instance and adjust the variable name if yours differs.

Output contractpaste into Structured Output Parser
{
  "draft_answer": "A short, friendly draft reply to the customer.",
  "used_faq": true,
  "matched_faq_ids": ["SHIP-INTL"],
  "needs_human_review": false,
  "missing_information": "",
  "confidence": "high"
}

Forcing a fixed JSON shape is what makes the next step reliable. Without it, the IF node would have to infer a yes or no out of a paragraph of prose, which fails the moment the model phrases things differently.

Screenshot placeholder 1  /  the Edit Fields node open, showing the question field with a sample value and a green success tick after running it
MAIN PATH Trigger sample question AI Agent the only node that decides anything IF route the draft ATTACHED SUB-NODES Chat Model the brain. must support tool calling Memory optional. skip it for version one Tool faq_lookup. the one thing it can choose Output Parser forces clean JSON every time
FIG 02  Top row is the fixed path. The four boxes below are what the agent reaches for while it works.
Screenshot placeholder 2  /  the OpenAI Chat Model node with a saved credential, key hidden, model set to gpt-4o-mini
05

Every node setting in one place

Use this as the build checklist. Anything not listed stays at its default.

NodeRoleKey settings
Manual TriggerStart buttonNone
Edit Fields
"Sample question"
Holds a test questionquestion (String) set to your sample message
AI AgentThe agent itselfSource for Prompt: Define below. User Message: {{ $json.question }}. Require Specific Output Format: On. Options › System Message: see below. Max Iterations: 10 (default)
OpenAI Chat ModelThe brainCredential: your own API key. Model: gpt-4o-mini
Custom Code ToolFAQ lookupName: faq_lookup. Description and Code as given above
Structured Output ParserForces clean JSONThe JSON contract given above
MemoryOptionalLeave out for version one. Add later for multi-turn chat
IFHuman review gateBoolean: {{ $json.output.needs_human_review }} is true
Edit Fields ×2The two outcomesstatus set to review on true, ready on false

The rulebookThe agent's full system instructions

Paste this into the System Message field. It is written to be strict about drafts, honest about gaps, and clear about when to stop and ask.

System messageAI Agent › Options › System Message
You are a customer support drafting assistant for an online store.
Your job is to write a DRAFT reply for a human agent to review. You never
send messages to customers directly.

How to work:
1. Read the customer's question.
2. Use the faq_lookup tool to search the FAQ before you answer. Choose a
   short, specific search phrase based on what the customer is asking.
3. Base your draft only on what the FAQ returns and on the customer's
   question. Do not invent policies, prices, dates, or promises.
4. If the FAQ does not clearly cover the question, say so plainly in the
   draft and set needs_human_review to true.

Rules:
- Be warm, brief, and clear. Use plain language. No emojis.
- If you are missing any information needed to answer correctly, set
  needs_human_review to true and describe what is missing in
  missing_information.
- Never guarantee anything the FAQ does not state.
- If the question involves a complaint, a refund dispute, a legal or safety
  issue, or anything sensitive, set needs_human_review to true regardless
  of what the FAQ says.
- Set confidence to "high", "medium", or "low" based on how well the FAQ
  covered the question.

Always return your answer in the required structured format with these
fields: draft_answer, used_faq, matched_faq_ids, needs_human_review,
missing_information, confidence.
06

Testing it, and knowing it works

Change the question field, click Execute workflow, and read the agent's output. The table shows how a correctly configured agent should behave. These are expected behaviours for teaching, not measured results from a particular run.

Sample questionWhat should happenExpected flag
"Do you ship to Canada and how long?"Calls the tool, finds SHIP-INTL, answers confidentlyfalse, confidence high
"What's your return window?"Finds RETURNS, cites 30 daysfalse
"Can I pay with cryptocurrency?"FAQ does not cover it, so it says sotrue, missing_information filled
"I want a refund, your product broke and I'm furious."Sensitive complaint rule firestrue even if partly covered
"asdfgh"No useful matchtrue, confidence low

Run each one, open the agent's output, and check the JSON has all six fields. Confirm the IF node sends the first two to "Draft ready" and the last three to "Needs human review." To see the agent's working, turn on Return Intermediate Steps in Options and confirm it actually called the tool rather than answering from its own memory.

ReusableVerification checklist

  • The agent calls faq_lookup on a normal question, rather than answering from training
  • A clearly covered question returns needs_human_review: false
  • A question the FAQ does not cover returns true
  • A sensitive or complaint question returns true
  • Every output has all six fields, every time
  • The IF node routes both branches correctly
  • The draft never promises anything the FAQ does not state
  • No real API keys appear in the workflow, in screenshots, or in exports
Screenshot placeholder 3  /  the full canvas: trigger, sample question, AI Agent with its sub-nodes, the IF node, both branches
07

When it breaks: what to check first

Five things go wrong far more often than anything else. Match what you see on screen to a column, then work down it.

WHAT DO YOU SEE ON SCREEN? 401 / bad key on the chat model Ignores the FAQ answers anyway ECONNREFUSED self-host or Ollama Bad JSON parser error Nothing runs no output at all CHECK CREDENTIAL Re-paste the keyRight providerBilling activePress Test CHECK TOOL CALLING Model supportstool callingSharper tooldescription FIX THE ADDRESS In Docker, usehost.docker.internalBind to 0.0.0.0Cloud cannot reachyour laptop FORCE THE FORMAT Require SpecificOutput Format onAdd the parserOr auto-fixing one CHECK THE TRIGGER Press ExecuteTrigger has dataNodes actuallyconnected Still stuck: open the failed node, compare its input to its output
FIG 03  Exact error wording varies by n8n version and model provider. Detail in the table below.
SymptomLikely causeWhat to check
401 or invalid API keyCredential wrong, or no billingRe-paste the key with no stray spaces, confirm the right provider, confirm credit is active, then use the credential's Test button
Agent never calls the toolModel cannot tool-call, or the tool is vagueConfirm the model supports tool calling. Make the tool name and description specific. Tell the agent to use it in the system message
Connection refusedWrong address between n8n and the modelSee the address table in section 08. On an IPv6 error use http://127.0.0.1:11434. Make sure the model listens on 0.0.0.0
Output is not valid JSONOutput format not enforcedTurn on Require Specific Output Format and connect the Structured Output Parser. Optionally add an Auto-fixing Output Parser. Keep the system message's field list matching the parser
IF always picks one branchWrong field pathOpen the agent output and confirm the real path to needs_human_review, then update the IF expression
Nothing runsTrigger or connectionsClick Execute workflow, confirm the trigger has test data, confirm every node is actually joined up
Screenshot placeholder 4  /  a successful run: the agent's structured JSON output and the IF node highlighting the branch it took
Four-panel blueprint infographic showing technology components of an automation setup
ILLUSTRATION  Same agent, different engine. Running the model on your own hardware.
08

Running it on a local model with Ollama

You can run a model on your own hardware with Ollama instead of paying per token. For an agent there is one hard requirement: the model must support tool calling, and plenty of local models do not. Ollama supports tool calling with popular models such as Llama 3.1, and groups the capable ones under a Tools category in its model library. Pick from that category, pull the model, and check before you build. A model without tool support will simply never call faq_lookup.

Then swap the chat model for the Ollama Chat Model and set the Base URL in the credential. The correct address depends entirely on where n8n runs, which is where almost everyone gets stuck.

Where n8n and Ollama runBase URLNote
Both on your own machinehttp://localhost:11434On an IPv6 error, use http://127.0.0.1:11434
n8n in Docker, Ollama on the hosthttp://host.docker.internal:11434On Linux, start the container with --add-host host.docker.internal:host-gateway
Ollama in Docker, n8n on your machinehttp://localhost:11434Publish the port with -p 11434:11434
Both in separate containershttp://ollama:11434Use the Ollama container's name
n8n Cloud, Ollama on your laptopNot possible as isCloud runs on n8n's servers. You would need a secured public endpoint, an advanced setup

One more rule from the docs: Ollama has to listen on 0.0.0.0, not only on localhost, or nothing in a container can reach it.

09

What an n8n AI agent costs

There is no single price. Cost splits four ways, and the parts behave very differently. All figures were verified in October 2026 and will drift, so check the linked pages before you budget anything.

Cost 1 of 4The n8n plan

n8n Cloud pricing, billed annually: Starter at 20 euros a month for 2,500 workflow executions, Pro at 50 euros for 10,000, Business at 667 euros for 40,000, Enterprise on request. An execution is one complete run of your workflow, regardless of how many steps it contains. There is a 14-day free trial with Pro-level features and 1,000 executions, no card required. Monthly billing costs more than the annual rates shown.

Cost 2 of 4Model usage

With a hosted model you pay per token. OpenAI lists gpt-4o-mini at 0.15 US dollars per million input tokens and 0.60 per million output tokens. Support questions are small. As an illustrative calculation, not a benchmark, a draft using roughly 2,000 input and 500 output tokens costs about 0.0006 dollars, comfortably under a cent. Measure your own usage rather than trusting that figure, because prompt length and FAQ size change it. With a local model through Ollama there is no per-token charge at all. The download is free and the cost is your hardware and electricity.

Cost 3 of 4Hosting, if you self-host

The self-hosted Community Edition is free software under the Sustainable Use License. n8n calls this fair-code and source available, which is not the same as fully open source, because it restricts some commercial uses. In practice you may run it free for your own company's internal work, including a business that makes money. You need a commercial licence if people outside your organisation build or configure workflows, if you host n8n as a service for paying customers, or if you need enterprise features such as single sign-on. Free software still is not a free setup: you pay for a machine to run it on, and local models want real RAM.

Cost 4 of 4Your time

On Cloud, updates, backups and uptime are someone else's job. Self-hosted, they are yours. No invoice shows that cost, which is exactly why it gets forgotten.

The cheapest way to learn is the Cloud trial and a few cents of model usage. The cheapest way to run privately at scale is self-hosting, paid for in server bills and your own attention.

Blueprint triptych illustrating three stages of an automated support process
ILLUSTRATION  Worth knowing the edges before this goes near a customer.
10

Where this approach falls short

Worth being clear about the edges before you put anything near a customer.

  • It is only as good as the FAQ. A thin or out-of-date FAQ produces confident, wrong drafts. The model will not make up for bad source content.
  • Keyword matching is crude. The demo tool matches words, so a customer who phrases something unusually may get no match. A real version would search properly, or use a vector store.
  • The review flag is a judgement, not a guarantee. The agent can be wrong about being right. Keep a person on the branch that matters until you have watched it for a while.

NextSensible upgrades, one at a time

  1. Add memory

    So it can handle a back-and-forth conversation rather than single questions.

  2. Swap the demo FAQ for real content

    Point the tool at your actual help centre or a vector store instead of the four sample entries.

  3. Send the draft where a person will see it

    A shared inbox, a Slack channel, or your ticketing tool, on the review branch.

  4. Move the lookup into a sub-workflow

    Using the Call n8n Workflow Tool, once it grows beyond a snippet.

Re-run the checklist after each change. One upgrade at a time is how you keep knowing what broke.

The point of this build was never the FAQ or the four sample questions. It was the shape: a model that looks something up before it speaks, and admits when it should not speak at all. Get that shape right on a small, harmless workflow, and the same pattern carries into refund checks, order lookups, and internal helpdesks without becoming something you have to supervise constantly. Start with the one question your team answers most often this week, and let the agent draft it.
11

Frequently asked questions

Is this a real AI agent, or just a chatbot?
It is a small but real agent. It becomes an agent because the model decides whether to call the FAQ tool, what to search for, and whether a human is needed. A chatbot would answer in one step with no tool and no decision. It is intentionally not fully autonomous, because a person reviews anything uncertain.
Do I need to know how to code to build an AI agent in n8n?
No. You paste one short snippet for the FAQ tool and change a sample question. Everything else is clicking and filling in fields. You can swap the code snippet for a no-code tool later once the workflow runs.
Which model should a beginner use for an n8n AI agent?
A hosted model that supports tool calling, such as OpenAI's gpt-4o-mini. It is inexpensive and tool calling works out of the box, which avoids the most common first-build problem. Local models through Ollama also work, but only if the model you pick supports tool calling.
Can I run an n8n AI agent completely free?
You can start on the n8n Cloud free trial and spend only a few cents on model usage. For an ongoing free setup, self-host the Community Edition, which is free software under the Sustainable Use License, and use a local model with Ollama. That removes subscription and API fees, but you then pay with your own server and maintenance time, so it is not truly free.
Why does my n8n agent ignore the FAQ tool?
Usually the model cannot do tool calling, or the tool's description is too vague for the model to know when to use it. Use a tool-capable model, write a specific tool name and description, and instruct the agent to use the tool in its system message.
Why do I get a connection refused error with a local model in n8n?
Almost always a networking mismatch. The word localhost means different things inside Docker, on your own machine, and on n8n Cloud. Use the base URL that matches where n8n runs, bind Ollama to 0.0.0.0, and remember that n8n Cloud runs on n8n's servers and cannot reach a model on your laptop at all.
How long does it take to build a first AI agent in n8n?
About 30 to 60 minutes for a first working version if you use n8n Cloud with a hosted model. Self-hosting with a local model takes longer, mostly because of the networking setup between n8n and the model rather than the agent itself.
Where this goes next

Taking this further than a demo FAQ?

Auriga IT builds AI and automation systems for businesses, including conversational AI, intelligent automation of manual workflows, and integration with existing systems. If you are weighing where an agent would genuinely help in your operations, we are happy to look at one workflow with you.

See our AI services →
Sources

All verified 20 October 2026 against n8n 2.x documentation. Node names and settings reflect the current AI Agent (Tools Agent) node and may change in later versions.

  1. n8n, AI Agent (Tools Agent) node
  2. n8n, What agents do
  3. n8n, Ollama model node common issues
  4. n8n, Pricing
  5. n8n, Sustainable Use License
  6. Ollama, Tool support
  7. Ollama, models with tool support
  8. OpenAI, API pricing

Related content

Stay Close to What We’re Building

Get insights on product engineering, AI, and real-world technology decisions shaping modern businesses.

Suman Yubraj
Suman Yubraj
Suman Yubraj writes Auriga IT's ERP and manufacturing technology content. He works with the delivery teams on ERPNext implementations across agri-commodity, manufacturing and distribution operations, and writes the case studies that document them.
Go to Top