n8n AI Agents: Build Agentic Workflows Without Writing Code

Build AI agents in n8n with tool calling, memory, and sub-agents. Step-by-step tutorial with 5 real workflow examples. Free and open-source. 2026 guide.

n8n AI agents turn what was already one of the most powerful open-source automation platforms into a full-featured agent builder. Instead of scripted "if X then Y" workflows, you can now build agents that reason about their inputs, decide which tools to call, remember previous conversations, and delegate tasks to sub-agents — all through n8n's visual drag-and-drop canvas.

What makes n8n's approach different from other no-code AI agent builders is the integration depth. Your AI agent sits inside the same workflow as your non-AI steps — HTTP requests, database queries, Slack messages, Google Sheets updates. The agent doesn't live in a separate "AI sandbox." It's a node in your workflow, connected to everything else.

This guide covers how n8n's AI agent system works, walks through building your first agent, and shows five production-ready patterns you can steal.

New to n8n?

n8n is a free, open-source workflow automation platform with 400+ integrations. You can self-host it (unlimited, free) or use n8n Cloud (from $20/month). If you're comparing platforms, see our no-code AI agent builder comparison.

How n8n AI Agents Work

n8n's AI agent system is built on LangChain under the hood, but you never touch LangChain code. Everything is visual.

The core components are:

🧠

AI Agent Node

The reasoning engine. Takes an input, consults the LLM, decides which tools to call, processes the results, and loops until the task is done. This is where agentic behavior lives.

🔧

Tools

Actions the agent can take: send email, query a database, call an API, search the web, run code, or call a sub-agent. You wire tools to the Agent node visually.

💬

LLM Node

The language model powering the agent's reasoning. Connect OpenAI, Anthropic, Google, OpenRouter, or a local model via Ollama. Swap models without changing your workflow.

📝

Memory

Conversation history that persists across messages within a session. Window Memory (last N messages), Token Buffer Memory (token-limited), or external storage for longer persistence.

The flow works like this: a trigger fires (chat message, webhook, scheduled event, new email) → the input reaches the AI Agent node → the LLM reasons about what to do → it calls tools as needed → loops until the task is complete → returns a result.

The key distinction from regular n8n workflows: the agent decides the execution path at runtime. A regular workflow always follows the same sequence. An agent might call tool A, then tool C, then tool A again — depending on what the LLM sees in the intermediate results.

Setting Up: From Zero to First Agent

Here's the fastest path to a working n8n AI agent.

Step 1: Get n8n Running

Option A: n8n Cloud (easiest) Sign up at n8n.io. You get a managed instance with no server setup. Starter plan is $20/month with 2,500 executions.

Option B: Self-hosted (free, more control) One-click deploy on Railway or Render. Or run locally with Docker:

docker run -it --rm --name n8n -p 5678:5678 -v n8n_data:/home/node/.n8n n8nio/n8n

Open http://localhost:5678 and you're in.

Step 2: Build the Agent Workflow

  1. Add a Chat Trigger node — this gives you a chat interface to interact with your agent during development.
  2. Add an AI Agent node — connect it to the Chat Trigger. This is the brain.
  3. Attach an LLM — click the Agent node, select "OpenAI Chat Model" (or Anthropic, Google, etc.), and enter your API key. Start with gpt-4o-mini for cheap experimentation.
  4. Write a system prompt — this is your agent's instructions. Be specific about its role, capabilities, and constraints.

At this point, you already have a working chatbot. But it can't do anything yet — it can only talk. The power comes from adding tools.

Step 3: Add Tools

This is where n8n shines. Every n8n node can be wired as a tool for the agent. Some examples:

ToolWhat It Doesn8n Node
Search the webAgent can look up current informationSerpAPI / HTTP Request
Send emailAgent drafts and sends email on your behalfGmail / SMTP
Query a databaseAgent reads from or writes to your databasePostgres / MySQL / MongoDB
Update CRMAgent creates or modifies contacts and dealsHubSpot / Salesforce
Post to SlackAgent sends messages to channels or usersSlack
Run codeAgent executes JavaScript or Python for custom logicCode node
Call a sub-agentAgent delegates a subtask to a specialized agentAI Agent Tool node
Access MCP serversAgent uses external MCP tools (GitHub, Jira, etc.)MCP Client Tool node

Each tool gets a name and description that the LLM reads to decide when to use it. Clear, specific descriptions are critical — they're the agent's instruction manual for each tool.

Tool Descriptions Matter

A vague tool description like "sends email" leads to the agent using it at the wrong time. Write: "Sends an email via Gmail. Use this ONLY when the user explicitly asks to send an email and provides a recipient address. Always confirm the recipient and subject before sending." The clearer the description, the more reliable the agent.

Step 4: Add Memory

Without memory, each message is a fresh start — the agent doesn't remember what you said 30 seconds ago.

n8n offers three memory types:

Memory TypeHow It WorksBest For
Window BufferStores the last N messagesQuick chats, simple tasks
Token BufferStores messages up to a token limitLonger conversations with cost control
Postgres/Redis Chat MemoryStores messages externallyProduction agents with session persistence

For most use cases, Window Buffer Memory (last 10–20 messages) is the right starting point. Switch to external storage when you need persistence across browser sessions or server restarts.

Five Production-Ready Agent Patterns

Pattern 1: Email Triage Agent

The workflow: Incoming email trigger → AI Agent decides if the email needs a CRM update, a drafted reply, an internal escalation, or can be archived → takes the appropriate action → logs the decision.

Tools wired to the agent:

  • Gmail (read full thread)
  • HubSpot (look up contact, create/update deal)
  • Gmail (send draft reply)
  • Slack (escalate to #support channel)
  • Google Sheets (log the decision and action taken)

System prompt excerpt: "You are an email triage assistant. For each incoming email, determine the sender's intent and take ONE of these actions: (1) If it's a sales inquiry, look up the sender in HubSpot and create a deal. (2) If it's a support question, draft a helpful reply and send it. (3) If it's urgent or unclear, escalate to Slack. (4) If it's spam or newsletters, archive it. Always log your decision."

Pattern 2: Lead Research & Enrichment Agent

The workflow: New HubSpot contact trigger → AI Agent researches the company (web search, LinkedIn, Crunchbase) → enriches the CRM record → scores the lead → drafts a personalized outreach email.

Why it works: Each step requires judgment. The agent decides which sources to check based on what it finds, adapts the outreach tone to the company size and industry, and can handle missing data gracefully.

Pattern 3: Customer Support Agent with Knowledge Base

The workflow: Chat widget trigger → AI Agent searches your documentation (via vector store or HTTP tool) → generates a response grounded in your actual docs → escalates to human if confidence is low.

Key detail: Use n8n's Supabase Vector Store or Pinecone node to give the agent access to your documentation. The agent retrieves relevant passages and uses them as context for its response — a classic RAG pattern that prevents hallucination.

Pattern 4: Multi-Agent Orchestrator

The workflow: Main orchestrator agent receives a request → delegates to specialist sub-agents (email agent, calendar agent, research agent) → combines results → returns a unified response.

How to build it: Use the AI Agent Tool node. This lets you define a sub-agent (with its own LLM, system prompt, and tools) and expose it as a tool to a parent agent. The parent decides which sub-agent to call based on the request.

Orchestrator Agent
├── Email Sub-Agent (Gmail tools, email-specific prompt)
├── Calendar Sub-Agent (Google Calendar tools, scheduling logic)
├── Research Sub-Agent (SerpAPI, web scraping tools)
└── CRM Sub-Agent (HubSpot/Salesforce tools)

This pattern scales well. Each sub-agent can be developed, tested, and improved independently.

Pattern 5: Webhook-Triggered Agentic API

The workflow: Webhook trigger (receives JSON payload from any external app) → AI Agent processes the request → returns a structured JSON response.

Use case: Turn n8n into an AI-powered API endpoint. External apps send structured requests, the agent reasons about them and responds. No chat interface needed — pure API-to-agent communication. This is how teams integrate n8n agents into existing products without rebuilding their frontend.

MCP Server Support

n8n now supports the Model Context Protocol (MCP), which means your agents can use tools from any MCP server — GitHub, Jira, Linear, Notion, databases, and hundreds more.

Adding an MCP server to your agent:

  1. Add an MCP Client Tool node
  2. Point it at your MCP server URL (or a local npx command)
  3. The agent automatically discovers available tools from the server

This is a significant capability. Instead of building custom n8n integrations for every service, you can tap into the growing MCP ecosystem. If you're interested in the protocol itself, see our guide on context engineering for AI agents.

n8n Cloud vs. Self-Hosted: What to Choose

Factorn8n CloudSelf-Hosted (Community)
CostFrom $20/mo (2,500 executions)Free (you pay for server hosting)
SetupInstant, no server neededDocker/Railway setup required (15 min)
Execution limitsBased on plan tierUnlimited
UpdatesAutomaticManual (but straightforward)
Data privacyData on n8n serversData stays on your infrastructure
AI agent featuresAll features includedAll features included
Best forTeams who want zero ops overheadTeams with data privacy requirements or high volume

For AI agent workloads specifically: self-hosted tends to win on cost because LLM-heavy workflows can rack up executions quickly. A single agent conversation might trigger 5–10 executions (one per tool call). At scale, the execution-based pricing on Cloud plans adds up.

The sweet spot for many teams: self-host n8n on a $5–$10/month VPS (Hetzner, DigitalOcean, Railway) and spend your budget on LLM API keys instead.

Common Pitfalls (and How to Avoid Them)

1. Vague system prompts. The agent is only as good as its instructions. "You are a helpful assistant" is useless. Specify the role, available tools, decision criteria, output format, and constraints.

2. Too many tools. Each tool adds to the LLM's context window and decision complexity. Start with 3–5 tools. Add more only when you have a clear use case for each.

3. No error handling. Tools can fail — APIs time out, rate limits hit, data is missing. Use n8n's error handling (try/catch patterns) around tool nodes and instruct the agent to handle failures gracefully in its system prompt.

4. Ignoring costs. Each agent reasoning loop makes an LLM API call. A complex agent with 5 tool calls per request costs ~$0.05–$0.15 per interaction with GPT-4o. Use gpt-4o-mini or Claude Haiku for simpler tool decisions, and route only complex reasoning to expensive models.

5. No human oversight. Don't let agents send emails, modify databases, or post to Slack without a review step — at least during the first few weeks. Add a "draft and wait for approval" pattern for high-stakes actions.

Start Simple

Build one agent that does one thing well before attempting multi-agent orchestration. The email triage pattern (Pattern 1) is the best starting point — it's immediately useful and teaches you the core concepts.

The Bottom Line

n8n is the best platform for building AI agents if you want real agentic behavior — tool calling, reasoning loops, memory, sub-agents — without writing code, and without getting locked into an expensive SaaS platform.

Start with a single agent, a few tools, and a clear task. Get it working reliably. Then expand: add memory, add sub-agents, connect to MCP servers, and build the compound system piece by piece.

The cost of entry is zero (self-hosted + your LLM API key). The learning curve is a weekend afternoon. And the ceiling is high enough that companies running 400+ agent workforces are doing it on n8n.


Get Started

New to AI agents? Start with our guide to agentic AI to understand the fundamentals. Already comparing platforms? See our no-code AI agent builder comparison for how n8n stacks up against Zapier, Make, Relevance AI, and others.

For a broader look at what AI agents can actually do in practice, explore our AI agent examples guide.

Frequently Asked Questions

Can I build AI agents in n8n for free?
Yes. n8n's Community Edition is free and open-source with unlimited workflow executions. You can self-host it on any server, including free tiers from Railway, Render, or Google Cloud. The only cost is your LLM API key (OpenAI, Anthropic, etc.) — typically $0.01–$0.10 per agent run depending on the task.
What LLMs work with n8n AI agents?
n8n supports OpenAI (GPT-4o, GPT-4o-mini), Anthropic (Claude Sonnet, Claude Haiku), Google (Gemini), and any model available through OpenRouter or Ollama for local inference. You can also mix models within a workflow — use a powerful model for reasoning and a cheaper one for simple tool calls.
What is the difference between n8n's AI Agent and a regular workflow?
A regular n8n workflow follows a fixed sequence of steps — trigger, action, action, done. An AI Agent workflow adds a reasoning layer where the LLM decides which tools to call and in what order based on the input. The agent can loop, retry, and adapt its plan. Think of a regular workflow as a recipe and an agent as a chef who can improvise.
Does n8n support multi-agent systems?
Yes. n8n supports sub-agents using the AI Agent Tool node, where one agent can call another as a tool. You can build hierarchical systems — a main orchestrator agent that delegates to specialist sub-agents for email, calendar, CRM, and other tasks. Each sub-agent can have its own LLM, system prompt, and memory.
How does n8n compare to Zapier for AI agents?
n8n's AI agent capabilities are significantly deeper than Zapier's. n8n offers native Tools Agent nodes with real LLM reasoning loops, memory management, sub-agents, and MCP server support. Zapier's AI features are more limited — primarily AI Actions (single LLM calls) without true agent loops. n8n is also free to self-host, while Zapier's paid plans start at $19.99/month.
Home Blog Company