How to Set Up an AI Agent with n8n (Step-by-Step Guide)
n8n AI Agent The n8n AI Agent node combines an LLM, tools, and memory components in a ReAct loop, enabling you to build enterprise-grade AI agents without writing code. This guide provides a complete roadmap for setting up a working agent from zero.
What Is the n8n AI Agent?
The n8n AI Agent node is a specialized workflow node that combines a large language model with a tool list and an optional memory component. The agent automatically runs the LLM query–tool call loop until it reaches the goal or hits a step cap.
Unlike traditional automation tools that follow a fixed rule sequence, the n8n AI Agent node uses dynamic decision-making. The node passes user input to the LLM; the LLM decides which tool to call, receives the tool's output, and repeats the loop if necessary. This pattern is known in the literature as ReAct (Reasoning and Acting) or function-calling.
For a broader perspective on n8n's enterprise workflow automation capabilities, it is recommended to understand the core architecture first. The AI Agent node integrates fully with n8n's standard node ecosystem: the trigger can be a Chat Trigger, Webhook, or any data source.
Four key components determine agent behavior: the chat model (LLM), the tool list (tools), memory, and the system prompt. Correctly configuring these components directly affects both the agent's functionality and its reliability.
Required Components: LLM, Tools, Memory, and Vector Store
A working n8n AI Agent requires at minimum four components: an LLM provider credential, at least one tool definition, an optional memory node, and a goal-oriented system prompt. A vector store is added as an additional component for RAG scenarios.
Choosing the LLM provider is the most critical decision affecting both the agent's performance and operational cost. The table below summarizes the providers supported by n8n as of May 2026 and their key characteristics.
| Provider | Model Examples | Hosting | Operational Note |
|---|---|---|---|
| OpenAI | GPT-4o, GPT-4.1, o3 | Cloud (API) | Wide tool support; stable JSON mode |
| Anthropic | Claude Sonnet 4, Claude Opus 4 | Cloud (API) | Long context; enterprise security focus |
| Mistral AI | Mistral Large, Codestral | Cloud / Self-hosted | European data sovereignty; cost advantage |
| Google Vertex AI | Gemini 2.5 Pro, Gemini Flash | Cloud (GCP) | Strong GCP integration; multimodal |
| Ollama | Llama 3.3, Mistral, Phi-4 | Local / On-premise | Maximum data privacy; requires GPU |
| OpenAI-Compatible Endpoint | Any LM Studio, vLLM model | Self-hosted | Flexible for custom fine-tuned models |
Tools allow the agent to take real-world actions beyond what the LLM can produce on its own. A tool can be an n8n sub-workflow, an HTTP Request node, or a database query. The Memory node stores previous messages as context for the LLM in multi-turn conversations, enabling the agent to 'remember.' When a vector store is integrated, the agent gains a tool for semantic search over a knowledge base (RAG).
Step by Step: Build Your First AI Agent
An n8n AI Agent workflow consists of a trigger node, an AI Agent node, a chat model connection, and at least one tool definition. All components can be configured in the n8n interface via drag-and-drop in a matter of minutes.
Step 1: Choose a trigger. Use the Chat Trigger node for testing via a chat interface. In production, a Webhook Trigger or scheduled Cron Trigger may also be appropriate. The Chat Trigger activates n8n's built-in chat interface and is ideal for rapid prototyping.
Step 2: Add the AI Agent node. Search for 'AI Agent' in the node panel and drag it into your workflow. This node has three sub-connection points: Chat Model (required), Memory (optional), and Tools (optional but recommended).
Step 3: Connect a Chat Model. Connect an OpenAI Chat Model node or your preferred provider node to the Chat Model input of the AI Agent node. Your credentials (API key) must be defined in advance in the n8n Credentials panel.
Step 4: Write a system prompt. Fill in the 'System Message' field in the AI Agent node configuration. This field defines the agent's role, which tools to use and when, and the response format. Example: 'You are the Sora Software customer support assistant. Use the database tool only for order queries.'
Step 5: Add at least one tool. Connect a 'Calculator' (built-in) or a custom Sub-workflow node to the Tools connection point. Each tool must have a clear name and description; the LLM uses these descriptions to decide which tool to select.
Step 6: Test it. Click the 'Chat' button to open n8n's built-in chat interface and type a question. The execution log shows which tools the LLM called, how many times, and what data it used at each step.
| Step | Node / Component | Required? | Description |
|---|---|---|---|
| 1 | Chat Trigger / Webhook | Yes | Receives user input |
| 2 | AI Agent | Yes | Central agent node; manages the ReAct loop |
| 3 | Chat Model (e.g. OpenAI) | Yes | Establishes the language model connection |
| 4 | System Message | Recommended | Defines the agent's role and constraints |
| 5 | Tool (Sub-workflow, HTTP, etc.) | Recommended | Gives the agent real-world capabilities |
| 6 | Memory Node | No (yes for multi-turn) | Preserves conversation history |
Tool Usage: Sub-Workflow, HTTP Request, and Database
To add tools to an n8n AI Agent, any n8n node or sub-workflow can be connected to the Tools connection point. The LLM independently decides which tool to call and when, based on the system prompt and tool descriptions.
Sub-workflow tools are the most powerful configuration option. When you define a separate n8n workflow as a tool via the Execute Workflow node, you expose all of that workflow's logic (conditions, loops, multiple API calls) as a single tool. This approach is the cleanest way to make complex business processes accessible to the agent.
You can connect to external systems using the HTTP Request node for webhook and API integration. For example, you can define HTTP Request nodes that fetch customer data from a CRM API, create an invoice in an accounting system, or close a support ticket as tools. Keep each tool's 'description' field clear and precise — the LLM reads it to decide when to use the tool.
For database tools, you can connect Postgres, MySQL, or MongoDB nodes directly as tools. The security best practice is to assign a read-only database user to tool nodes and grant write permissions only after a separate approval step when needed. Enterprise n8n use cases commonly include such hybrid agent-database workflows.
Tool naming directly impacts performance: clear, action-oriented names like 'get_customer_orders' produce far better LLM decisions than vague names like 'tool1'. In each tool description, specify what input is expected and what output will be returned.
Memory and Context Management
Memory management in the n8n AI Agent is handled through the Memory node. This node stores conversation history and passes it to the LLM at each new turn, allowing the agent to maintain context and produce consistent responses across a multi-turn conversation.
Memory types supported in n8n include Window Buffer Memory (retains the last N messages), Token Buffer Memory (stays within a token limit), and external store-based memory options (Redis, Postgres). External stores are recommended for enterprise environments so that conversation history is preserved when the agent restarts.
When configuring the Memory node, pay attention to the 'Session ID' field. This field ensures that different users or different conversations are kept separate. The most common practice in webhook-driven conversations is to use the user identifier (such as an email address or session token) as the Session ID.
Setting a token limit to prevent the context window from filling up is critical in long conversations. While models like OpenAI GPT-4o support 128k token context, every token adds to processing cost. Retaining the last 10–20 messages with Window Buffer Memory is sufficient for most enterprise use cases and keeps costs predictable.
RAG-Augmented AI Agent
By adding a Vector Store tool to the n8n AI Agent, you can implement a Retrieval-Augmented Generation (RAG) architecture. In this setup, the agent first searches the vector database for the user's question, retrieves relevant documents, and passes this context to the LLM to generate source-backed responses.
A comprehensive guide on building a RAG-based AI chatbot with n8n is available separately. Here we focus on the key integration point: when you connect a Pinecone, Qdrant, or PGVector node to the AI Agent node's 'Vector Store Retriever' input, the agent gains a tool capable of semantic search over that knowledge base.
Write the RAG tool description carefully when adding it to the tool list. A description such as 'Searches the internal document base; provides access to product manuals, procedure documents, and FAQ content' ensures the LLM calls this tool in the right context.
In enterprise RAG setups, it is also recommended to automate the document update process. By creating a separate 'Document Ingest' workflow in n8n, you can automatically convert new documents to embeddings and write them to the vector database. This workflow can be triggered from SharePoint, Confluence, or an internal file server.
Enterprise Scenarios and AI Evaluations
n8n AI Agents are used in enterprise scenarios including customer support automation, internal process management, data analysis assistants, and multi-step approval workflows. The AI Evaluations feature lets you systematically measure agent and RAG performance against a test dataset.
Customer support agents are the most common enterprise use case. The agent classifies an incoming support request, queries the customer history from the CRM, searches the document base for a resolution, and escalates to a human representative if necessary. All of these steps can be modeled as a single workflow in n8n.
Internal process agents automate repetitive business processes such as purchase approvals, leave requests, and project status updates. In these scenarios the agent reads relevant system data (ERP, HR software), checks the approval matrix, and sends the necessary notifications.
n8n's AI Evaluations feature compares agent responses against pre-defined correct answers and calculates precision, recall, and F1 scores. This feature is critical for testing agent behavior before going to production and for measuring how model changes affect performance.
| Scenario | Trigger | Tools Used | Expected Benefit |
|---|---|---|---|
| Customer Support Agent | Chat / Email Webhook | CRM Query, RAG, Create Ticket | 60% reduction in first response time |
| Internal Process Approval Agent | Form Webhook | ERP Read, Approval Matrix, Email | Eliminate manual approval steps |
| Data Analysis Assistant | Chat Trigger | SQL Query, Chart Generation, RAG | Self-serve analytics; lower BI cost |
| Document Processing Agent | File Upload Webhook | OCR, NLP, Database Write | Automate manual data entry |
In enterprise environments, it is strongly recommended to validate on a test set of at least 50–100 examples using AI Evaluations before going live. Based on Sora Software's field experience, projects that skip this step have a significantly higher probability of encountering unexpected agent behavior in production.
Frequently Asked Questions
What exactly is the n8n AI Agent node?
The n8n AI Agent node is a specialized workflow node that combines a large language model (LLM), a tool list, and optional memory and vector store components. It makes autonomous decisions via a ReAct or function-calling loop until it reaches the goal.
Which LLM providers does the n8n AI Agent support?
As of May 2026, supported providers include OpenAI, Anthropic, Mistral AI, Google Vertex AI, Ollama (local), and any OpenAI-compatible endpoint. You can also connect if you are running LM Studio or vLLM on your own server.
Do I need coding skills to set up an n8n AI Agent?
No coding knowledge is required to build a basic agent; all components are configured via the drag-and-drop interface. However, technical knowledge is useful for custom tool logic, advanced system prompts, or when using JavaScript/Python code nodes.
What does 'tool' mean in the context of an n8n AI Agent?
A tool is an n8n component that allows the agent to take real-world actions beyond what the LLM generates. An HTTP Request node, a database query, a sub-workflow, or built-in utilities like the Calculator can all be registered as tools.
How does the agent remember context across multiple conversation turns?
The Memory node (Window Buffer Memory, Token Buffer Memory, or external memory backed by Redis/Postgres) stores conversation history and passes it to the LLM at each new turn. A Session ID separates the history of different users.
Can I use a local model with Ollama?
Yes. By installing Ollama and adding the Ollama Chat Model node to n8n, you can run models such as Llama 3.3, Mistral, or Phi-4 entirely in a local environment. This approach is ideal for enterprise environments where data privacy is a priority, but requires GPU hardware.
How is the operational cost of an n8n AI Agent calculated?
Cost depends on the token pricing of the chosen LLM provider and the number of tokens consumed per agent run. Local models like Ollama generate no API cost; with cloud providers, additional token consumption per tool call must be considered. Token efficiency can be measured with AI Evaluations.
Conclusion
The n8n AI Agent node offers one of the most practical ways to integrate AI capabilities into enterprise automation projects without writing code. From LLM selection and tool definition to memory management, RAG integration, and performance measurement with AI Evaluations, all components can be managed on a single platform.
Ready to build your own n8n AI Agent infrastructure? Our Sora AI agent team offers a free discovery session covering custom agent architecture design, LLM selection, and enterprise integration.