Guide · n8n · AI agents

How to build AI agents with n8n

n8n's AI Agent node turns a workflow into something that decides what to do next. This guide walks through a production-grade setup for two common business use cases — lead qualification and automated customer support — and the patterns that keep those agents reliable.

What an n8n AI agent actually is

An n8n AI agent is a node that wraps a chat model (OpenAI, Anthropic, a local model via Ollama) and gives it a set of tools — other n8n nodes it can call when it decides they're useful. The agent reads an input, picks a tool, runs it, reads the result, and loops until it returns a final answer. Everything is visible in the n8n execution view, which is why it scales past the prototype stage where bare LLM calls usually break.

You'll see three building blocks repeatedly: the Agent node, one or more Tool nodes (HTTP request, database query, Gmail, Slack, custom workflows), and a Memory node when the conversation needs context across turns.

Use case 1 — Lead qualification

  1. Trigger: Webhook node receiving form submissions from your site (name, email, company, message).
  2. Agent prompt: "You qualify inbound leads. Use the tools available to enrich the company, then score the lead from 1–5 against this ICP: …".
  3. Tools to attach: an HTTP Request tool pointing at a company-enrichment API, a Postgres tool to check whether the domain already exists in your CRM, and a Slack tool that posts qualified leads (score ≥ 4) to your sales channel.
  4. Output: the agent writes the score and reasoning back to the CRM row and only escalates the ones worth a human.

The win isn't replacing your SDR — it's removing the 80% of inbound that never deserved a reply in the first place.

Use case 2 — Automated support triage

  1. Trigger: Gmail or Intercom node watching the support inbox.
  2. Memory: attach a Window Buffer Memory node keyed by thread ID so multi-message conversations stay coherent.
  3. Tools: a Vector Store tool (Pinecone, Supabase pgvector, or n8n's built-in Simple Vector Store) loaded with your help-center articles; an Orders lookup tool that calls your backend; an "escalate to human" tool that assigns the ticket and stops the agent.
  4. Guardrail: a final If node that checks the agent's confidence and routes anything ambiguous to a human queue.

Patterns that keep agents reliable

  • Narrow tools beat clever prompts. Give the agent 3–6 well-named tools with strict input schemas, not "an HTTP Request node, go figure it out".
  • Always return structured output. Use the Structured Output Parser node so downstream steps don't have to regex the model's prose.
  • Log everything. n8n's execution data is your audit trail — pin a "Save run" step that writes the agent's reasoning, tool calls, and final answer to a database table.
  • Set a step cap. The Agent node has a max iterations setting. Keep it low (5–8) and fail loud if it's hit.

When n8n is the right call

Pick n8n when the agent needs to touch your existing stack — databases, internal APIs, Slack, Gmail, CRMs — and you want every run inspectable. Pick a code-first framework (LangGraph, Mastra) when you need fine-grained control over the planning loop itself. Most real businesses I work with land on n8n because the team can read and edit the workflow without me in the room.

Related workflows

Want one built for your stack?

I design and ship n8n AI agents for lead ops, support, and internal tooling. Book a free review and I'll map the highest-leverage workflow in your business.

★ Book review