Phase 2: n8n for AI Automation · 55 min · n8n · OpenAI API · Anthropic API
AI Agent Nodes in n8n — LLMs, Tools, and Memory
Agents decide which tools to call; you define the tools.
Hiring signal: AI agent configuration is the skill that distinguishes automation engineers from automation users. Being able to configure an n8n AI Agent node with LLM, tools, memory, and iteration limits — and explain when to use agents vs fixed workflows — demonstrates the depth that production automation roles require.
What you will learn
- Configure n8n's AI Agent node with LLM model, tools, memory, and system prompt
- Define tools for agents: HTTP requests, database queries, sub-workflow calls
- Configure conversation memory: window size, token buffer
- Set maximum iterations to prevent infinite loops and control cost
The Problem
A customer support team builds an n8n workflow: receive ticket → LLM classifies category → IF node routes by category → separate workflow per category. It works for 80% of tickets. But the other 20% are ambiguous — a refund request that's also a complaint, a billing question that requires checking the order database, a technical issue that needs both knowledge base lookup and account history. The fixed IF/ELSE routing can't handle these. The team needs a system that can look at a ticket, decide what information it needs, call the right tools to get that information, and then respond.
This is what AI agents do. Instead of hardcoding the decision tree, you give the LLM a set of tools and let it decide which to call based on the input. n8n's AI Agent node makes this visual and production-ready.
An agent is not a smarter LLM call — it's a loop
The agent node implements a ReAct-style loop: the LLM receives the input, decides which tool to call, gets the tool's result, decides if it needs another tool, and repeats until it can answer. Your job is to define good tools and set boundaries (max iterations, memory, system prompt).
The Concept
AI Agent Node Anatomy
┌─────────────────────────────────────────────────────────────┐
│ AI Agent Node │
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ LLM Model │ │ Tools │ │ Memory │ │
│ │ │ │ │ │ │ │
│ │ OpenAI │ │ HTTP Req │ │ Window │ │
│ │ Anthropic │ │ DB Query │ │ Buffer │ │
│ │ Ollama │ │ Sub-workflow│ │ Token │ │
│ │ Azure │ │ Calculator │ │ Buffer │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────┐ │
│ │ System Prompt │ │
│ │ "You are a support agent. Use tools to look up │ │
│ │ order info before responding. Always cite the │ │
│ │ order number in your response." │ │
│ └─────────────────────────────────────────────────┘ │
│ │
│ Max Iterations: 5 │
└─────────────────────────────────────────────────────────────┘
The Agent Loop
LLM Providers Supported in n8n
| Provider | n8n Node | Models | Best For |
|---|
| OpenAI | OpenAI Model | GPT-4o, GPT-4o-mini, o3-mini | Default choice, tool calling, fast |
| Anthropic | Anthropic Model | Claude 3.5 Sonnet, Haiku | Long context, careful reasoning |
| Ollama | Ollama Model | Llama 3, Mistral, Qwen | Local, no API cost, privacy |
| Azure OpenAI | Azure OpenAI Model | GPT-4o (Azure) | Enterprise, data residency |
| Google | Google Gemini Model | Gemini 2.0 Flash/Pro | Multimodal, long context |
Defining Tools
Tools are the agent's capabilities. In n8n, you connect tool nodes to the AI Agent node:
| Tool Type | n8n Node | Example Use |
|---|
| HTTP Request | HTTP Request Tool | Call external APIs, webhooks |
| Database Query | Postgres/MySQL Tool | Look up customer, order, inventory |
| Sub-workflow | Execute Workflow Tool | Run complex logic as a tool |
| Calculator | Calculator Tool | Math operations |
| Knowledge Search | Vector Store Tool | RAG retrieval |
| Custom | Code Tool | Any custom JavaScript logic |
Each tool has:
- Name: Short identifier (e.g.,
lookup_order) - Description: What the tool does (the LLM reads this to decide when to use it)
- Input schema: What parameters the tool accepts (JSON Schema)
Tool descriptions are the most important prompt engineering in agent systems
The LLM decides which tool to call based on the description. If your description says "lookup" but the tool actually searches by email, the LLM will pass the wrong parameters. Write descriptions like documentation: what it does, what input it expects, what it returns.
Memory Configuration
Memory lets the agent remember previous turns in a conversation:
| Memory Type | How It Works | Best For |
|---|
| Window Buffer | Keeps last N messages | Short conversations, simple |
| Token Buffer | Keeps messages until token limit | Cost control, long conversations |
| Postgres/Redis | Persists across sessions | Multi-turn chatbots, user history |
| No memory | Each call is independent | One-shot tasks, batch processing |
You're building a support agent that handles multiple questions from the same user in a session. The agent keeps forgetting the user's order number from earlier in the conversation. What should you configure?
The agent isn't forgetting because it's not smart enough — it's forgetting because there's no memory configured, or the window is too small. Window Buffer memory keeps the last N messages in context. Increase the window size so the order number from earlier turns stays in the LLM's context window.
Maximum Iterations
The max iterations setting prevents infinite loops and controls cost:
| Setting | Effect | Use Case |
|---|
| 1–3 | Agent can call 1–3 tools before stopping | Simple lookups, single-step |
| 5 (default) | Agent can call up to 5 tools | Most support/automation tasks |
| 10+ | Agent can do multi-step research | Complex investigation, data gathering |
Each iteration is an LLM call. At 5 iterations with GPT-4o-mini, a single agent run costs ~$0.003–$0.01. At 10 iterations with GPT-4o, it can cost $0.05–$0.15 per run.
Unlock the full lesson
You've read the first 2 sections. The rest of this lesson covers Build It, Use It, Ship It, Exercises, Key Terms, Common Pitfalls — plus a hands-on lab, quiz, and project artifact.
Create a free account to unlock Phase 0 and Phase 1 of every course — no credit card.
Browse all courses · View pricing · DeVenture Academy