n8n

Building AI Agents in n8n With OpenAI and Claude

How to build a production AI agent in n8n: the Tools Agent, choosing between OpenAI and Claude, tool design, structured output, memory, human approval and testing.

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

In n8n you build an AI agent with the AI Agent node: attach a chat model sub-node (OpenAI, Anthropic's Claude, Azure OpenAI, Groq and others are supported), connect the tools it may use, optionally add memory, and write a system message defining its job and limits. The model then decides which tools to call. What makes it production-ready is everything around it: structured output, human approval on risky tools, and an evaluation set.

That last sentence is the point of this article. The model is the easiest decision you will make. Everything that determines whether the agent survives contact with real work — tool design, output structure, approval gates, testing — is architecture you have to build deliberately. This guide is about that architecture. For the wider picture of AI inside n8n, see n8n for AI automation.

In short

  • The node is the Tools Agent. n8n's docs state the agent type setting is deprecated as of 1.82.0 and all nodes now act as a Tools Agent (n8n Docs).
  • Chat models are interchangeable sub-nodes. OpenAI, Anthropic, Azure OpenAI, Groq and Mistral Cloud are among the documented options (Tools Agent).
  • Fewer tools, sharper boundaries. Every tool added is another wrong path.
  • Structured output is not optional for anything downstream of the agent.
  • Approval gates belong on irreversible tools, not on the whole agent.
  • Choose your model with an evaluation, not with a benchmark someone posted.

Do you actually need an agent?

Start here, because the honest answer is usually no.

An agent earns its complexity when the sequence of steps genuinely depends on the input. A rep asks a question and the system must decide whether to look in the CRM, check a calendar, or read a policy document — that is an agent. Classifying an inbound message into one of four categories is not; it is one model call with a fixed prompt, which n8n calls a chain.

The test we use: can you draw the flowchart? If you can draw it, build the flowchart. It will be cheaper, faster, easier to debug, and it will behave identically on Tuesday and on Friday. AI agents vs automation covers the distinction in depth, and agentic workflows covers the patterns worth using when you do need one.

The MitHub agent contract

Before opening n8n, we write five lines. If any line is hard to fill in, the agent is not ready to build.

LineExample answer
JobAnswer a rep's question about an account using our own systems
ToolsCRM record lookup, last-5-activities lookup, policy document search
Hard limitsRead-only. Never contacts a customer. Never writes to the CRM.
Output shape{ answer, sources[], confidence, escalate }
EscalationIf confidence is low or no source was found, hand to a named human

The two lines people skip are hard limits and escalation, which are exactly the two that decide what happens on the bad day. An agent without a defined failure behaviour will invent one.

Assembling the agent in n8n

The chat model

Attach a chat model sub-node. n8n's Tools Agent documentation lists OpenAI, Anthropic, Azure OpenAI, Groq and Mistral Cloud chat models among the supported options, and the wider node index includes Google Gemini, AWS Bedrock, DeepSeek, Cohere, OpenRouter and Ollama for locally hosted models. Claude is reached through the Anthropic Chat Model sub-node, and each provider has its own node with its own model list and options.

How to choose between OpenAI and Claude, practically:

  1. Build the agent with whichever you already have credentials for.
  2. Assemble 30–50 real inputs, including the ugly ones, and label the correct outcome by hand.
  3. Run the set. Swap the chat model sub-node. Run it again.
  4. Compare on three axes: correctness on your labels, how well each follows your output schema, and cost per run at your volume.
  5. Keep the winner, keep the test set, and re-run it whenever you change the prompt.

This takes an afternoon and replaces an argument with a number. It is also the only comparison that reflects your data, which is the only comparison that matters. Provider model lineups change often, so treat any list of specific model names — including one you read today — as perishable and check the provider's own documentation.

The tools

Tools are what the agent can do. n8n exposes many app nodes as agent tools, and lets the model populate their parameters: the $fromAI() function dynamically fills in parameters for tools connected to the Tools Agent, and each eligible parameter field has a button that hands that field to the model (n8n Docs).

That convenience is also the sharpest edge in the whole build. A field the model fills is a field the model can fill wrongly — including record IDs, recipients and search filters. Three rules:

  • Name tools by intent, not by app. find_account_by_email beats HubSpot. The name is part of the prompt.
  • One tool, one job. A single tool that can read, update and delete gives the model three chances to pick the wrong one under one label.
  • Pin what should never vary. If a tool must always write to one specific list, hard-code it rather than letting the model choose.

n8n's Tools Agent also documents a Max Iterations option that controls how many times the model runs to generate an answer, defaulting to 10. Lower it for narrow agents. It is a cost ceiling and a loop guard at once.

Structured output

An agent that returns a paragraph forces the next node to parse prose. Turn on Require Specific Output Format and connect an output parser; n8n documents Auto-fixing, Item List and Structured parsers for this (Tools Agent).

The Structured Output Parser returns fields based on a JSON Schema. You can define the schema by hand, or generate it from an example JSON object — n8n notes that when generating from an example it uses the property names and types, ignores the values, and treats every field as mandatory (n8n Docs). Note also that $ref references in JSON schemas are not supported.

A schema we would use for the account-question agent:

{
  "answer": "string",
  "sources": ["string"],
  "confidence": "high",
  "escalate": false
}

Then validate it anyway. If confidence comes back as something outside your allowed values, route to a human rather than letting an unexpected value flow onward.

Memory

Add memory only for conversations. n8n documents Simple Memory, which stores chat history for the current session, alongside memory services including Redis Chat Memory, Postgres Chat Memory, Motorhead, Xata and Zep, plus a Chat Memory Manager node for advanced cases (n8n Docs). The Tools Agent documentation is explicit that memory does not persist between sessions.

Two things worth knowing: memory is for agents, not chains — n8n's documentation notes AI chains cannot use memory. And a growing conversation history is a growing bill, since it is resent as context on every turn.

The system message

Write it as instructions to a competent new hire on their first day, not as a personality description. Cover: what the job is, what to do when data is missing, what it must never do, and the exact output shape. "You are a helpful assistant" is decoration. "If no account matches the email, set escalate to true and stop" is an instruction.

The gate: human approval on risky tools

This is the difference between a demo and something you would let near a customer.

n8n supports requiring human approval before an AI Agent executes a specific tool. The workflow pauses, sends an approval request showing which tool the model wants to use and with what parameters, and the tool runs only if a person approves; if denied, the action is cancelled and the model is informed of the rejection. Available approval channels include n8n's built-in Chat, Slack, Discord, Telegram, Microsoft Teams, Gmail, WhatsApp Business Cloud, Google Chat and Microsoft Outlook, and the review can happen in a different channel from the main interaction (n8n Docs).

The design choice is which tools get a gate. Our rule, borrowed from the risk tiers in human in the loop:

TierExamplesGate
ReadLook up a record, search documentsNone
Internal writeCreate a task, post to a team channelNone, but logged
External or irreversibleEmail a customer, change a stage, deleteAlways

n8n's own guidance suggests starting with review enabled and reducing oversight as confidence grows. Make that a deliberate decision with a date attached, not something that erodes by neglect.

Testing, and the honest version of "it works"

An agent cannot be verified by reading it. n8n's evaluation documentation makes the case directly: code is deterministic and you can reason about it, but LLMs are black boxes, so you must measure output by running data through them. Evaluations let you test across a range of inputs including edge cases, make changes without quietly breaking what worked, and compare models or prompts (n8n Docs). The docs distinguish light evaluation while building from metric-based evaluation after deployment.

Build the test set before you ship, not after something goes wrong. It is also your proof of work: "it matched the human label on 44 of 50 real cases" is a claim a client can check. "It works well" is not. That distinction is the whole idea behind proof of work over credentials.

Pre-launch checklist

  • The task genuinely needs decisions, not a flowchart.
  • The agent contract is written: job, tools, hard limits, output shape, escalation.
  • Every tool has an intent-based name and a single job.
  • Nothing irreversible can run without human approval.
  • Output is schema-constrained and validated after parsing.
  • Max Iterations is set deliberately.
  • Memory exists only if the task is conversational.
  • Credentials live in n8n's credential store, never in prompts.
  • An error workflow is attached and alerts a named person.
  • An evaluation set exists, with a current score written down.

Next steps

Go wider with n8n for AI automation, or back to fundamentals with What is an AI agent? If you are choosing between building an agent and building a plain workflow, AI agents vs automation is the shorter answer. And if you want to learn this as a path rather than a tool, the Faculty of Revenue Reverse Engineering starts free.

Frequently asked questions

Which models can I use in an n8n AI agent?

n8n's Tools Agent documentation lists chat model sub-nodes including OpenAI, Anthropic, Azure OpenAI, Groq and Mistral Cloud, and the integrations index includes many more such as Google Gemini, AWS Bedrock, DeepSeek, OpenRouter and Ollama for local models.

Do I have to choose an agent type in n8n?

No. n8n's AI Agent node documentation states the agent type option is deprecated as of version 1.82.0 and all nodes now act as a Tools Agent, with version 1 of the node due for removal by n8n 3.0.

How do I force an n8n agent to return JSON?

Enable Require Specific Output Format on the AI Agent node and connect an output parser. The Structured Output Parser returns fields based on a JSON Schema, which you can either write yourself or generate from an example JSON object.

Does memory persist between sessions in n8n?

n8n's Tools Agent documentation notes that memory does not persist between sessions. Simple Memory holds chat history for the current session; for durable history you use a memory service such as Redis or Postgres chat memory.

Can I stop an agent from taking an action without approval?

Yes. n8n supports human review on individual tools: the workflow pauses, sends an approval request through a channel such as Slack or email, and the tool runs only if a person approves it.

Sources

  1. AI Agent node documentation — n8n Docs (accessed 2026-09-17)
  2. Tools Agent — n8n Docs (accessed 2026-09-17)
  3. Understand why to test — n8n Docs (accessed 2026-09-17)
  4. Use AI for parameters — n8n Docs (accessed 2026-09-17)
  5. Structured Output Parser — n8n Docs (accessed 2026-09-17)
  6. How memory works — n8n Docs (accessed 2026-09-17)
n8nAI AgentsOpenAIClaudeAI 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

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.

Read · 7 min →mithub.club
n8n

What Is n8n? Workflows, Webhooks, AI Agents and Hosting Explained

What n8n is and how it works: nodes, triggers, webhooks, cloud vs self-hosted, AI agent nodes, revenue workflows and the basics of error handling.

Read · 9 min →mithub.club
AI & Automation

What Is an AI Agent? LLMs, Tools, Memory and Their Limits

What an AI agent is in plain language: how LLMs use tools in a loop, memory and context, RAG, agentic workflows, human in the loop and where agents fail.

Read · 7 min →mithub.club
AI & Automation

Human in the Loop: Where People Belong in AI Workflows

How to place humans in AI workflows on purpose: risk tiers, seven approval patterns, the rubber-stamp trap, and written criteria for removing a review gate.

Read · 9 min →mithub.club
AI & Automation

Agentic Workflows: Patterns That Actually Work

The five agentic workflow patterns that work in production — chaining, routing, parallelization, orchestrator-workers, evaluator-optimizer — and when to use none.

Read · 7 min →mithub.club
AI & Automation

AI Agents vs Automation: How to Choose the Right One

AI agents vs automation: how they differ in control, cost, testing and risk, plus a simple decision grid to choose a workflow, an AI step or a bounded agent.

Read · 6 min →mithub.club