You’ve heard about AI agents. You know they can automate work, answer questions, and connect to your tools. But most guides either skip the setup entirely or assume you already have everything running.
Not this one.
By the time you finish reading, you’ll have a working n8n AI agent — installed, configured, and executing its first workflow. No gaps. No “figure it out yourself” moments.
Here’s the path: Install → Configure Credentials → Build Your First Agent. Let’s go.
Before You Start: Cloud vs. Self-Hosted
Before installing anything, you need to answer one question: where will your n8n live?
n8n gives you two paths:
| n8n Cloud | Self-Hosted (Docker) | |
|---|---|---|
| Setup time | Under 5 minutes | 15–30 minutes |
| Cost | Free tier available; paid plans from €20/month | Your server costs only |
| Maintenance | Zero — n8n handles updates, backups | You manage everything |
| Data control | n8n’s infrastructure | Your infrastructure |
| AI agent support | Full | Full |
| Best for | Getting started fast, teams that don’t want DevOps | Businesses with compliance needs, high-volume workflows |
The short answer: If you’re learning or prototyping, start with n8n Cloud. If you’re building something that handles sensitive data or needs to scale, go self-hosted. This guide covers both.
One thing to know: n8n AI agents require n8n version 1.60 or later. Cloud instances are always current. Self-hosted users — pin your Docker image to a specific version. Never use the
latesttag in production. More on that in Step 1.
Step 1: Install n8n
Option A: n8n Cloud (Under 5 Minutes)
This is the fastest path to a working AI agent.
- Go to app.n8n.cloud and create an account.
- Verify your email.
- That’s it. You’re on the latest n8n version with AI agent support built in.
Your instance is live at https://[your-subdomain].n8n.cloud. Bookmark it — you’ll need it in Step 3.
Option B: Docker Self-Hosted (Production-Ready)
If you’re self-hosting, do it right from day one. The default docker run command uses SQLite and an ephemeral encryption key — fine for testing, but it will break under any real load.
Here’s a production-ready Docker Compose setup with PostgreSQL:
# docker-compose.yml
version: '3.8'
services:
postgres:
image: postgres:16
restart: always
environment:
POSTGRES_USER: n8n
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: n8n
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U n8n"]
interval: 5s
timeout: 5s
retries: 5
n8n:
image: docker.n8n.io/n8nio/n8n:1.82.0
restart: always
ports:
- "5678:5678"
environment:
- N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY}
- DB_TYPE=postgresdb
- DB_POSTGRESDB_HOST=postgres
- DB_POSTGRESDB_PORT=5432
- DB_POSTGRESDB_DATABASE=n8n
- DB_POSTGRESDB_USER=n8n
- DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}
- N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true
- GENERIC_TIMEZONE=America/Chicago
- TZ=America/Chicago
volumes:
- n8n_data:/home/node/.n8n
depends_on:
postgres:
condition: service_healthy
volumes:
postgres_data:
n8n_data:
Create a .env file alongside your compose file:
POSTGRES_PASSWORD=generate-a-strong-password-here
N8N_ENCRYPTION_KEY=generate-another-strong-key-here
To generate a secure encryption key, run:
openssl rand -hex 32
Now bring it up:
docker compose up -d
Once the containers are running, visit http://localhost:5678 and create your owner account.
Why pin the version? The latest tag can introduce breaking changes to the AI Agent node or LangChain integration without warning. Pin to a specific version (check n8n’s releases page for the current stable) and test upgrades before deploying to production.
Step 2: Configure AI Credentials
Your n8n instance is running. Now it needs a brain.
n8n’s AI Agent node connects to any supported LLM — OpenAI, Anthropic, Google Gemini, Groq, Mistral, or Azure OpenAI. For this guide, we’ll use OpenAI (the most common starting point), but the credential pattern is identical for any provider.
Get Your OpenAI API Key
- Go to platform.openai.com/api-keys.
- Click “Create new secret key.” Give it a name like
n8n-agent. - Copy the key immediately. OpenAI won’t show it again.
Critical: Add billing credits. An API key without credits won’t work. Go to Billing → Payment methods and add a payment method. Then go to Billing → Add to credit balance and add at least $5. This is the #1 reason first-time setups fail — the key is valid, but there’s no money behind it.
Add the Credential in n8n
- In your n8n dashboard, click Settings (gear icon, bottom-left).
- Select Credentials → Add Credential.
- Search for “OpenAI” and select OpenAI API.
- Paste your API key.
- Click Save.
You’ll verify this works in the next step. But first — if OpenAI isn’t your preference, n8n supports Anthropic (Claude), Google Gemini, Groq (fast + cheap), and Mistral. The setup is identical: get the API key from the provider, add the credential in n8n settings.
Step 3: Build Your First AI Agent Workflow
Now the fun part. You’ll build a working AI agent in under 10 minutes.
What You’re Building
A simple AI agent that can answer questions and use a calculator tool. It demonstrates the three components every n8n AI agent needs:
- Chat Model (the brain — OpenAI, in our case)
- Memory (remembers the conversation)
- Tools (actions the agent can take)
Create the Workflow
1. Start with a Chat Trigger
From the n8n dashboard, click “Add Workflow.” Name it “First AI Agent.”
Add a Chat Trigger node. This gives you a chat interface right inside n8n where you can talk to your agent. No external integrations needed for testing.
2. Add the AI Agent Node
Add an AI Agent node. Connect the Chat Trigger to it.
In the AI Agent settings:
- Set Agent Type to “Tools Agent”
- Leave Prompt set to “Take from previous node automatically”
3. Connect the Chat Model (Brain)
Click the “+” icon on the AI Agent node and add an OpenAI Chat Model sub-node.
In the Chat Model settings:
- Select the OpenAI credential you created in Step 2
- Set Model to
gpt-4o-mini(fast, cheap, and more than capable for most agents)
4. Add Memory
Click “+” on the AI Agent node again and add a Simple Memory sub-node.
Configure it:
- Context Window Length: Set to 10 (the agent remembers the last 10 messages)
- This lets your agent maintain context across multiple exchanges — ask a follow-up question and it remembers what you were talking about.
5. Add a Tool: Calculator
Click “+” once more and add a Calculator tool node.
This gives your agent the ability to do math. It’s simple, but it demonstrates the core pattern: the agent decides when to use a tool, calls it, and incorporates the result into its response.
Your workflow should now look like this:
Chat Trigger → AI Agent
├── OpenAI Chat Model
├── Simple Memory
└── Calculator
6. Set the System Message
In the AI Agent node, open Options and find the System Message field. This is your agent’s instruction set — it defines how the agent behaves, what it can do, and how it should respond.
Paste this:
You are a helpful assistant with access to a calculator tool.
When the user asks a math question, use the calculator tool to compute the answer.
Always explain your reasoning before using the tool.
Be concise and friendly.
7. Test It
Click “Test Workflow” (the play button). A chat window opens on the right.
Try these prompts:
- “What’s 247 multiplied by 63?” — The agent should use the calculator tool.
- “Now divide that result by 3.” — The agent remembers the previous answer (memory at work).
- “What can you help me with?” — The agent describes its capabilities.
If the agent responds to all three, congratulations — you’ve built your first n8n AI agent.
What Just Happened
When you sent “What’s 247 multiplied by 63?”, here’s what n8n did behind the scenes:
- The Chat Trigger captured your message.
- The AI Agent node received it and, guided by the system message, decided it needed the calculator.
- It called the Calculator tool with
247 * 63. - The result (15,561) was returned to the AI Agent.
- The OpenAI Chat Model formulated a natural-language response.
- Simple Memory stored the exchange so your next prompt had context.
That’s the loop: perceive → decide → act → respond → remember. Every AI agent you build from here is a variation on this pattern.
Common Setup Problems (and How to Fix Them)
| Problem | Likely Cause | Fix |
|---|---|---|
| “Error: Invalid API key” | Key copied incorrectly or not saved | Re-copy the key from OpenAI. Check the credential in n8n Settings > Credentials. |
| “Insufficient quota” | No billing credits on OpenAI account | Go to platform.openai.com → Billing → Add $5+ to credit balance. |
| AI Agent node doesn’t appear | n8n version below 1.60 | Cloud: check you’re on the latest. Self-hosted: docker compose pull && docker compose up -d. |
| Agent doesn’t use tools | System message doesn’t instruct tool use | Add explicit instructions: “Use the [tool name] tool when [condition].” |
| “Connection refused” (Docker) | Port mapping or firewall issue | Confirm -p 5678:5678 in your compose file. Check firewall allows port 5678. |
| Agent responds slowly | Using a large model like gpt-4o | Switch to gpt-4o-mini or gpt-3.5-turbo for faster responses. |
| Memory not working | Context Window Length set too low or not configured | Set Context Window Length to at least 10 in Simple Memory settings. |
The most common failure? No billing credits on OpenAI. It trips up nearly everyone the first time. The API key is valid — there’s just no money behind it. Add $5 and you’re good.
What’s Next?
You’ve built your first agent. Here’s where to go from here:
- Understand what AI agents actually are — If terms like “Tools Agent” and “system message” still feel fuzzy, the next article in this series breaks down the architecture. [Planned — Article #1]
- Add real tools — Replace the calculator with a Google Sheets tool, a Slack tool, or an HTTP Request tool that calls any API. [Planned — Article #3]
- Deploy to production — Learn how to trigger agents from webhooks, schedule them, and handle errors gracefully. [Planned — Article #4]
- Go multi-agent — Chain multiple AI agents together, each with different tools and instructions, to handle complex workflows. [Planned — Article #29]
- Master the full system — This article is part of the complete n8n AI Agent Mastery path. The pillar guide ties everything together. [Planned — Article #119]
The agent you built today is simple, but the pattern scales. Add different tools and you have a customer support agent. Add a vector store and you have a knowledge-base agent. Add webhooks and you have an agent that acts on external events.
The foundation is the same: Chat Model + Memory + Tools. Everything else is iteration.
Ready to build your first AI agent? Join the waitlist at aitokenlabs.com/ai-agent-builders/waitlist and get early access to the complete AI Agent Builders platform.
About the Author
Anthony Odole is a former IBM Senior Managing Consultant, where he served as Enterprise Architect on Fortune 500 engagements, and the founder of AIToken Labs. He helps business owners cut through AI hype by focusing on practical systems that solve real operational problems.
His flagship platform, EmployAIQ, is an AI Workforce platform that enables businesses to design, train, and deploy AI Employees — AI agents that function as digital workforce members — that perform real work without adding headcount.
