n8n AI Agent Tutorial: How to Build One with Tools
A step-by-step guide to building a working AI agent in n8n, using an LLM node, tools, and triggers. And the honest moment when n8n hits its ceiling and you need custom code.

An n8n AI agent is a workflow in which a language model decides which tools to call, and in what order, until it has an answer. n8n gives you that loop as a single node, so a working agent is a handful of nodes on a canvas. This tutorial builds one step by step, the way we built and tested ours in November 2026, and then names the moment n8n stops being the right tool and a custom build has to take over.
What You Need Before You Start
A running n8n instance, self-hosted or n8n Cloud, on a recent version: since n8n 1.82 every AI Agent node works as a tools agent, which is what this guide uses. You also need an API key for a chat model (OpenAI, Gemini, Anthropic, or OpenRouter, which reaches many models with one key) and credentials for whatever your tools touch. n8n’s official AI agent page lists the supported models, and the quick-start template gives you a skeleton to import.
How to Build an AI Agent with n8n: The Core Workflow
An n8n AI agent is one root node with sub-nodes plugged into it: a trigger starts it, the AI Agent node runs the loop, and a chat model, a memory and one or more tools hang underneath. The agent sends the conversation to the model, the model picks a tool, n8n runs it and hands back the result, and the loop repeats until the model has an answer. That's the entire pattern. If you'd rather start from a working one, import our n8n agent template. Here's how to assemble it.
- Add a trigger. For a chatbot, use the Chat Trigger: it gives you an Open chat button in the editor, and it can be made public as a hosted chat page. To call the agent from your own app, use a Webhook node instead and send the user's message in the request.
- Add the AI Agent node and connect it to the trigger. With a Chat Trigger it picks up the message by itself: the prompt source "Take from previous node automatically" expects a field called chatInput. With a webhook, set the prompt source to "Define below" and map the message in.
- Plug in a chat model. Click the Chat Model connector under the agent and pick a model node, for example OpenAI Chat Model or OpenRouter Chat Model. A small, cheap model handles tool calling well; our template uses DeepSeek V4 Flash through OpenRouter.
- Add memory. Attach a Simple Memory sub-node so the agent remembers the conversation; its Context Window Length sets how many past interactions it keeps. Simple Memory does not work in queue mode, so on a scaled n8n use a database-backed memory such as Postgres or Redis instead.
- Give it tools. Every agent needs at least one. Many n8n app nodes can be added as tools (Google Sheets, Gmail, HTTP Request and more), and inside a tool you can let the model fill a field with $fromAI(), for example $fromAI('to', 'The recipient email address', 'string'). Give each tool a one-line description: the model reads it to decide when to call it.
- Write the system message. Under the agent’s options, the System Message tells the model what it is for and what each tool is for. Keep it specific; vague instructions are where agents start guessing. There is an example below the steps.
- Test it. Click Open chat and ask something that needs a tool. The execution log shows each model call and each tool run, which is the fastest way to see why an agent did what it did.
The system message from step 6, shortened from the one in our template:
You are an assistant for a small team. You have three tools:
- The sheet tool reads the team's Google Sheet. Use it for any
question about that data, and never guess a number.
- The email tool creates a Gmail draft. It never sends anything.
- The web tool looks something up and returns sources.
If a tool fails, say so plainly. Never make up a result.Settings That Keep an n8n AI Agent Safe in Production
- Cap the loop. Max Iterations (default 10) limits how many times the model runs per answer. Lower it for simple agents so a confused one cannot run up a bill; our template uses 8.
- Prefer drafts over sends. Give an email tool the draft action instead of send until you trust it, so a person approves what goes out.
- Tell it to admit failure. One line in the system message ("if a tool fails, say so") stops the agent inventing a result when an API is down.
- Route failures to a person. Set an error workflow on the workflow so a failed run reaches someone, not just the Executions list. On newer n8n versions the error workflow itself must be active.
- Mind streaming. Enable Streaming is on by default and needs a trigger that supports it, such as the Chat Trigger or a Webhook in streaming response mode.
That's it: a working n8n AI agent. The dev.to walkthrough shows a similar build using a Telegram bot trigger: same pattern, different channel. If you'd rather skip the trial runs, you can hire an n8n developer to build and harden it for production.
When n8n Hits Its Ceiling: Three Graduation Points
n8n stops being the right answer the moment you need real-time turn-taking, systematic prompt evaluation, or audit-trailed scoring. These are not hypotheticals; they're the exact scenarios where we've had to move clients to custom stacks. No amount of extra nodes or community plugins will close the gap.
- LiveKit/Realtime voice agents A conversational voice agent requires low-latency, streaming audio I/O and custom turn-taking logic. n8n's trigger-response model is fundamentally request/response — it can't hold an open socket with frame-by-frame audio decisions. You'll need WebRTC and a dedicated media server.
- LangGraph-style orientation engine When you must gate every prompt change through a battery of evaluations — factual accuracy, tone, policy compliance — you need a graph that routes and evaluates deterministically. n8n's visual flow can handle simple branching, but it lacks the fine-grained state management and eval-loop introspection of LangGraph. Users frequently hit this wall, as a Reddit thread on agent struggles confirms: once logic gets complex, debugging becomes a time sink.
- Rubric screeners with 380-case eval sets Imagine an agent that scores candidate interviews across 12 criteria, each requiring an audit trail showing exactly which rubric point triggered a score. That demands per-criterion scoring functions, a structured output schema, and a regression suite to validate against 380 known cases. n8n's nodes can call the LLM, but they offer no native way to version prompts and re-run the entire eval set on every change. Custom code with a pipeline and a test harness is the only safe route.
At these ceilings, a custom build isn't an extravagance — it's engineering necessity. If you're already brushing against them, our custom AI agent development services exist precisely because off-the-shelf tools can't handle the real world beyond their sweet spot.
FAQ
What is the AI Agent node in n8n?
It is the root node that runs an agent loop: it sends the conversation to a chat model, lets the model choose among the tools you connected, runs them, and repeats until there is an answer or Max Iterations is reached. Since n8n 1.82 it always works as a tools agent; the model, memory and tools are sub-nodes you plug into it.
Can I build a production-ready AI agent with n8n?
Yes, for well-scoped agents with clear decision points, n8n is production-capable. It shines when the agent relies on standard LLM calls and simple tool integrations.
What are the limitations of n8n for AI agents?
n8n struggles with real-time voice interactions, complex prompt evaluation chains, and audit-trailed scoring systems. Those scenarios typically require custom code.
When should I switch from n8n to a custom AI agent build?
Move to custom code when you need real-time turn-taking voice, LangGraph-style evaluation gates on every prompt change, or rubric-based screening with per-criterion audits.
If you're already at the ceiling, start a project with us.