In 2026, AI agents have moved from research demos to production tools. n8n is one of the friendliest places to build them: visual, self-hostable and packed with native LLM nodes. This guide walks through building a real, useful AI agent in n8n step by step.
TL;DR: Start with a clear job, give the agent the right tools (search, email, database), put guardrails around it and ship in n8n with the AI Agent node connected to your favorite LLM.
What is an AI Agent in n8n?
An AI agent in n8n is a workflow where a Large Language Model (LLM) decides which actions to take based on an objective. Unlike simple chatbots that respond to queries, agents can use tools — web search, database queries, email sending, API calls — to complete multi-step tasks autonomously.
n8n’s AI Agent node uses a ReAct (Reasoning + Acting) pattern: the LLM reasons about what to do, uses a tool, observes the result, and reasons about the next step until the task is complete.
1. Define the Agent’s Job
A good AI agent has a narrow, well-defined job. Trying to build a “do everything” agent is the fastest path to failure. Instead, start with a specific use case:
- Lead research agent: Given a company name, research their website, LinkedIn and news, then produce a sales briefing
- Content monitoring agent: Check competitor websites for new content and summarize findings daily
- Customer support triage agent: Read incoming support tickets and route them to the right department with priority tags
- Data enrichment agent: Take a list of email addresses and find company, job title and LinkedIn profile for each
Define your agent’s job as a clear sentence: “Given [input], do [actions] and return [output].”
2. Prerequisites: What You Need Before Building
Before building your first n8n AI agent, you’ll need:
- n8n account: Use n8n Cloud (free tier available) or self-host n8n on a server
- LLM API key: OpenAI, Anthropic Claude, or Google Gemini — all work with n8n’s AI nodes
- Tool credentials: API keys for any external tools your agent will use (Serper for search, Gmail for email, Airtable for database, etc.)
3. Build the Agent Workflow Step by Step
Step 1: Add the AI Agent Node
In n8n, search for “AI Agent” in the node panel. This is the core node that connects your LLM to your tools. Configure it with:
- System prompt: Define the agent’s role and constraints
- Chat model: Select your LLM (GPT-4o, Claude 3.5, Gemini Pro)
- Memory: Add a Window Buffer Memory node for conversation history
Step 2: Write an Effective System Prompt
The system prompt is your agent’s operating manual. A good system prompt includes:
You are a [role] that helps [persona] with [task].
Your capabilities:
- [Tool 1]: Use this to [when/why]
- [Tool 2]: Use this to [when/why]
Rules:
- Always [constraint 1]
- Never [constraint 2]
- When unsure, [fallback behavior]
Output format: [specify format]
Step 3: Add Tools to the Agent
Connect tool nodes to the AI Agent node. n8n supports these tool types natively:
| Tool Type | n8n Node | Use Case |
|---|---|---|
| Web search | SerpAPI / Serper Tool | Research, fact-checking |
| Code execution | Code Tool | Data processing, calculations |
| HTTP requests | HTTP Request Tool | API calls, webhooks |
| Database | Postgres/MySQL Tool | Query and update data |
| Gmail Tool | Read and send emails | |
| Vector store | Pinecone/Supabase Tool | RAG, knowledge base |
Step 4: Add Memory
Without memory, your agent forgets the conversation context after each response. Add a “Window Buffer Memory” node connected to the AI Agent to maintain context across multiple steps. For long-running agents that need persistent memory across sessions, use “Postgres Chat Memory” with a database connection.
Step 5: Add a Trigger and Output
Connect a trigger to start your agent workflow:
- Webhook trigger: For real-time activation from external apps
- Chat trigger: For interactive chat interfaces
- Schedule trigger: For automated periodic runs
- Form trigger: For simple input forms
Add an output node to deliver results: Email, Slack message, Google Sheet row, or HTTP response.
4. Add Guardrails and Error Handling
Production AI agents need safety checks. Add these to your n8n workflow:
- Max iterations limit: Set a maximum loop count to prevent infinite loops
- Output validation: Use an IF node to check the agent’s output format before delivering
- Error trigger: Connect an Error Trigger node to catch and log failures
- Human-in-the-loop: For sensitive actions, add a “Wait for approval” step via Slack or email
5. Test and Iterate
Test your agent with edge cases before deploying. In n8n, use the “Test with execution” button and check each node’s output in the execution log. Common issues to watch for:
- Agent getting stuck in loops (set max iterations)
- Tool errors not handled gracefully (add error nodes)
- Output format inconsistency (add an output parser node)
- Context window overflow for long conversations (trim memory window)
Real-World Example: Lead Research Agent
Here’s a complete simple agent workflow for researching sales leads:
- Trigger: Webhook receives company name
- AI Agent: System prompt: “You are a lead researcher. Given a company name, use web search to find their website URL, main product, company size, recent news and CEO name. Return as structured JSON.”
- Tool 1: Serper web search
- Tool 2: HTTP Request to extract website content
- Output: Google Sheet row with research findings + Slack notification
How to Build AI Agent n8n FAQ
Is n8n free for AI agents?
n8n offers a free cloud tier with 5 active workflows and 2,500 executions per month — enough to test and run small agents. Self-hosted n8n is completely free with no execution limits. The AI Agent node, memory nodes and tool nodes are all available on free tiers.
Which LLM works best with n8n AI agents?
GPT-4o and Claude 3.5 Sonnet both work excellently with n8n’s AI Agent node. GPT-4o tends to be faster and handles tool calling reliably. Claude 3.5 Sonnet produces more thoughtful, careful reasoning for complex multi-step tasks. Both are solid choices — the best LLM depends on your budget and use case complexity.
Can n8n AI agents run autonomously without human input?
Yes. Triggered by a Schedule node, n8n agents can run completely autonomously on a timetable. For example, a content monitoring agent can check competitor websites every morning and send a briefing email without any human intervention. Add proper error handling and output validation before running agents fully autonomously.
Final Thoughts
n8n is one of the best platforms for building production AI agents in 2026. Its visual workflow builder removes the coding barrier, its native LLM and tool nodes integrate cleanly, and its self-hosting option means enterprise-grade data privacy. Start with a narrow, well-defined use case, test thoroughly, and expand the agent’s capabilities incrementally.