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.
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
- Add a Chat Trigger node — this gives you a chat interface to interact with your agent during development.
- Add an AI Agent node — connect it to the Chat Trigger. This is the brain.
- Attach an LLM — click the Agent node, select "OpenAI Chat Model" (or Anthropic, Google, etc.), and enter your API key. Start with
gpt-4o-minifor cheap experimentation. - 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:
| Tool | What It Does | n8n Node |
|---|---|---|
| Search the web | Agent can look up current information | SerpAPI / HTTP Request |
| Send email | Agent drafts and sends email on your behalf | Gmail / SMTP |
| Query a database | Agent reads from or writes to your database | Postgres / MySQL / MongoDB |
| Update CRM | Agent creates or modifies contacts and deals | HubSpot / Salesforce |
| Post to Slack | Agent sends messages to channels or users | Slack |
| Run code | Agent executes JavaScript or Python for custom logic | Code node |
| Call a sub-agent | Agent delegates a subtask to a specialized agent | AI Agent Tool node |
| Access MCP servers | Agent 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.
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 Type | How It Works | Best For |
|---|---|---|
| Window Buffer | Stores the last N messages | Quick chats, simple tasks |
| Token Buffer | Stores messages up to a token limit | Longer conversations with cost control |
| Postgres/Redis Chat Memory | Stores messages externally | Production 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:
- Add an MCP Client Tool node
- Point it at your MCP server URL (or a local
npxcommand) - 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
| Factor | n8n Cloud | Self-Hosted (Community) |
|---|---|---|
| Cost | From $20/mo (2,500 executions) | Free (you pay for server hosting) |
| Setup | Instant, no server needed | Docker/Railway setup required (15 min) |
| Execution limits | Based on plan tier | Unlimited |
| Updates | Automatic | Manual (but straightforward) |
| Data privacy | Data on n8n servers | Data stays on your infrastructure |
| AI agent features | All features included | All features included |
| Best for | Teams who want zero ops overhead | Teams 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.
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.