n8n AI Agent Node Tutorial: Build Your First Agent in 9 Steps
Quick answer
The n8n AI Agent node lets a large language model reason across multiple steps, call external tools like HubSpot or Gmail, and stop when a task is complete — unlike a basic prompt node that returns a single response. SMB teams can build a working lead-qualification or support-triage agent in nine steps without writing code, using n8n v1.22 or later.
Building an AI agent in n8n is one of the highest-leverage moves a small business can make right now. This tutorial walks you through every configuration step — from connecting a language model to writing a system prompt that actually controls agent behaviour. Follow the nine steps below and you will have a working agent by the end of this page.
What the n8n AI Agent Node Actually Does (and Why SMBs Should Care)
The n8n AI Agent node gives a large language model the ability to decide which tools to call, in what order, and when to stop — unlike a basic prompt node that simply returns a single block of text. The agent runs a REACT loop: Reason about the goal, Act by calling a tool, Observe the result, then repeat until the task is complete or a stopping condition is met.
A standard n8n LLM node handles one-shot generation. You send a prompt, you get a response. The AI Agent node is different. The agent can call five tools in sequence, evaluate each result, and change course mid-run without any extra logic from you. That distinction matters enormously for real business tasks. A five-person ops team can use this node to automate lead qualification, invoice chasing, or support triage — no developer required. The agent can connect to tools including Google Search Console, HubSpot, Slack, Gmail, and any custom HTTP endpoint your business already uses. For a broader look at what n8n can do across your operations, explore the LEVRYO automation resource hub.
Step 1 — Prerequisites: What to Set Up Before You Open n8n
Before building anything, confirm you are running n8n v1.22 or later — the AI Agent node is not available in earlier versions. Check your version in Settings → About inside the n8n interface.
Next, obtain an API key from your chosen language model provider. OpenAI is the most common starting point; Anthropic and Google Gemini are solid alternatives. Whichever provider you choose, locate the usage limits dashboard before you start building — cost overruns during testing are avoidable if you set a monthly cap upfront. On the infrastructure side, decide between n8n Cloud and self-hosted. Cloud removes the DevOps burden entirely, which suits most SMBs with no dedicated technical staff. Self-hosted gives you data-residency control if your industry requires it. Either way, create your LLM credential inside n8n before you open the workflow canvas. Creating credentials mid-build is the most common cause of unexplained save errors that new users report. Finally, set up a test Slack channel or a dedicated Gmail label as your output destination during testing. Pointing the agent at a safe sandbox means live customer data is never touched while you are still iterating on the configuration.
Step 2 — Create a New Workflow and Add the AI Agent Node
Navigate to Workflows → New and give the workflow a descriptive name immediately — something like "Lead Qualifier Agent" rather than "My Workflow 3." Vague names create real confusion once you are managing five or more agents.
Click the + button on the canvas, type "AI Agent" in the search bar, and select the node. You will see two similar options in the panel: Agent and Basic LLM Chain. The Basic LLM Chain is a single-shot prompt node. The Agent node is what you want — it supports tool calling and the REACT reasoning loop described above. Once the node opens, you will see four configuration tabs: Model (the language model powering the agent), Memory (conversation history storage), Tools (external actions the agent can take), and Output Parser (how the agent formats its final response). Throughout this tutorial, the LEVRYO Agent Blueprint maps these tabs to a three-layer mental model: Brain (Model tab), Memory (Memory tab), and Hands (Tools tab). Keep that framework in mind — every setting you touch belongs to one of those three layers. Save the empty workflow with Ctrl+S before touching credentials. n8n does not auto-save, and a browser crash at this stage loses everything.
Step 3 — Connect a Language Model (The Agent's Brain)
Inside the Model tab, click Connect Model and add an OpenAI Chat Model sub-node. For reasoning-heavy tasks like lead qualification or multi-step data lookup, select gpt-4o. For high-volume, cost-sensitive tasks where speed matters more than nuance, gpt-3.5-turbo is the better choice.
Attach the OpenAI credential you created in Step 1. Credentials in n8n are workspace-scoped, meaning the same API key works across every workflow in your account — you will not need to re-enter it. Set Temperature to 0 for deterministic business logic such as invoice chasing or structured data extraction. Use 0.7 for creative tasks like email drafting or content generation. One practitioner detail that official documentation examples consistently omit: set Max Tokens to 1000 as a hard ceiling on agent responses. Leaving Max Tokens unlimited is the primary cause of runaway API costs when an agent enters an unexpected loop and keeps generating output. A 1000-token cap stops that before it becomes expensive. If OpenAI rate limits become a constraint at volume, Anthropic Claude 3 and Google Gemini are available as drop-in alternatives through their own n8n credential nodes — the rest of your workflow configuration stays unchanged. See the n8n official AI Agent node documentation for a full list of supported model providers.
Step 4 — Add Memory So the Agent Remembers Context
Under the Memory tab, connect a Window Buffer Memory sub-node. This stores the last N conversation turns in memory so the agent does not repeat questions it already asked earlier in the same session.
Set Window Size to 10 for support-ticket agents that need to track a full customer conversation. Set it to 4 for quick lookup agents where each run is largely independent — smaller windows consume fewer tokens per execution and keep costs lower. The most important setting in this tab is the session key. Use a dynamic value like {{ $json.userId }} so each customer or lead gets a completely isolated memory context. A static session key — one that never changes — means every user shares the same memory. That is the single most common and least-documented mistake SMB teams make with n8n agents: one customer's data bleeds into the next customer's conversation, producing responses that look like hallucinations but are actually context contamination. For stateless workflows such as batch invoice processing, disable memory entirely. The agent runs faster and cheaper when it does not load prior context on every execution. Review the n8n Window Buffer Memory documentation for all available session key options.
Step 5 — Give the Agent Tools (Its Hands)
Tools are the sub-nodes the agent can call autonomously during a run. Add them under the Tools tab. Each tool requires a clear name and a plain-language description, because the language model reads those descriptions to decide when and whether to use each tool.
Three tools cover the majority of SMB use cases. An HTTP Request tool lets the agent call any REST API your business already uses. An n8n Workflow tool triggers a separate sub-workflow, which is useful for complex multi-step operations you want to keep modular. A Code tool runs JavaScript directly inside the agent loop — useful for calculations or string transformations that no built-in node handles cleanly. Naming discipline matters more than most tutorials acknowledge. A tool named "Get CRM Contact" performs measurably better than one named "Tool 1" because the model's routing accuracy depends on understanding what each tool does from its label alone. Worked example: an SMB connects a HubSpot HTTP tool and a Gmail tool. The agent pulls a lead's deal stage from HubSpot, evaluates it against a qualification threshold, and sends a personalised follow-up email via Gmail — all in a single run, saving a sales rep roughly 45 minutes per day. Keep your tool count between five and seven. Beyond that range, the model's tool-selection accuracy drops and execution latency increases noticeably.
Step 6 — Write a System Prompt That Controls Agent Behaviour
The System Prompt is the agent's standing instruction set. Access it in the Agent node's main settings panel under System Message. A well-written system prompt is the difference between an agent that stays on task and one that wanders into unrelated territory.
Use the LEVRYO Prompt Stack structure: Role → Constraints → Output Format → Escalation Rule. Each layer prevents a specific failure mode. The Role line defines what the agent is and what it does: "You are a lead qualification assistant for a B2B SaaS company. Your only job is to assess inbound leads using the BANT framework." Constraints prevent scope creep: "Do not answer questions outside lead qualification. If asked, reply: I can only help with lead assessment." Output Format tells the agent exactly how to structure its final response — JSON, a bullet list, or a plain sentence — so downstream nodes can parse it reliably. The Escalation Rule is the most important layer for cost control: "If you cannot complete the task in 3 tool calls, output JSON: {escalate: true, reason: <string>} and stop." That single line prevents infinite loops that burn API budget while the agent retries a failing tool call indefinitely.
Which n8n Agent Configuration Fits Your Use Case: A Decision Table
Not every SMB use case needs the same configuration. The table below maps five common agent applications to their optimal settings across five dimensions. Use the Complexity column to gauge whether your team can build and maintain each type without outside help.
| Use Case | Memory | Tools Needed | Recommended Model | Complexity | Comparable Alternative |
|---|---|---|---|---|---|
| Lead Qualification | Yes (Window: 4) | 2–3 (CRM, Email, HTTP) | GPT-4o | Intermediate | Zapier AI Actions |
| Customer Support Triage | Yes (Window: 10) | 3–5 (Helpdesk, Slack, KB search) | GPT-4o | Advanced | Make.com AI modules |
| Invoice Chasing | No | 2 (Accounting API, Email) | GPT-3.5-turbo | Beginner | Zapier AI Actions |
| Content Drafting | No | 1–2 (HTTP, Code) | GPT-4o | Beginner | Make.com AI modules |
| Internal Data Lookup | Yes (Window: 4) | 2–3 (Database, HTTP, Code) | GPT-3.5-turbo | Intermediate | Zapier AI Actions |
One qualitative rule applies across all rows: if your use case requires more than three sequential decisions — branching based on what a previous tool returned — the n8n AI Agent node outperforms static Zapier Zaps because branching logic is handled natively by the REACT loop rather than requiring separate conditional branches you have to build and maintain manually.
Steps 7–9: Test, Handle Errors, and Deploy
Step 7 — Test With Real but Safe Data
Run the agent using the Test Workflow button, not a live trigger. Feed it a real lead record or a real invoice — but route output to your test Slack channel or Gmail label from Step 1. Watch the execution log on the right panel. Each tool call appears as a separate step, so you can see exactly where the agent succeeded or stalled.
Step 8 — Handle Errors and Set Max Iterations
Open the Agent node settings and locate Max Iterations (default: 10). Lower this to 5 for simple agents — fewer iterations mean lower worst-case cost per run. Add an Error Trigger node connected to the agent's error output. Route failed runs to a Slack alert or a Google Sheet log so nothing fails silently. The escalation rule in your system prompt acts as a first safeguard; Max Iterations is the hard backstop.
Step 9 — Activate and Monitor
Switch the workflow from inactive to active using the toggle in the top-right corner. Set a trigger — a Webhook for real-time events, a Schedule trigger for batch runs, or an app trigger like a new HubSpot contact. Monitor execution history under Executions in the left sidebar for the first 48 hours. Check token usage in your LLM provider's dashboard daily until you have a reliable baseline cost per run.
- Confirm Max Tokens is set to 1000 on the model sub-node
- Confirm session key is dynamic, not static
- Confirm each tool has a descriptive name and description
- Confirm the system prompt includes an escalation rule
- Confirm error output is routed to a Slack alert or log sheet
Frequently Asked Questions About the n8n AI Agent Node
Do I need coding skills to build an n8n AI agent node workflow?
No coding is required for most SMB agent workflows. n8n's visual canvas handles all connections between nodes through drag-and-drop. The only optional coding surface is the Code tool sub-node, which accepts JavaScript — but you can skip it entirely by using HTTP Request nodes or built-in app integrations to achieve the same result without writing a single line.
How much does running an n8n AI agent cost per month?
Costs split into two parts. n8n Cloud starts at $20 per month for 2,500 workflow executions — see the n8n pricing page for current plan details. LLM API costs depend on model and volume. A lead-qualification agent using GPT-4o typically costs between $0.01 and $0.05 per run, so 1,000 runs per month adds roughly $10–$50 in OpenAI charges on top of your n8n subscription.
What happens if the n8n AI agent gets stuck in an infinite loop?
The n8n AI Agent node includes a built-in Max Iterations setting, defaulting to 10 iterations per run. When the agent hits that limit, the node returns an error output that you can route to a Slack alert or log to a Google Sheet. Always pair this with an escalation rule in your system prompt as a second safeguard — the prompt-level rule fires before Max Iterations is reached.
How does n8n AI agent compare to Zapier AI Actions for SMBs?
Zapier AI Actions suits simple, single-step AI tasks embedded in a linear Zap. n8n's AI Agent node handles multi-step reasoning, tool chaining, and conditional branching logic natively inside one node. For workflows requiring more than two sequential decisions, n8n provides significantly more control and flexibility without requiring a developer to maintain separate conditional branches.
Is my business data safe when using the n8n AI agent node with OpenAI?
Data sent to OpenAI via the API is not used for model training by default under OpenAI's API data usage policy. For stricter data-residency requirements, self-host n8n and route requests to a local LLM such as Ollama — all data stays within your own infrastructure and never leaves your network.
Can one n8n AI agent workflow handle hundreds of simultaneous runs?
Both n8n Cloud and self-hosted instances support concurrent executions, but the default concurrency limit varies by plan. On self-hosted n8n, operators can raise the concurrency ceiling through environment variables. At high volume, the binding constraint is typically the rate limit imposed by your LLM provider — OpenAI and Anthropic both publish their rate tiers, and upgrading your API tier is usually the first scaling lever to pull.