How to Build an AI Agent in n8n: Step-by-Step
n8n AI Agent is a node in n8n’s workflow editor that combines an LLM with tools and memory, so the model can decide which action to run instead of following a fixed path. You drag in an Agent node, attach a chat model, add tool connections, and trigger the whole thing from a chat widget, webhook or schedule. Self-hosted n8n is free; n8n Cloud starts around €20 a month.
That is the whole concept. What follows is the actual build, including the parts that eat an afternoon.
How do you add an AI Agent node to a workflow?
Create a new workflow, press the plus button, search “AI Agent”, and drop it on the canvas. The node needs three types of connection: a Chat Model (OpenAI, Anthropic, Google, or a local Ollama endpoint), optionally a Memory node, and one or more Tool nodes.
Connect the model in the node’s panel under “Chat Model.” If you use OpenAI, paste your API key into a credential — do not hardcode it in the node. Then attach memory: Simple Memory is fine for testing, Postgres or Redis for anything real.
What tools can the agent actually call?
The built-in tool set is the reason to use n8n instead of a plain API call. You can give the agent:
- HTTP Request tool — hits any REST endpoint, the escape hatch for everything else.
- Google Sheets / Gmail / Slack tools — read a row, send a mail, post a message.
- n8n workflow tool — call another workflow as a sub-function.
- Calculator and Code tools — arithmetic and a JS sandbox, which reduces hallucinated numbers.
- Vector store / retriever nodes — RAG over your own documents.
Keep the tool count low. Every tool you attach adds its description to the prompt, and past roughly eight to ten tools the model starts choosing badly. Two focused agents beat one agent with twelve tools.
How do you trigger the agent and test it?
Attach a Chat Trigger node for the in-editor chat panel — that is the fastest way to test. It gives you a chat window inside n8n; type and watch each step execute on the canvas.
For production, swap in a Webhook trigger and point your front end at the URL. Add a Schedule trigger if the agent should run on a cron instead.
One setting to change immediately: the Agent node’s system message. Default prompts produce chatty answers. Write explicit instructions about length, tone and when to use which tool.
Is n8n AI Agent free, and what do runs cost?
n8n itself is free if you self-host (fair-code licence, free for internal business use). Cloud plans start around €20/month. Your real cost is tokens: a single agent turn that calls two tools and loops once can burn 3,000-8,000 tokens depending on the system prompt size.
Multi-step agents are not cheap. A daily report agent that runs 20 times with four tool calls each, on GPT-4 class models, can cost more than the n8n subscription. Cheaper models plus tight prompts fix most of it.
Who is this for, and what breaks?
It fits developers and technical ops people who already run cron jobs or Zapier substitutes and want the logic to be model-driven. It does not fit non-technical users — the debugging is visual but the bugs are not.
Common failures: the agent loops on the same tool, the memory node loses context between sessions, and webhook timeouts kill long agent runs. All three are fixable, none are obvious.
Quick Summary
- n8n AI Agent = Chat Model + tools + memory, configured on a canvas.
- Self-hosted n8n is free; n8n Cloud is roughly €20/month and up.
- Keep tools under eight; each adds prompt overhead and choice error.
- Test with Chat Trigger, ship with Webhook trigger.
- Real cost is tokens, not the licence — 3,000-8,000 tokens per multi-step turn.
Node-by-node feature detail lives on the n8n AI Agent tool page.
