Building autonomous AI agents that can make decisions, use tools, and maintain context across conversations presents significant challenges for full-stack developers. You need to orchestrate multiple AI models, manage state persistence, handle API integrations, and ensure your agents can scale under production load. Traditional approaches require extensive backend infrastructure and complex state management logic that pulls focus from shipping features.
This guide walks through the technical implementation of AI agents in n8n, from initial setup through production deployment. You'll configure LLM integrations, implement memory management for stateful conversations, connect external tools and APIs, and deploy scalable agent systems using queue-based architecture.
In brief:
Before building AI agents with n8n, you need:
n8n implements AI agent functionality through a hierarchical node system built on the LangChain JavaScript framework. The architecture separates root nodes (cluster nodes) that define main agent logic from sub-nodes that provide specific capabilities like language model integration, memory management, and tool execution.
The platform supports four primary architectural patterns for AI workflows. Chained requests execute sequential AI model calls with intermediate processing, reducing API costs by 30-50% compared to monolithic agent calls through selective model invocation. Single agent with state maintains context throughout workflow execution using memory nodes, making it ideal for conversational interfaces.
Multi-agent with gatekeeper implements centralized control with specialized agent delegation in a modular and scalable architecture. Multi-agent teams enable parallel specialized agents that collaborate on complex tasks with distributed decision-making.
At the core, every AI agent workflow in n8n requires four key components that work together as a hierarchical system. Trigger nodes (such as Webhook, Scheduler, or HTTP request nodes) initiate execution.
The AI Agent node serves as the orchestration layer, using LangChain-powered reasoning to make decisions and determine which tools to use based on user input and available capabilities.
Sub-nodes connect to the agent and provide critical capabilities: a language model integration node (for LLM access), memory nodes for maintaining context across interactions, and tool nodes that provide external APIs and functions the agent can invoke. Output nodes process the agent's responses and route them to downstream systems or user interfaces.
The workflow engine executes nodes sequentially or in parallel based on your configuration, with data flowing as JSON objects from node outputs to node inputs. This design lets you compose complex agent behaviors by connecting pre-built nodes rather than implementing orchestration logic from scratch.
The fastest path to a production-ready n8n instance uses Docker Compose with PostgreSQL. Create a project directory and a .env file with your configuration:
1DOMAIN_NAME=yourdomain.com
2SUBDOMAIN=n8n
3GENERIC_TIMEZONE=America/Los_Angeles
4POSTGRES_PASSWORD=your-secure-password
5N8N_ENCRYPTION_KEY=your-32-character-keyCreate a docker-compose.yml file with PostgreSQL and n8n services:
1version: '3.8'
2
3services:
4 postgres:
5 image: postgres:15
6 restart: unless-stopped
7 environment:
8 - POSTGRES_USER=n8n
9 - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
10 - POSTGRES_DB=n8n
11 volumes:
12 - postgres-data:/var/lib/postgresql/data
13 healthcheck:
14 test: ['CMD-SHELL', 'pg_isready -U n8n']
15 interval: 10s
16 timeout: 5s
17 retries: 5
18
19 n8n:
20 image: docker.n8n.io/n8nio/n8n:2.1.4
21 restart: unless-stopped
22 ports:
23 - "5678:5678"
24 environment:
25 - DB_TYPE=postgresdb
26 - DB_POSTGRESDB_HOST=postgres
27 - DB_POSTGRESDB_DATABASE=n8n
28 - DB_POSTGRESDB_USER=n8n
29 - DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}
30 - N8N_HOST=${SUBDOMAIN}.${DOMAIN_NAME}
31 - N8N_PORT=5678
32 - N8N_PROTOCOL=https
33 - WEBHOOK_URL=https://${SUBDOMAIN}.${DOMAIN_NAME}/
34 - N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY}
35 - N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true
36 - N8N_RUNNERS_ENABLED=true
37 - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
38 - TZ=${GENERIC_TIMEZONE}
39 - NODE_ENV=production
40 volumes:
41 - n8n-data:/home/node/.n8n
42 depends_on:
43 postgres:
44 condition: service_healthy
45
46volumes:
47 postgres-data:
48 n8n-data:Start your services:
1docker-compose up -dAccess the web interface at http://localhost:5678 and complete the initial setup wizard. The installation uses version 2.1.4, released December 23, 2025, which includes security hardening and enhanced credential encryption.
The N8N_RUNNERS_ENABLED parameter activates task runners for improved workflow execution, while N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS enforces secure file permissions required for production deployments.
Building your first agent starts with the Chat Trigger node, which captures user input and initializes conversation sessions. Add a Chat Trigger to your workflow canvas. This node outputs a JSON object containing chatInput (the user's message) and sessionId (a unique identifier for conversation context).
Add an AI Agent node to handle orchestration and decision-making. Configure the system prompt to define your agent's behavior:
1{
2 "parameters": {
3 "promptType": "define",
4 "text": "You are a helpful assistant that can answer questions and take actions using available tools. When users ask about content management, reference relevant features and capabilities.",
5 "hasOutputParser": false
6 }
7}Connect the Chat Trigger to the AI Agent through the main connection. The agent receives input from the trigger and processes it using the connected language model and tools. This separation between trigger, orchestration, and language model provides flexibility to swap models or add capabilities without rebuilding your entire workflow.
You can test the basic structure before adding language model integration by creating a simple response workflow. The Chat Trigger passes user input to the AI Agent, which requires an LLM sub-node to generate actual responses.
This modular architecture mirrors how you might structure a modern web application with separated concerns between routing, business logic, and data access layers.
Language model integration with n8n's AI Agent nodes occurs through specialized Chat Model sub-nodes that connect via the ai_languageModel connection type. The platform supports a comprehensive range of LLM providers including OpenAI (GPT-4, GPT-3.5-turbo), Anthropic Claude (Claude 3 family), HuggingFace inference models, Google Gemini, Cohere, and local models via Ollama, with each provider accessible through dedicated integration nodes.
For OpenAI integration, add an OpenAI Chat Model node to your workflow. Configure your API credentials in n8n's credential system by navigating to Settings and adding an OpenAI API credential with your key from platform.openai.com. Return to your workflow and configure the model parameters:
1// OpenAI Chat Model Configuration
2{
3 "name": "OpenAI Chat Model",
4 "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
5 "parameters": {
6 "model": "gpt-4",
7 "options": {
8 "temperature": 0.7,
9 "maxTokens": 1000,
10 "frequencyPenalty": 0.0,
11 "presencePenalty": 0.0
12 }
13 },
14 "credentials": {
15 "openAiApi": {
16 "name": "OpenAI Account"
17 }
18 }
19}Connect the OpenAI Chat Model to the AI Agent through the language model connection. The temperature parameter (0.0 to 2.0) controls response randomness, with lower values producing more deterministic outputs and higher values increasing creativity.
The maxTokens parameter limits response length to control API costs and processing time. Additional configuration parameters include topP for nucleus sampling, frequencyPenalty and presencePenalty for controlling token repetition and topic diversity respectively.
For Anthropic Claude integration, add an Anthropic Chat Model node with similar configuration. Claude models use a temperature range of 0.0 to 1.0 and require a maxTokens parameter. The model selection accepts identifiers like "claude-3-opus-20240229" or "claude-3-sonnet-20240229" depending on your performance requirements.
The AI Agent automatically handles the communication protocol with your chosen language model, sending conversation history and tool information according to each provider's API specification. You can swap between providers by disconnecting one Chat Model node and connecting another without modifying the agent configuration. This abstraction proves valuable when you need to compare model performance or optimize costs across different tasks.
AI agents in n8n can be implemented with or without memory management. Agents without memory sub-nodes (such as Window Buffer Memory or Buffer Memory nodes) operate without conversation history, making them unsuitable for conversational interfaces or workflows requiring historical awareness.
Memory nodes solve this by connecting to AI Agent nodes as sub-nodes and storing conversation history through configurations like context windowing and session management, making them available to the agent during processing.
Add a Window Buffer Memory node to your workflow and configure it with session management:
1// Window Buffer Memory Configuration
2{
3 "name": "Window Buffer Memory",
4 "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
5 "parameters": {
6 "sessionKey": "={{ $json.sessionId }}",
7 "contextWindowLength": 10
8 }
9}Connect the memory node to the AI Agent through the ai_memory connection type. The sessionKey parameter uses the session identifier from the Chat Trigger to associate memory with specific users or conversation threads. The contextWindowLength parameter is configurable to maintain a set number of messages in conversation history (for example, 10 messages), balancing context retention with token usage optimization.
The agent automatically includes relevant conversation history in its prompts to the language model, enabling it to reference previous exchanges and maintain coherent multi-turn conversations.
This pattern works for chatbot implementations that need to remember user preferences, ongoing tasks, or conversation context across sessions, as supported through n8n's memory management system including Window Buffer Memory and Chat Memory Manager nodes for maintaining conversation state.
For production deployments requiring long-term memory persistence, integrate vector database nodes like Qdrant or Pinecone. These enable retrieval-augmented generation patterns where agents can search through large knowledge bases and retrieve relevant information based on semantic similarity. Configure a Simple Vector Store node in retrieve mode and connect it to your AI Agent as a memory source for document-based context retrieval.
Tools extend agent capabilities beyond text generation by enabling actions like API calls, database queries, and custom logic execution. Tool nodes connect to the AI Agent through the ai_tool connection type, and the agent autonomously decides when to invoke them based on tool descriptions and user requests.
Built-in tool nodes include the Calculator Tool, Code Tool, HTTP Request Tool, Workflow Tool for calling other n8n workflows, SerpAPI Tool for web search, and Wikipedia Tool for knowledge retrieval, while app integration tools provide access to services like Google Drive, Gmail, Notion, and Slack.
Add an HTTP Request Tool to your workflow for external API integration:
1// HTTP Request Tool Configuration for CMS Content Retrieval
2{
3 "name": "Get Content Tool",
4 "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
5 "parameters": {
6 "name": "get_content",
7 "description": "Retrieve content from the CMS API. Input should be a content type slug like 'articles' or 'pages'. Returns populated content entries with all related fields.",
8 "method": "GET",
9 "url": "={{ $env.CMS_API_URL }}/api/{{ $json.contentType }}",
10 "authentication": "genericCredentialType",
11 "sendQuery": true,
12 "queryParameters": {
13 "parameters": [
14 {
15 "name": "populate",
16 "value": "*"
17 },
18 {
19 "name": "pagination[pageSize]",
20 "value": "{{ $json.limit || 10 }}"
21 }
22 ]
23 },
24 "options": {
25 "timeout": 30000,
26 "retry": {
27 "maxTries": 3,
28 "waitBetweenTries": 1000
29 }
30 }
31 }
32}Technical Configuration Notes:
This HTTP Request Tool integrates with CMS APIs (such as Strapi) as a callable function within AI Agent workflows. The tool configuration enables:
contentType parameter passed by the AI agent populate: "*") to retrieve all related fields and nested content Integration Pattern:
This tool connects to an AI Agent node through the ai_tool connection type, allowing autonomous agents to dynamically retrieve content based on user queries. The agent's natural language understanding determines when to invoke this tool, using the description to understand its purpose and required inputs.
Production Recommendations:
For self-hosted instances, external modules can be used by setting NODE_FUNCTION_ALLOW_EXTERNAL=true. For n8n Cloud deployments, ensure credentials are stored using the platform's credential management system rather than hardcoded in workflow definitions. The timeout and retry parameters are critical for production reliability when calling external CMS APIs that may experience temporary latency or failures.
The name and description parameters are critical because the AI Agent uses them to determine when to invoke the tool. Write descriptions that clearly specify what the tool does, what input format it expects, and the expected output format. The agent analyzes user requests, compares them against available tool descriptions, and selects appropriate tools to accomplish the task.
Add a Calculator Tool for mathematical operations:
1// Calculator Tool Configuration
2{
3 "name": "Calculator Tool",
4 "description": "Performs basic mathematical calculations. Input should be a math expression like '2 + 2' or '15 * 3'."
5}This tool can be integrated into AI Agent workflows as a sub-node tool to enable autonomous mathematical calculations during agent decision-making processes.
For custom business logic in AI agent workflows, use Code Tool nodes or Code nodes that execute JavaScript or Python:
JavaScript (Recommended):
$input.all(), $json, $binary) Python (For Specialized Libraries):
_input.all(), _json) Both execution modes run in a dedicated sandbox environment with security restrictions preventing unauthorized file system or network access. Use "Run Once for All Items" mode for batch processing or "Run Once for Each Item" mode for individual agent task processing. Execution history, debugging tools, and error logging via the Debug Helper node enable comprehensive development and troubleshooting of custom AI workflow logic.
1// Code Tool Implementation
2const contentTypes = $input.all();
3
4return contentTypes.map(item => ({
5 json: {
6 slug: item.json.attributes.slug,
7 title: item.json.attributes.title,
8 publishedAt: item.json.attributes.publishedAt,
9 formatted: `${item.json.attributes.title} (${item.json.attributes.slug})`
10 }
11}));In n8n, AI agents can autonomously chain multiple tool calls together to accomplish complex tasks through the Tools Agent node architecture. When a user asks "What articles were published this month?", the n8n AI Agent node—powered by LangChain—might first invoke an HTTP Request tool to query a database, then use a Code tool to filter results by date, and finally format the output through a downstream processing node.
This autonomous tool selection and chaining, orchestrated through n8n's sub-node tool connections and agent reasoning capabilities, distinguishes AI agents built in n8n from simple API wrappers or chatbots.
Your agents can integrate with content management workflows by connecting tools that query, create, or update content through your CMS API. Configure authentication using n8n's credential system and reference stored tokens or API keys using environment variables.
Production AI agent deployments require queue mode architecture for horizontal scaling. Queue mode separates the main instance that handles webhooks and UI from worker instances that execute workflows, enabling you to scale execution capacity by adding workers.
Add Redis to your Docker Compose configuration:
1services:
2 redis:
3 image: redis:7-alpine
4 restart: unless-stopped
5 volumes:
6 - redis-data:/data
7 healthcheck:
8 test: ['CMD', 'redis-cli', 'ping']
9 interval: 10s
10 timeout: 5s
11 retries: 5
12
13volumes:
14 redis-data:Configure the main instance and worker services:
1 n8n-main:
2 image: docker.n8n.io/n8nio/n8n:2.1.4
3 restart: unless-stopped
4 ports:
5 - "127.0.0.1:5678:5678"
6 environment:
7 - DB_TYPE=postgresdb
8 - DB_POSTGRESDB_HOST=postgres
9 - DB_POSTGRESDB_PORT=5432
10 - DB_POSTGRESDB_DATABASE=n8n
11 - DB_POSTGRESDB_USER=n8n
12 - DB_POSTGRESDB_PASSWORD=${DB_PASSWORD}
13 - N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY}
14 - N8N_HOST=${N8N_HOST}
15 - N8N_PROTOCOL=https
16 - WEBHOOK_URL=https://${N8N_HOST}/
17 - EXECUTIONS_MODE=queue
18 - QUEUE_BULL_REDIS_HOST=redis
19 - QUEUE_BULL_REDIS_PORT=6379
20 - QUEUE_HEALTH_CHECK_ACTIVE=true
21 - N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true
22 - N8N_RUNNERS_ENABLED=true
23 depends_on:
24 - redis
25 - postgres
26 volumes:
27 - n8n_data:/home/node/.n8n
28
29 n8n-worker:
30 image: docker.n8n.io/n8nio/n8n:2.1.4
31 command: worker
32 environment:
33 - EXECUTIONS_MODE=queue
34 - QUEUE_BULL_REDIS_HOST=redis
35 - QUEUE_BULL_REDIS_PORT=6379
36 - DB_TYPE=postgresdb
37 - DB_POSTGRESDB_HOST=postgres
38 - DB_POSTGRESDB_PORT=5432
39 - DB_POSTGRESDB_DATABASE=n8n
40 - DB_POSTGRESDB_USER=n8n
41 - DB_POSTGRESDB_PASSWORD=${DB_POSTGRESDB_PASSWORD}
42 - N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true
43 - N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY}
44 - GENERIC_TIMEZONE=America/Los_Angeles
45 - TZ=America/Los_Angeles
46 deploy:
47 replicas: 3
48 depends_on:
49 - redis
50 - postgres
51
52volumes:
53 redis-data:
54 n8n_data:This configuration creates one main instance and three workers. The main instance receives webhook triggers and API requests, adds workflow executions to the Redis queue, and workers pull tasks for execution.
Scale horizontally by adjusting the replicas parameter based on load. Queue mode architecture achieves significantly higher throughput than single-instance deployments—a single instance in standard mode handles up to 100 concurrent workflow executions, while queue mode with three workers on a C5.large instance processes approximately 72 requests per second with less than 3-second latency and zero failures under load.
Monitor your deployment using n8n's built-in health check endpoints. Configure Docker health checks to ensure service availability.
For production deployments requiring high availability, deploy n8n on Kubernetes using managed services like AWS EKS, Google Kubernetes Engine, or Azure Kubernetes Service. The same Docker images work across platforms, and you can use Helm charts or custom manifests to define your deployment topology.
Implement proper SSL/TLS termination using a reverse proxy like Nginx or Caddy. Bind n8n to localhost (127.0.0.1:5678) for security, and configure your reverse proxy to listen on ports 80 and 443. With Caddy, the reverse proxy automatically provisions and renews SSL certificates through Let's Encrypt—simply configure your domain in the Caddyfile and Caddy handles certificate provisioning without manual intervention.
For Nginx, integrate with Let's Encrypt using certbot or similar tools. First configure your domain DNS to point to the reverse proxy (not directly to n8n), wait for DNS propagation to complete, then enable SSL/TLS configuration on the reverse proxy. The reverse proxy will handle all certificate management and HTTPS traffic, while n8n communicates securely with it over the local network.
Secure your deployment by restricting network access to internal services. Bind PostgreSQL and Redis to internal networks only, exposing only the n8n web interface through your reverse proxy. Use n8n's credential management system for storing API keys and sensitive configuration rather than environment variables, and enable role-based access control through n8n's user management system introduced in version 2.0.
Connect your AI agents to Strapi CMS through webhooks configured in Strapi's settings to trigger automated workflows on content events like entry creation, updates, or publication. The n8n Strapi node supports Create and Update operations, allowing you to build workflows that process content with AI models and update your CMS accordingly.
For example, you could configure an n8n workflow triggered by Strapi's entry.create webhook event to pass the content through an OpenAI or Anthropic language model for processing, then use the Strapi node's Update operation to store AI-generated enhancements back to the original entry.
Configure API Token authentication in both systems to prevent unauthorized workflow triggers, using Strapi's granular API token permissions to limit n8n integration access to only necessary content types.
Your deployed AI agents can integrate with API-driven architectures through n8n's comprehensive REST API and HTTP Request nodes, enabling direct communication with backend services and external APIs. This capability allows agents to participate in broader application workflows by responding to events from frontend applications, mobile apps, or other backend services.
When combined with n8n's 500+ pre-built integrations and queue-based execution model, agents can reliably orchestrate complex multi-service workflows while maintaining the scalability and reliability benefits of the queue-based architecture, which supports up to 220 workflow executions per second on a single instance.
Building AI agents with n8n gives you production-ready workflow automation with LangChain integration, enabling autonomous decision-making systems that scale horizontally through queue-based architecture. Your agents can orchestrate multiple language models, maintain conversation context through memory systems, and execute actions across your stack through tool integrations.
To extend your implementation, explore n8n's workflow templates for pre-built agent patterns, or integrate your agents with Strapi's plugin marketplace for additional capabilities. Start by deploying the Docker Compose configuration from this guide, then examine the self-hosted AI starter kit to extend your agent capabilities with local LLM hosting and vector databases.
For production optimization, review n8n's official scaling documentation and consider implementing monitoring solutions like Prometheus for workflow observability. Test your agent's performance under production load using tools like Apache Benchmark or k6 to validate your deployment architecture. Join the Strapi community to share your AI agent implementations and discover advanced integration patterns from other developers building autonomous systems.
npx create-strapi-app@latest in your terminal and follow our Quick Start Guide to build your first Strapi project.