n8n

n8n for AI Automation: How to Build AI Workflows That Hold Up

How to use n8n for AI automation: webhooks, data, AI steps, agents, memory, RAG, human approval, error workflows and evaluations, with a worked lead workflow.

Mauricio Esparza By ·Published ·7 min read
mithub.club
Short answer

n8n is a workflow automation tool you can use to build AI automation visually: a trigger such as a webhook starts the workflow, nodes fetch and reshape data, AI nodes call language models or run agents with tools and memory, and other nodes update your systems. Its value for AI work is control: human approvals, error workflows and evaluations sit in the same canvas.

If you're new to the tool itself, start with What is n8n?. This article is about using it specifically for AI automation, and about the parts beginners skip.

What n8n gives you for AI

According to n8n's Integrate AI documentation, you can connect LLM providers such as OpenAI, Anthropic and Google, add tools and memory, use MCP servers and combine several models in one workflow. In practice that breaks into a few building blocks:

Building blockWhat it doesWhen you use it
Chat modelThe LLM that reads and writesEvery AI step
ChainA fixed AI step: prompt in, output outClassify, extract, summarize, draft
AgentA model that decides which tools to callOpen-ended tasks with several possible steps
ToolsActions an agent may take (search, CRM lookup, HTTP request, another workflow)Giving an agent abilities
MemoryKeeps conversation history across turnsChat-style agents
Vector storeStores content by meaning for retrieval (RAG)Answering from your own documents

n8n's docs describe an agent as a chain that can make decisions. That one line is the key design choice in every AI workflow you build: do you need a fixed step or a decision-maker? We cover that choice in AI agents vs automation. The short version: use a chain unless you have a clear reason for an agent.

The anatomy of an n8n AI workflow

MitHub breaks every AI automation into six layers: Trigger → Data → Decide → Act → Record → Alert (explained in What is AI automation?). Here's how each maps to n8n.

1. Trigger

Common triggers are a schedule, an app event (a new row, a new CRM record) or a webhook.

The Webhook node gives you a URL that starts the workflow when another system sends data to it. It has two URLs:

  • Test URL: active while you listen for a test event; incoming data appears in the editor so you can build against it.
  • Production URL: registered when you publish the workflow; runs show up in the Executions tab, not in the editor.

Habit to build: develop against the test URL, switch the source system to the production URL only after testing, and write down which URL each external system points to. Many "it stopped working" problems are a source still pointing at the test URL.

2. Data

n8n passes data between nodes as a list of items, each carrying its fields under a json key, as described in Understand n8n's data structure. Nodes generally run their operation once per item.

This matters for AI because every item can be a model call. Send 500 rows into an AI node and you've made 500 calls. Filter, deduplicate and clean before the AI step. Use rules nodes (filters, IF, Switch) to remove anything that doesn't need a model.

3. Decide

This is where rules and AI split the work.

  • Rules first: IF and Switch nodes for anything you can write as a condition.
  • AI step: a chain with a tight prompt and structured output: a fixed label, a score, specific fields. Not a paragraph.
  • Agent: only when the step truly needs the model to choose tools.

Then validate. If the model returns a label that isn't in your allowed list, route it to a human instead of letting it continue.

4. Act

Update the CRM, send the Slack message, create the task. For risky actions, add a human.

n8n supports human-in-the-loop for tools: when an agent wants to run a tool that requires review, the workflow pauses and sends an approval request through a channel such as n8n Chat, Slack, Teams, Telegram or email. If approved, the tool runs with the parameters the AI chose. If denied, it's cancelled and the AI is told. You can require review on specific high-risk tools only, leaving safe read-only tools free.

5. Record

Write the input, the AI's decision and the outcome somewhere a person can check: a CRM note, a log table, a sheet. A workflow that acts without leaving a trace can't be trusted or improved.

6. Alert

n8n lets you handle errors with a separate error workflow that starts with an Error Trigger node. You pick it in the main workflow's settings, and when an execution fails it receives details such as the failed node, the error message and a link to the execution. One error workflow can serve many workflows. You can also force it on purpose with a Stop And Error node, for example when the AI returns something outside your allowed values.

A worked example: inbound lead triage (hypothetical)

Imagine a company whose website form sends leads with a free-text message. Today someone reads every message and routes it by hand. Here's an n8n design.

  1. Webhook receives the form submission.
  2. Set / Edit Fields normalizes it: trims whitespace, lowercases the email, formats the phone.
  3. CRM lookup checks if the contact already exists. IF it exists, update and stop; otherwise continue.
  4. Filter drops obvious junk with rules (empty message, test email domains). No model needed.
  5. AI chain reads the message and returns structured output:
{
  "intent": "sales",
  "urgency": "high",
  "locations_mentioned": 3,
  "summary": "Asks for pricing for 3 locations and wants a call this week."
}
  1. IF intent is not one of sales, support, spam → route to a human review queue.
  2. Switch on intent: sales → create lead and assign by territory; support → create a ticket; spam → log only.
  3. For high-urgency sales leads: send the rep a Slack message with the summary and a drafted first reply that the rep approves before anything reaches the prospect.
  4. Record: write the original message, the AI output and the route taken to a log.
  5. Error workflow alerts a channel if any node fails.

Of ten steps, one uses a model. That's normal. The AI step removes the manual reading; everything else makes it safe.

Testing AI steps: evaluations

A workflow with rules can be checked by reading it. An AI step can't. n8n's evaluation docs explain that because models behave like black boxes, you build confidence by running a dataset of test cases (sample inputs, often with expected outputs) through the workflow. The docs name three benefits: testing across a range of inputs including edge cases, iterating without accidentally breaking something that worked, and comparing models or prompts.

A practical way to start:

  1. Collect 30–50 real past inputs (anonymized) including the weird ones.
  2. Label the correct answer for each by hand.
  3. Run them through the AI step and count how many match.
  4. Change one thing (prompt, model, examples) and run again.
  5. Keep the version that scores best, and keep the test set for next time.

That score is also your proof. "It works" becomes something like "it matched the human label on 44 of 50 real cases" (an illustrative figure), which is a claim a manager or client can verify.

Memory and RAG in n8n, briefly

  • Memory keeps the history of a conversation so a chat agent doesn't forget earlier messages. Start with simple built-in memory; move to an external database when conversations need to persist or scale. Memory is for agents in conversation, not for one-off classification steps.
  • RAG lets an agent answer from your documents. You load content, split it into chunks, turn it into embeddings and insert it into a vector store; at query time, the agent (or a direct vector store query) retrieves the most relevant chunks. Quality depends heavily on how you chunk and what you load. Bad documents in, confident wrong answers out.

n8n AI workflow checklist

Before you publish, check every box:

  • The trigger was tested on the test URL; the source now points at the production URL.
  • Data is filtered and deduplicated before any AI node.
  • Each AI step has a single job and returns structured output.
  • Unexpected AI output routes to a human or an error, never silently onward.
  • Agents have the fewest tools possible; write actions require approval.
  • Credentials live in n8n's credential store, never pasted into prompts or nodes.
  • Every run writes a record a non-builder can read.
  • An error workflow is attached and alerts a real person.
  • An evaluation set exists for each AI step, with a current score.
  • Someone else could understand the workflow from its node names and notes.

Where n8n fits in a revenue stack

n8n is the orchestration layer: it connects systems and moves data between them. It usually works alongside a CRM (the system of record), an enrichment tool like Clay and communication tools. If you're deciding which tool should own which job, see Clay vs n8n.

To choose your first workflow, don't start from n8n's node list. Start from the money: MitHub's Follow the money chapter maps the process backwards from the payment, and Prove value fast helps you pick the automated workflow that shows results soonest. If you want the concepts behind agents first, read What is an AI agent?

Frequently asked questions

Can n8n build AI agents?

Yes. n8n provides an agent node that uses a language model to decide which connected tools to call, and it can be given memory. It can also run simpler AI steps, called chains, that don't make decisions.

What is the difference between the test URL and production URL in n8n webhooks?

The test URL is for building: it shows incoming data in the editor. The production URL works once the workflow is published, and its runs appear in the Executions tab instead of the editor.

How do I add human approval to an n8n AI workflow?

n8n supports human review on specific agent tools: the workflow pauses and sends an approval request through a channel like Slack, email or chat, and the tool runs only if approved.

Which LLMs can I use in n8n?

n8n's documentation lists connections to providers such as OpenAI, Anthropic and Google, and you can combine several models in one workflow.

Sources

  1. Integrate AI — n8n Docs (accessed 2026-09-17)
  2. Webhook node documentation — n8n Docs (accessed 2026-09-17)
  3. Understand n8n's data structure — n8n Docs (accessed 2026-09-17)
  4. Human-in-the-loop for tools — n8n Docs (accessed 2026-09-17)
  5. Handle errors gracefully — n8n Docs (accessed 2026-09-17)
  6. Understand why to test — n8n Docs (accessed 2026-09-17)
n8nAI AutomationAI AgentsWorkflow Automation
Mauricio Esparza
Mauricio EsparzaGTM Systems Lead · Revenue Engineer · Founder of MitHub. Designs and runs revenue systems for multi-location businesses: AI voice campaigns, enrichment, CRM automation and attribution. Founded MitHub to teach the method in the open.

Part of n8n on MitHub.

Keep going