Part of
n8n consulting
Implementation

How to Build an AI Agent with n8n That Holds Up in Production

Dark card: n8n AI agents in production, checked before it ships; four stacked rows, Draft: AI Agent node, Check: Second agent, highlighted in orange, Pass: Reply to the user, Block: Back for a rewrite

An AI agent built in n8n holds up in production when the workflow around it expects failure. Run n8n in queue mode on Postgres, keep the agent's chat history in Postgres, give every node that calls a model or an API a retry and an error path, set an error workflow that alerts a person, and have a second agent check each draft before it reaches the user, with a person approving any tool call that sends, writes or deletes. Every draft is then checked before it ships, and a failed run reaches a person instead of disappearing. Pinkcube's chat agent, which Ovidius built on n8n, has a second agent that checks every draft before the customer sees a word.

A prototype that works on the canvas meets different conditions in production. A webhook fires in the middle of the night, the model returns malformed JSON, an API answers with a rate limit or times out, and the run fails with no alert, no retry and no record anyone reads, so your team hears about it from a customer the next morning. n8n has a setting or a node for each of these failures.

What breaks in production
Pick a failure to see what handles it in n8n
Malformed output
Stop And Error

Check the model's output before the next step uses it, and when it does not parse, fail the run on purpose with the Stop And Error node, which starts the error workflow.

Rate limit or timeout
Retry On Fail

Turn on Retry On Fail for each node that calls a model or an API. When an execution fails, the node reruns until it succeeds.

Memory in queue mode
Postgres Chat Memory

On a queue-mode instance, Simple Memory does not work in an active production workflow, because n8n can't guarantee that every call reaches the same worker. Use Postgres Chat Memory instead: it stores chat history in a Postgres table that every worker reads.

Silent failure
An error workflow

You set an error workflow for each workflow in Workflow Settings. It must start with the Error Trigger. Have it send a Slack or email alert to a person.

Wrong answer
A second agent checks every draft

A second agent reads each draft the AI Agent node writes and checks it against your rules before anything reaches the user. A draft that breaks a rule goes back for a rewrite, with the violation and the fix.

Risky tool call
Human approval

Approval runs the tool with the input the agent gave, and a denial cancels the action and tells the agent. Use it for any tool that sends, writes or deletes.

The failures are illustrative. Sources: n8n's documentation (node settings, error handling, Simple Memory, Postgres Chat Memory, human review of tool calls), checked 20 November 2026, and the Pinkcube case study. Orange marks the second-agent check, the remedy this post argues for.

Run n8n in queue mode on Postgres

Self-hosting n8n in your own cloud account keeps the editor, your credentials and every execution log on infrastructure you control. For production volume, run it in queue mode. In n8n's queue mode documentation, "The main n8n instance handles timers and webhook calls, generating (but not running) a workflow execution", and Redis holds the queue of pending executions so the next available worker picks each one up. You switch it on by setting EXECUTIONS_MODE to queue on the main instance and every worker, and you add workers as volume grows, so one slow workflow does not hold up the rest.

Move the database to Postgres before you switch queue mode on. By default n8n saves credentials, past executions and workflows in SQLite (n8n's database settings), and the queue mode page says that running queue mode "with an SQLite database isn't recommended". Postgres also gives the agent a place to keep its chat history, which the next section needs.

For regulated data, where n8n runs decides which agreements apply: self-hosted in your own AWS or Google Cloud account, it runs under the business associate agreement you hold with that provider. Prune execution data on a schedule, so personal data does not pile up in the logs.

Keep the agent's memory in Postgres

The AI Agent node sits at the centre of the workflow. Per n8n's AI Agent node documentation, you "Connect a chat model and one or more tools, and the agent decides which tools to call to complete a task", and you must connect at least one tool sub-node. The chat model can be Claude, an OpenAI model or a model you host.

Memory needs a different node in production. Simple Memory, the node earlier n8n versions called Window Buffer Memory, keeps chat history in the workflow, and on a queue-mode instance it "doesn't work in an active production workflow", because n8n can't guarantee that every call reaches the same worker (Simple Memory documentation). Postgres Chat Memory stores the history in a Postgres table instead, so every worker reads the same conversation, and its Context Window Length sets how many previous interactions the agent sees (Postgres Chat Memory documentation).

A production build sets up each of these nodes before the agent sees live input:

  • Trigger node: a webhook, an email or an ERP event starts the run; protect a webhook with header, basic or JWT authentication and check the payload before the agent sees it.
  • AI Agent node: runs the reasoning loop, calls the tools and passes its output on.
  • Chat model sub-node: the connection to the model provider your security team approved.
  • Memory sub-node: Postgres Chat Memory, so every worker reads the same chat history.
  • Tool sub-nodes: the APIs, database queries and internal services the agent may call; give the agent a fixed list of actions with the permissions your people already have, and check what each tool returns.

Design for the unhappy path

Plan for every external dependency to fail at some point, and give each failure its own branch. Turn on Retry On Fail for each node that calls a model or an API: "When an execution fails, the node reruns until it succeeds" (n8n's node settings). Where a retry will not fix the failure, set the node's On Error to Continue (using error output), which passes the error information to the next node, so a branch of your own handles it. Check the model's output before the next step uses it, and when it does not parse, fail the run on purpose with the Stop And Error node, which starts the error workflow.

A failed run then has to reach a person. Per n8n's error handling documentation, you set an error workflow for each workflow in Workflow Settings, it "runs if an execution fails", it must start with the Error Trigger, and one error workflow can serve many workflows. Have it send a Slack or email alert to a person, and log each run's metadata to Postgres, so you can trace a failure without replaying the whole workflow.

Check every draft before it ships

Build the guardrails into the first version, before launch. A second agent reads each draft the AI Agent node writes and checks it against your rules before anything reaches the user. A draft that passes goes out as the reply to the user, and a draft that breaks a rule goes back for a rewrite, with the violation and the fix. At Pinkcube the second agent, the Gatekeeper, passes a draft or sends it back up to ten times, and only text the Gatekeeper passes reaches the customer (the Pinkcube case study).

An action needs a check of its own, before it runs. n8n lets you "require human approval before an AI Agent executes a specific tool", on all of the agent's tools or only the ones you choose. The reviewer approves or denies the request in n8n's chat, in Slack or by email; approval runs the tool with the input the agent gave, and a denial cancels the action and tells the agent (n8n's human-in-the-loop documentation). Use it for any tool that sends, writes or deletes. For an approval step outside the agent, the Wait node pauses the run, offloads the execution data to the database and resumes when it receives an HTTP call (Wait node documentation).

Ovidius builds AI agents on self-hosted n8n in your cloud, behind your own sign-in. A failed step retries, then alerts your team in Slack and by email, and where a wrong answer would cost money or trust, a second AI model reviews each output before it goes out. A senior partner scopes the first agent with you, and the scope gives you the timeline before you commit.

Two n8n agents Ovidius built

Pinkcube sells branded merchandise to Dutch and Belgian businesses, and its chat desk was staffed 45 hours a week. The agent Ovidius built on n8n answers in Dutch or English, checks live order status and files a pre-sorted HubSpot ticket when it cannot help, and now covers all 168 hours of the week. Before launch it faced 76 hostile test scenarios, and 64 of them scored 5 out of 5. The chat agent has no ticket permissions at all. A separate triage agent reads the finished conversation and creates the ticket wherever the chat agent made a promise (the Pinkcube case study).

The second build is a content pipeline for an e-commerce product customisation platform that wanted to rank for hundreds of long-tail keywords without adding headcount. Ovidius designed and built a pipeline of AI agents on n8n: research agents pull keyword, competitor and search result data, a brief agent sets the structure, and content agents write, check and polish the article. A keyword becomes a publish-ready article in 29 minutes, in about 33 n8n executions (the case study).

In both builds, n8n orchestrates every step and a check runs before a customer or a reviewer sees the output: the Gatekeeper at Pinkcube, and the content agents' fact-checking passes in the content pipeline. Before you build, check that n8n fits your job. Ovidius's platform comparison scores eight platforms against the same four jobs, and rates n8n a good fit for an agent that works through a queue of tasks.

Compare before you build
AI Agent Platform Comparison

n8n, Zapier, Sim, Copilot Studio and four more, side by side.

Compare platforms

Frequently asked questions

What does the AI Agent node in n8n do?

It connects a chat model to one or more tools, and the agent decides which tools to call to complete a task, as n8n's AI Agent node documentation puts it. You must connect at least one tool sub-node, and the chat model can be Claude, an OpenAI model or a model you host. In production it also takes a memory sub-node that keeps chat history in Postgres.

Does Simple Memory work in queue mode?

No. On a queue-mode instance, Simple Memory does not work in an active production workflow, because n8n can't guarantee that every call reaches the same worker. Use Postgres Chat Memory instead: it stores chat history in a Postgres table that every worker reads, and its Context Window Length sets how many previous interactions the agent sees.

What database does n8n use by default?

SQLite. By default n8n saves credentials, past executions and workflows in SQLite, and it also supports Postgres. n8n's queue mode documentation says running queue mode with an SQLite database isn't recommended, so move to Postgres before you set EXECUTIONS_MODE to queue on the main instance and every worker.

How do I get alerted when an n8n workflow fails?

Set an error workflow. In the workflow's Workflow Settings, choose an error workflow that starts with the Error Trigger. Per n8n's error handling documentation, n8n runs it when an execution fails, and you can point other workflows at the same error workflow. Have it send a Slack or email alert to a person. To fail a run on purpose, for example when the model's output does not parse, add the Stop And Error node.

Can a person approve an agent's action before it runs?

Yes. n8n can require human approval before an AI Agent executes a specific tool, on all of its tools or only the ones you choose. The reviewer approves or denies the request in n8n's chat, in Slack or by email. Approval runs the tool with the input the agent gave, and a denial cancels the action and tells the agent. Use it for any tool that sends, writes or deletes.

What happens to a draft the second agent rejects?

It goes back to the AI Agent node for a rewrite, with the violation and the fix, and only a draft that passes goes out as the reply to the user. In the Pinkcube case study, the second agent, the Gatekeeper, checks every chat reply this way and can send a draft back up to ten times before the customer sees a word.

Building an AI agent on n8n?

Book a discovery call. A senior partner leads your workflow from the first call and scopes the first agent with you.

More on this topic

Put your first workflow on the board

Answer a few questions about your team and what you want automated, then a senior partner scopes it with you on the call.