Build Your First AI Agent in n8n (2026)


If you can drag boxes onto a canvas, you can build an AI agent in n8n — no JavaScript required. This beginner tutorial walks through the full build, from the Chat Trigger to publishing, using only what n8n’s official documentation says. If you’re still deciding whether n8n is the right tool, start with the n8n getting started guide or the n8n vs Zapier vs Make comparison.

How This Guide Was Built

This guide is a desk-research tutorial assembled from n8n’s official documentation so you know exactly what it does and doesn’t cover. This tutorial is based on n8n’s official documentation and pricing pages, fetched on 2026-09-30 — no n8n instance was installed, no workflow was built, and no agent was run for this article. Every node name, parameter, and price below comes from the n8n docs on building AI or the n8n pricing page, and each section links its source so you can verify before you build.

What You’ll Build

You will build a chat-based AI agent that answers questions, remembers the conversation, and calls tools to fetch data on demand. In n8n’s AI architecture, described in the LangChain integration docs, a root node like the AI Agent sits at the center with sub-nodes attached: a chat model, memory, and tools. Your finished canvas will wire a Chat Trigger to an AI Agent with an OpenAI Chat Model, Simple Memory, an HTTP Request tool, and a Call n8n Workflow Tool. If you’d rather start from a template, the n8n workflow library includes “Build your first AI agent” (workflow 6270) among its 12,795 community templates.

Prerequisites: Account, Plan, and Model Access

Before building, you need an n8n account with enough executions and a way to reach an AI model. The n8n free trial gives you $0 for a 14-day free trial with 1,000 executions and no credit card required, per the n8n pricing page. On n8n Cloud you can skip provider API keys entirely by using Gateway credits on the OpenAI Chat Model or Google Gemini Chat Model — available on Starter and Pro from n8n 2.36.0. Self-hosters can install the free Community Edition with curl -fsSL https://get.n8n.io | sh per the hosting docs.

Step 1: Add the Chat Trigger

Every chatbot workflow starts with the Chat Trigger, the node that receives user messages and starts the workflow. Per the Chat Trigger documentation, it’s available from n8n 1.24.0 and offers Make Chat Publicly Available, a Mode of Hosted Chat or Embedded Chat, and auth options of None, Basic Auth, or n8n User Auth. Set an Initial Message(s) greeting (Hosted Chat only) and pick a Response Mode such as When Last Node Finishes. Note the billing catch: a 10-message conversation uses 10 executions.

Step 2: Add the AI Agent Root Node and a Model

The AI Agent root node is the brain that decides which tools to call to complete a task. The AI Agent docs state you must connect at least one tool sub-node, so add a model first: attach an OpenAI Chat Model or Google Gemini Chat Model sub-node, both of which support Gateway credits on Cloud (OpenAI docs, Gemini docs). OpenAI’s Built-in Tools (Web Search, File Search, Code Interpreter) only work with the AI Agent node, not a Basic LLM Chain.

Step 3: Attach Simple Memory

Simple Memory gives your agent conversational recall so it can reference what was said earlier. The Simple Memory docs describe it as a buffer that persists chat history, configured with a Session Key and Context Window Length. Two rules matter: memory sub-nodes only attach to the AI Agent root node (LangChain docs), and for Load Previous Session to work, n8n recommends connecting BOTH the Chat Trigger and the Agent to the same memory sub-node.

Step 4: Add the HTTP Request Tool

The HTTP Request node becomes a tool when you attach it to the agent, letting the model call any REST API. The HTTP Request docs cover Method (GET, POST, PATCH, DELETE, and more), URL, Authentication (prefer Predefined Credential Type), query parameters, headers, body, Import cURL, and a Pagination option. Describe the endpoint clearly in the tool’s description so the agent knows when to call it — the model reads that description to decide.

Step 5: Add the Call n8n Workflow Tool

The Call n8n Workflow Tool lets your agent run another n8n workflow and fetch its output, which is how you give the agent complex capabilities without cluttering the canvas. Per the tool’s documentation, you set a Description (tells the agent when to use it), a Source of Database or Define Below, and Workflow Inputs with a Refresh button. A common pattern is a sub-workflow that queries a database — the template library’s “Chat with a database using AI” shows the shape of this. Publish the sub-workflow before going live (see troubleshooting below).

Step 6: Let the Model Fill Parameters with $fromAI()

$fromAI() is an expression that lets the AI model fill in a tool’s parameters at runtime instead of you hardcoding values. The official guide shows the form {{ $fromAI('key') }} with an optional description, type (string/number/boolean/json), and defaultValue, e.g. $fromAI("name", "The commenter's name", "string", "Jane Doe"). Keys are 1-64 characters. It only works for tools connected to the AI Agent node — not the Code tool or non-tool sub-nodes.

Step 7: Test the Agent

Testing means chatting with your agent in the editor and checking that it picks the right tools and remembers context. n8n’s test-and-improve docs recommend quick evaluations against known test cases during development, and metrics that score production quality over time. Send messages that should trigger each tool, ask follow-ups that depend on earlier turns, and watch each execution’s node-by-node input and output. If a tool call fails, the agent receives the error as the tool’s result — read it before changing anything.

Troubleshooting

  • Workflow is not active and cannot be executed — the sub-workflow behind a Call n8n Workflow Tool (Database source) isn’t published in production. Publish it; the error is returned to the agent as the tool result.
  • Memory gaps in queue mode — Simple Memory may not hit the same worker in queue mode, so use Postgres Chat Memory or Redis Chat Memory instead.
  • Chat-Trigger cost surprise — a 10-message conversation = 10 executions. Estimate weekly conversations × messages per conversation before choosing a plan.

Step 8: Publish the Agent

Publishing means activating the workflow and sharing the chat so real users can reach it. With Make Chat Publicly Available on the Chat Trigger, you get a Hosted Chat link or Embedded Chat snippet for your site (the embed uses @n8n/chat on npm); protect it with Basic Auth or n8n User Auth if it’s public. Remember billing: every message is one execution, and the pricing page defines an execution as a single run of your entire workflow regardless of step count.

AI Agent vs. Basic LLM Chain

n8n offers two AI root nodes, and choosing wrong limits what your workflow can do. The AI Agent (docs) decides which tools to call autonomously, while the Basic LLM Chain (docs) just runs a prompt with an optional output parser — and no n8n chain node supports memory (source). Use the chain for single-shot tasks like summarizing; use the agent when tools or memory are involved.

Feature AI Agent Basic LLM Chain
Autonomy Decides its own steps and tool calls Single prompt → response
Tool calling Yes, required (≥1 tool sub-node) No
Memory Yes, via memory sub-nodes Not supported
Use when Multi-step tasks needing tools or context One-shot text generation

The Bottom Line

Building your first AI agent in n8n is an afternoon project: a Chat Trigger, an AI Agent with a model, Simple Memory, and one or two tools. Start on the 14-day free trial (1,000 executions), prototype with Gateway credits, and upgrade to Starter $20/mo (2.5K executions) or Pro $50/mo (10K executions) only when your execution math says so (pricing). Self-hosters get the Community Edition free — n8n shows 206,323 GitHub stars (repo) — and can extend agents through MCP servers or the MCP Client Tool (modelcontextprotocol.io). For a deeper conceptual primer, see n8n’s AI agents post, and for tool selection read the Make vs Zapier comparison.

FAQ

These are the questions beginners hit most often when building their first n8n agent: how executions are counted, whether you need your own model key, what a common tool error means, and how conversational memory actually works. Each answer is self-contained and sourced to n8n’s official documentation so you can verify it before you build.

How many executions does my chatbot use?

Per the Chat Trigger docs, every message to the Chat Trigger executes your workflow — one conversation where a user sends 10 messages uses 10 executions. Multiply your expected weekly conversations by average messages per conversation, then compare against plan limits on the n8n pricing page.

Do I need my own OpenAI or Gemini key?

Not on n8n Cloud Starter or Pro: the OpenAI Chat Model and Google Gemini Chat Model both support Use Gateway credits, letting you use supported models without provider accounts or API keys (Gateway credits docs). Gateway credits are separate from Assistant credits and aren’t available on Enterprise or self-hosted, where you’d supply your own keys.

Why do I get “Workflow is not active and cannot be executed”?

This error means the sub-workflow behind a Call n8n Workflow Tool (Database source) isn’t published in production. Per the tool docs, the call fails and the error is returned to the agent as the tool result — so publish the sub-workflow and retry the conversation.

Can the agent see earlier messages?

Yes, if you attach a memory sub-node: Simple Memory persists chat history with a Session Key and Context Window Length (docs). For Load Previous Session, connect the Chat Trigger and the Agent to the same memory sub-node. A Basic LLM Chain can’t do this — no chain node supports memory.

  • NiteAgent — AI agent development, frameworks, and production patterns
  • ToolBrain — tool reviews, LLM comparisons, and AI workflow guides
  • Hermes Tutorials — Hermes Agent setup, configuration, and advanced workflows

Cross-links automatically generated from NoCode Insider.