Create an AI Agent with n8n : Tutorial, Costs, and Safeguards

Create an AI Agent with n8n : Tutorial, Costs, and Safeguards
8 min read

To create an AI agent with n8n, all you need is a workflow composed of a trigger, an AI Agent node, a language model, and at least one tool, all configured without code. The real work begins afterwards: limiting tools to the bare minimum, adding human validation, setting a maximum time limit, planning error handling, measuring the real cost of calls, and versioning the workflow. This tutorial walks through these steps with a simple example, including the settings to check before going into production.

The node and option names mentioned here come from the official n8n documentation consulted in November 2026, when the stable version was 2.47.7; the interface may change from one version to another. If you’re new to the topic, our reference guide on AI agents and automation explains what distinguishes an agent from a classic workflow and when each is justified.

Prepare n8n, an API key, and a bounded task

n8n exists in a version hosted by the publisher and a self-hosted version, distributed on GitHub under the Sustainable Use License. To test locally, the official repository provides a Docker command that launches the editor on port 5678 of your machine: docker run -it –rm –name n8n -p 5678:5678 -v n8n_data:/home/node/.n8n docker.n8n.io/n8nio/n8n. On the hosted side, the official pricing grid displayed in November 2026 a Starter plan at 20 euros per month and a Pro plan at 50 euros per month on annual billing, with 2,500 and 10,000 monthly executions respectively.

You then need an API key from the model provider (OpenAI, Anthropic or another supported provider), dedicated to this project, with a spending limit if the provider’s console allows it: in case of a loop or abuse, the bill will remain capped.

The example task

Our agent serves the sales team of a small company. In an internal chat window, a team member asks a question about an order; the agent consults the order spreadsheet, responds, and can prepare a draft email to the customer, which a human validates before any sending. It cannot modify the spreadsheet or send an email. If you haven’t yet finalized your platform or use case, our method for creating an AI agent without coding helps choose a limited process and define the expected outcome before touching n8n.

Connect a model and authorized tools

In n8n, an agent is a ‘root’ node to which sub-nodes are attached. The documentation for the AI Agent node specifies that, since version 1.82.0, all AI Agent nodes function as a tooled agent, and at least one tool must be connected. Assembly is done in five steps.

  1. Trigger: add a Chat Trigger node, which opens a conversation window and transmits each message to the agent.
  2. Agent: add the AI Agent node and leave the prompt source on ‘Take from previous node automatically’, so it receives the chat message.
  3. Model: attach the conversation model sub-node from your provider and select the identifier created with your API key.
  4. Memory: attach a memory sub-node so the agent keeps track of the conversation from one message to the next.
  5. Tools: attach a tool for reading the order spreadsheet, limited to the useful sheet, then a messaging tool limited to creating drafts.

In the agent’s options, fill in the System Message field: role, scope (questions about orders only), rules (never invent a status, cite the order number, politely refuse off-topic requests) and procedure when a tool is denied. The Max Iterations option, set to 10 by default, caps the number of loop turns; for such a simple task, a lower value limits the cost of an agent that might go in circles.

Add an external tool via MCP

If the service to be queried exposes an MCP server (Model Context Protocol, the open standard for connecting assistants to tools), the MCP Client Tool sub-node allows connection, with authentication via token, headers, or OAuth2. Its Tools to Include setting is crucial: choose ‘Selected’ and tick only the useful tools, rather than ‘All’, which would expose the server’s entire catalog to the agent. Software publishers are adopting this standard at high speed, as shown by the announcement from Adobe, which opens Photoshop and Premiere to agents via an MCP server; our guide ‘MCP: Understanding the Model Context Protocol and Its Uses’ will detail its architecture and risks. If the agent must respond from a document base rather than a spreadsheet, you will need to add a RAG-type search, covered in our article ‘RAG: Definition, Architecture, and Concrete Examples’.

Add human validation, a time limit, and error handling

Since version 2.6 from January 2026, n8n allows you to require human approval before a tool call. Open the tools panel from the agent’s Tools connector, add a human review step, choose the channel (n8n chat, Slack, Discord, Telegram, Microsoft Teams, Gmail, WhatsApp Business Cloud, Google Chat, or Outlook), then connect the draft creation tool after it. The review message can display the tool name and parameters chosen by the model using the $tool.name and $tool.parameters variables. If denied, the action is not executed and the agent is informed; specify in the System Message how it should respond in that case.

The maximum time limit is set in the workflow settings: enable Timeout Workflow and indicate a duration in Timeout After. In the same settings, the Error Workflow field designates a second workflow, which must start with the Error Trigger node, responsible for alerting you when an execution fails. At each node level, the Settings tab offers Retry On Fail to retry a failed call and On Error to choose between stopping the workflow, continuing, or continuing while sending the error to a dedicated output.

Grid of security settings

Risk n8n Setting Location
Unwanted action (incorrect draft, sending) Human review before the concerned tool Agent’s Tools panel
Agent going in circles Max Iterations AI Agent node Options
Blocked execution Timeout Workflow and Timeout After Workflow settings
API or model outage Retry On Fail, On Error Settings tab of each node
Silent failure Error Workflow with Error Trigger Workflow settings
Too many tools exposed Tools to Include set to ‘Selected’ MCP Client Tool sub-node

Test calls, costs, and logs

Temporarily enable the agent’s Return Intermediate Steps option: the output will then contain each intermediate step, allowing you to see which tool was called, with which parameters, and in what order. Prepare about ten test questions, including tricky cases: non-existent order number, off-topic question, message asking the agent to ignore its instructions, request for direct email sending. Replay each question several times and verify that none trigger action outside of human review.

For cost, record in each execution the number of calls to the model and the tokens consumed, which providers charge for input and output. As a theoretical example, with Claude Haiku 5.5, billed at $0.10 per million input tokens and $0.50 per million output tokens for prompts under 100,000 tokens according to the Anthropic pricing grid consulted in November 2026, a conversation of four calls with 3,000 input tokens and 300 output tokens costs about $0.002, or about $3.60 for 2,000 conversations per month. A more powerful model can multiply this amount by twenty or more, and tool definitions count towards input tokens. The AI agent cost calculator allows you to redo this calculation with your own measurements.

Errors that skew tests

  • Leaving Return Intermediate Steps active in production if the output is displayed to users.
  • Not keeping failed executions, while the Save failed production executions setting allows them to be analyzed.
  • Keeping personal data in logs, which the Redact production execution data and Redact manual execution data options allow to mask.

Update the workflow in production

Before each modification, export the workflow in JSON format from the Workflow menu: this is your rollback point. The documentation on export warns that this file contains connection names and identifiers, and that an HTTP Request node imported from a cURL command may contain authentication headers: review and anonymize the JSON before sharing or versioning it in a repository.

The secrets themselves remain in n8n. According to the documentation on the encryption key, n8n encrypts connection credentials before saving them to the database, with a key generated at first launch and stored in the ~/.n8n folder, or provided by the N8N_ENCRYPTION_KEY environment variable. When self-hosting, back up this key with the database: without it, a restored database becomes unusable. Updates then follow a fixed order: modification, new pass on test questions, comparison with the previous version using n8n’s version history, then publication.

Check the result after the update

In the following days, monitor three signals in the execution list: the share of failed executions, the average number of iterations per conversation, and the share of drafts rejected during human review. An increase in one of them after an update justifies a rollback to the previous export. The limit of this monitoring is that it only detects what leaves a trace: a false but plausible response generates no error, hence the value of regularly reviewing a sample of conversations.

S’abonner
Notification pour
guest

0 Commentaires
Le plus ancien
Le plus récent Le plus populaire
0
Nous aimerions avoir votre avis, veuillez laisser un commentaire.x