How to Build an AI Agent with n8n
An AI agent in n8n is a workflow that passes data to a language model (such as GPT-4 or Claude), uses the model's output to make a decision, and routes to different actions based on that decision. You build one using n8n's AI Agent node, which handles tool calling and multi-step reasoning, or a plain HTTP node for simpler classification tasks.
n8n lets you build AI agents that call a language model, make decisions based on the response, and route to different actions. Here is how to set one up step by step.
What an AI Agent Does in n8n
In n8n, an AI agent is not a separate product: it is a pattern built from standard nodes. Data enters the workflow, gets passed to a language model with a task-specific instruction, the model returns a decision or transformed output, and subsequent nodes act on that output. For example: an email arrives, the AI classifies it as urgent or routine, and the workflow routes accordingly. This is different from a simple chatbot because the agent acts, not just responds. See what an AI agent is for a conceptual overview before you build.
What You Need
You need an n8n account (cloud or self-hosted) and an API key from an AI provider: OpenAI, Anthropic, or another supported provider. For most email triage and classification use cases, GPT-4o mini or Claude Haiku are fast and cost-effective. For more complex reasoning tasks, use a larger model. Costs per request are low for classification tasks, typically fractions of a cent per run, so cost is rarely a limiting factor for moderate volumes.
Tips for Reliable AI Steps
AI nodes can introduce variability that traditional workflow nodes do not have. Three practices keep your agent reliable. First, keep the task focused: ask the model to do one thing per node, not many things at once. Second, specify the output format explicitly in the system prompt: “return only one of these three values: Urgent, Normal, Low” is more reliable than asking the model to explain its reasoning. Third, set a low temperature (0.0 to 0.3) for classification and routing tasks. Higher temperatures are useful for creative generation, not for deterministic triage. Test with at least 20 to 30 real examples before enabling the workflow on production data.
Our tip: Build your first AI agent around a classification or triage task with a fixed set of output values. These are the easiest to validate and the most forgiving to tune. Once you have one working reliably, the pattern transfers to more complex use cases.