An AI agent, practically speaking, is an automated workflow that uses a language model to process information and take action. It’s not science fiction — it’s a set of connected nodes in a tool like n8n that runs on a trigger, does something intelligent with the input, and produces a useful output.
I have about a dozen of these running for my own business. One monitors competitor content and sends me a weekly digest. One processes incoming lead forms, enriches the data, and drafts a personalized follow-up. One takes raw meeting notes and formats them into structured summaries with action items.
All of them were built in n8n. Most of them were built in a single day.
This guide covers how to build your first AI agent in n8n — from setup through to an active, running workflow.
What an AI agent actually is in n8n
In n8n, an “AI agent” is a workflow that includes at least one AI node — typically a language model node (OpenAI, Anthropic, or similar) — that processes some input and produces output that gets used downstream.
The simplest possible AI agent: a webhook receives a text input → the text goes to an AI node with a system prompt → the AI’s response is sent via email. Three nodes. Total build time: 20 minutes.
More complex agents might: pull data from multiple sources, run multiple AI processing steps, make decisions about which path to take, call external APIs based on AI output, and loop until a condition is met.
n8n has specific “AI Agent” nodes that give the AI access to tools it can call autonomously — things like web search, code execution, or API calls. These create more autonomous agents that can take multi-step actions. For a one-day build, I recommend starting simpler and adding autonomy later.
Setting up n8n
Option 1: n8n cloud (fastest start)
n8n has a hosted cloud version at n8n.io. Free trial available, then plans from ~$20/month. Best for getting started fast without any server setup. All your workflows are hosted and managed by n8n.
Option 2: self-hosted via Docker (most control)
If you want to self-host (and many people do, for privacy and cost reasons), n8n runs easily on Docker:
docker run -it --rm \
--name n8n \
-p 5678:5678 \
-v ~/.n8n:/home/node/.n8n \
n8nio/n8n
This runs n8n locally at localhost:5678. For production, deploy to a VPS (DigitalOcean, Hetzner, or Fly.io all work well). Hetzner is the cheapest option — a €4/month server handles dozens of active workflows easily.
Connecting credentials
Before building your first agent, add your credentials. The most commonly needed ones:
- OpenAI or Anthropic API key (for AI processing)
- Gmail or SMTP (for email outputs)
- Slack API (for Slack outputs)
- Any SaaS tool you want to connect to
n8n’s credential manager stores these securely and makes them available across all your workflows.
Defining your agent’s job
Before building anything in n8n, write this down:
- Trigger: What starts the agent? (A new email, a form submission, a schedule, a webhook from another app)
- Input: What data does the agent receive?
- AI task: What should the AI do with that data? (Summarize, classify, extract, generate, decide)
- Output: What does the agent produce and where does it go?
- Action: Does the agent take any action beyond producing output? (Send an email, update a database, post to Slack)
Keep the scope narrow. An agent that does one thing well is dramatically easier to build, test, and maintain than an agent that tries to handle multiple tasks. You can always build a second agent for the second task and connect them later.
Building the workflow
Node types you’ll use most
Trigger nodes: These start your workflow. The most common: Webhook (receives HTTP requests), Schedule (runs on a cron schedule), Email Trigger (fires on new emails), and Form Trigger (fires on form submissions).
AI nodes: The OpenAI node or Anthropic node for text generation. The AI Agent node for more autonomous behavior. The Text Classifier node for routing based on content type.
Data manipulation nodes: Set Node (set or modify data), Code Node (run JavaScript for complex transformations), HTTP Request (call any external API), Merge (combine data from multiple branches).
Output/action nodes: Gmail, Outlook, Slack, Notion, Airtable, Google Sheets, and hundreds more via native integrations.
The basic AI workflow structure
Most AI agents follow this pattern:
- Trigger → receives the input that starts the workflow
- Data prep → optionally format or enrich the input data
- AI node → system prompt + input → AI output
- Parse output → optionally extract structured data from AI response
- Action node → send, save, or forward the output
Build in this order. Get the trigger working first. Then connect the AI node and test the output. Then add the action node last.
Writing effective system prompts for n8n agents
The system prompt is the most important thing you’ll write when building an AI agent. It defines the agent’s role, its task, its output format, and its constraints.
A good system prompt has four parts:
- Role definition: Who is the AI in this context?
- Task description: What exactly should it do with the input?
- Output format: What should the output look like? (JSON, bullet points, a paragraph, a specific structure)
- Constraints: What should it not do? What rules should it follow?
Example for a lead enrichment agent:
“You are a sales research assistant. You receive a lead’s name, company, and LinkedIn URL. Your task: write a 3-sentence personalized outreach note that references something specific about their company or recent activity. The note should be direct and professional — not salesy. Output only the note text, no preamble, no signature. If you cannot find specific information to reference, write a generic but well-crafted note and flag it with [GENERIC] at the start.”
Notice the specific output format instruction and the edge case handling. Both matter for an agent that runs automatically without human review.
In n8n, you can use expressions in your system prompt to include dynamic data from earlier nodes. For example: You are processing data about {{$node["Set"].json["company_name"]}}.
A complete example: lead enrichment agent
Here’s a complete AI agent I built and actively use. It processes new form submissions from my website contact form:
Trigger: Webhook — fires when someone submits my contact form
Node 2 — Classify the lead: OpenAI node with a system prompt that classifies the lead as “potential client,” “job seeker,” “partnership,” or “other” based on their message
Node 3 — Route by classification: Switch node that sends each classification to a different branch
Branch A (potential client) — Node 4: HTTP Request node that looks up their company domain in a company data API
Branch A — Node 5: OpenAI node that writes a personalized reply based on their message + company data
Branch A — Node 6: Gmail node that drafts (not sends) the reply in my inbox for review
Branch A — Node 7: Airtable node that creates a record in my CRM with the enriched data
Other branches: Simpler handling — a Slack notification for partnership inquiries, a templated reply for job seekers
Total nodes: 11. Build time on day one: about 5 hours including testing. Time saved per week: approximately 3 hours of manual email processing and lead logging.
Testing and activating
n8n has an excellent test execution mode. Before activating any workflow:
- Run a manual test execution with real (or realistic) sample data
- Check each node’s input and output data in the execution log
- Verify the AI outputs are what you expected
- Test edge cases: empty inputs, unusual data, error scenarios
- Run the full workflow end-to-end at least three times before activating
Common issues to check:
- Data mapping: are the right fields being passed between nodes?
- AI output format: is the AI returning the format you asked for, or freeforming?
- Error handling: what happens when an API call fails? Add error branches for production workflows.
Once testing is solid, click “Active” to turn the workflow on. It will now run automatically on every trigger event.
What to build next
- → [LINK: How to Build a Personal AI Assistant in One Day]
- → [LINK: n8n vs Make vs Zapier — Which Automation Tool to Use]
- → [LINK: Connect Your Agent to a Full App]
- → Back to the Build with AI pillar
FAQ
Is n8n free?
n8n is open-source and free to self-host. The self-hosted version has no workflow limits and no execution limits. n8n Cloud (hosted version) has a free tier with limited executions per month, and paid plans for higher usage. For most users, self-hosting on a cheap VPS is the best combination of cost and control.
How is n8n different from Zapier or Make?
n8n is open-source, self-hostable, and significantly more powerful for complex workflows. Zapier and Make are hosted SaaS tools with simpler interfaces but usage-based pricing that gets expensive at scale. n8n has a steeper learning curve but a much higher ceiling. For AI agents specifically, n8n’s AI nodes and agent capabilities are more advanced than both Zapier and Make.
Do i need to know how to code to use n8n?
For basic workflows — no. For complex data manipulation or custom logic — some JavaScript knowledge helps. The Code Node lets you write JavaScript for transformations that the built-in nodes can’t handle. But many useful agents can be built with zero code using n8n’s visual interface alone.
How do i handle errors in n8n agents?
Every production workflow should have error handling. n8n’s Error Trigger node catches failed executions. At minimum, set up a workflow that emails you when any production workflow fails. For individual nodes, you can set “Continue on fail” and add error branches that handle failures gracefully.
What AI models does n8n support?
n8n has native nodes for OpenAI (GPT-4o, o1), Anthropic (Claude), Google Gemini, Mistral, Cohere, and others. It also supports any OpenAI-compatible API, which covers most open-source models running on platforms like Together AI or Groq. You can switch models per workflow or even within a workflow.