Hosto

Sign In

Building AI Agent Workflows in n8n: A Practical Introduction

By Tushar Khatri

White robotic hand extended open, palm up, in a bright clean room

If you have spent any time in automation communities lately, you have seen the phrase "n8n AI agent" everywhere. It sounds like hype, but underneath it is a genuinely useful pattern: instead of hardcoding every step of a workflow, you give a language model a goal, a set of tools, and some memory, and let it decide how to get the job done. n8n is one of the most practical places to build this because its AI Agent node, chat models, and tool connections are visual, inspectable, and self-hostable.

This guide covers what an AI agent actually is, how n8n's building blocks fit together, and three concrete builds at increasing depth, plus the two things most tutorials skip: real costs and safety.

What Is an AI Agent, and How Is It Different from a Plain LLM Call?

A plain LLM call is a single round trip. You send a prompt, the model sends back text, and the workflow moves on. That is perfect for classification, summarization, or drafting, where the task is fully described up front.

An agent is a loop. The core recipe is:

Agent = model + tools + memory, in a loop where the model decides which tool to call next.

Here is the loop in practice:

  1. The agent receives a task, for example "How many orders came in today?"
  2. The model picks a tool, say a database lookup.
  3. n8n executes that tool and feeds the result back to the model.
  4. The model decides whether it has enough information. If not, it calls another tool. If yes, it answers.

The key difference is control flow. In a normal workflow, you draw the arrows. In an agent workflow, the model draws them at runtime, within the boundaries of the tools you attached. That flexibility is why agents can handle open-ended requests, and also why they need guardrails.

n8n AI Workflows: The Building Blocks

n8n's AI capabilities live in a cluster of LangChain-based nodes. You do not need to know LangChain to use them; under the hood, n8n orchestrates a LangChain agent loop. Four pieces matter:

The AI Agent node

The orchestrator. You drop it into a workflow, give it a system message describing the agent's role and constraints, and connect the other components to it. The node exposes settings like the maximum number of iterations, which caps how many times the loop can run. Always set this deliberately.

A chat model

The agent needs a brain. n8n ships dedicated chat model nodes for the major providers: the OpenAI Chat Model, Anthropic Chat Model, and Google Gemini Chat Model nodes, among others. You attach one to the AI Agent node's model input and configure credentials. Swapping providers later is as simple as swapping the connected node.

Tools

Tools are what separate an agent from a chatbot. In n8n, you attach tools directly to the AI Agent node, and the model invokes them by name. Two of the most useful:

  • HTTP Request tool: lets the agent call any API. You define the endpoint and parameters, and write a short description so the model knows when to use it.
  • Workflow tools: let the agent call another n8n workflow as a tool. This is the pattern that scales: each sub-workflow does one job well (look up an order, search a knowledge base, create a ticket), and the agent composes them.

Many regular n8n integrations can also be attached as tools, so the agent can read a Google Sheet or post to Slack without glue code.

Memory

Without memory, every message starts from zero. n8n's window buffer memory (shown as Simple Memory in recent versions) keeps the last N exchanges in context, so the agent remembers what "that order" refers to two messages later. Key it to the session so different users do not share context.

Finally, the Chat Trigger node gives you a ready-made chat interface, so you can talk to your agent without building a frontend.

Build 1: A Support Inbox Triage Agent

The best first agent, because a human stays in the loop the whole time.

Goal: classify incoming support emails, draft a reply, and hold it for approval.

The build:

  1. Trigger: a Gmail or IMAP trigger fires on each new message in the support inbox.
  2. AI Agent node: the system message says it is a support triage assistant that classifies each email (billing, technical, refund request, spam) and drafts a reply in your brand voice.
  3. Tools: attach a workflow tool that searches your help docs, so drafts cite real answers instead of inventing policy.
  4. Approval: route the draft to Slack or email for a human to approve or edit.
  5. Send: only after approval does the email node send the reply.

The agent never sends anything itself. It classifies and drafts, a human approves, and a deterministic step sends. This division of labor, model for judgment and workflow for actions, is the safest way to start, and it still saves real time: urgent tickets surface first, and a grounded draft turns a five-minute reply into a thirty-second review.

Build 2: A Research Agent with the HTTP Request Tool

Now let the agent fetch information on its own.

Goal: given a topic or a list of URLs, gather content, synthesize a briefing, and post it to Slack.

The build:

  1. Trigger: a Chat Trigger for on-demand requests, or a Schedule Trigger for a recurring briefing.
  2. AI Agent node: the system message defines the output, for example "Produce a briefing with a three-sentence summary, key facts, and open questions, citing which source each fact came from."
  3. HTTP Request tool: attached with a description like "Fetches the content of a web page. Provide a full URL." The agent decides which URLs to fetch and in what order.
  4. Memory: window buffer memory so a follow-up like "go deeper on the second source" works.
  5. Output: the final answer flows into a Slack node that posts to your research channel.

The interesting behavior here is iteration. The agent may fetch one page, notice it links to a better source, fetch that too, and synthesize both. You did not program that sequence. You gave it a fetch tool and a goal.

Two tips: set max iterations to something like 5 to 8 so a rabbit hole cannot run forever, and keep tool descriptions specific. Vague descriptions are the top cause of agents calling the wrong tool.

Build 3: An Ecommerce Ops Agent

The deepest build: an agent that answers questions from live store data.

Goal: let your team ask "How many orders came in today?", "What is our best seller this week?", or "Any orders stuck in processing?" and get accurate answers in chat.

The build:

  1. Trigger: a Chat Trigger, so the team gets a conversational interface.
  2. AI Agent node: the system message describes the store, the available data, and hard rules such as "Only report data returned by tools. If a tool returns nothing, say so. Never estimate numbers."
  3. Workflow tools, one per question type:
    • get_orders: queries your store API (Shopify, WooCommerce, or your database) with date and status filters, returning a compact summary.
    • get_product_stats: returns top sellers and stock levels for a date range.
    • lookup_order: takes an order ID and returns its status history.
  4. Memory: session-scoped window buffer memory, so "and yesterday?" is understood as a follow-up.

The decision that makes or breaks this build is doing aggregation in the sub-workflows, not in the model. Do not hand the agent 2,000 raw order records and hope it counts correctly. Have get_orders return "142 orders today, 3 in processing over 24 hours, total revenue $8,410" and let the model interpret the question and present the answer. Deterministic math in the workflow, language in the model.

Once this works, pair it with event-driven flows from our guide to 10 store automations: the agent handles ad hoc questions while conventional workflows handle the predictable, repetitive work.

What Agents Actually Cost, and How to Keep Them Safe

Two caveats before you ship anything.

Costs. n8n does not charge for AI usage, but your model provider does, per token, on a separate bill. Agents multiply token usage because every loop iteration resends the conversation, tool definitions, and accumulated tool results, so one agent run can easily consume many times the tokens of a plain LLM call. Keep it in check by setting max iterations on every agent, keeping tool outputs compact (summaries, not raw dumps), trimming memory windows, and using cheaper models for simple agents.

Safety. Never give an agent destructive tools without a human approval step. Read-only tools like fetching pages, querying orders, and searching docs are low risk. Tools that send emails, issue refunds, modify inventory, or delete anything should be excluded entirely or gated behind explicit human approval, exactly like the triage build. Write the boundary into the system message too, but do not rely on the prompt alone. The reliable guardrail is which tools you attach and where you place approval steps.

Why Self-Hosted n8n Fits Agent Workloads

Agents change the economics of where you run n8n. A chat agent fires an execution per message, a scheduled research agent runs all day, and sub-workflow tools mean one conversation can trigger a dozen executions. Agents poll and loop constantly, and per-execution cloud pricing meters every one of them. This is a big part of the calculus in our n8n vs Zapier vs Make comparison: task-metered pricing punishes exactly the chatty, iterative behavior that makes agents useful.

Self-hosting removes the meter. On a flat-rate dedicated VM, like Hosto n8n hosting from $9 per month billed annually, executions are unlimited, so an agent that loops fifty times costs the same as one that runs once. You still pay your LLM provider per token, but orchestration stops being a variable cost.

There is a second reason: privacy. Agents routinely touch customer emails, order histories, and internal documents. On a dedicated instance from Hosto or your own server, that data flows through infrastructure you control, which makes compliance conversations far simpler.

FAQ

What is the difference between the AI Agent node and a regular OpenAI node in n8n?

A regular model node makes one call: prompt in, text out. The AI Agent node runs a loop in which the model calls attached tools, reads the results, and decides its next step before answering. Use a plain model node for fixed tasks, and the AI Agent node when the path to the answer depends on what the data says.

Which chat model should I use for n8n AI agents?

n8n has dedicated chat model nodes for OpenAI, Anthropic, and Google Gemini, so you can swap providers without rebuilding the workflow. Start with a mid-tier model, test against real tasks, and upgrade only if the agent misuses tools or reasons poorly. Simple triage agents rarely need the most expensive model.

Do AI agents in n8n cost extra to run?

n8n itself does not bill for AI features, but the model provider bills per token, and agent loops consume far more tokens than single calls. On n8n Cloud, each execution also counts against your plan. Cap costs with max iterations, compact tool outputs, and, if volume grows, a flat-rate self-hosted instance.

Are n8n AI agents safe to connect to production systems?

Yes, if you control the blast radius. Attach read-only tools freely, but gate anything that writes, sends, refunds, or deletes behind a human approval step. The tools you attach are the real permission system: an agent cannot call a tool it does not have, so start with the minimum set and expand as it earns trust.

Start with the triage build this week. One trigger, one agent, one approval step: an afternoon of building teaches more about n8n AI workflows than a month of reading.

Host it without the ops.

WordPress, WooCommerce, static sites, and dedicated n8n VMs. Same price at renewal, live in minutes.