n8n tutorial
How to Build an AI Agent in n8n (Step by Step)
n8n is one of the fastest ways to build an AI agent without writing much code. This tutorial shows how an n8n AI agent is put together, how to build your first agentic workflow, and how to make it safe enough to run on real work.
The parts of an n8n AI agent
In n8n, an agent is a workflow built around the AI Agent node. You attach a few pieces to it:
- Trigger: what starts the workflow, such as a chat message, a form, a new email or a schedule.
- Chat model: the AI model that does the thinking, such as OpenAI, Anthropic or Google Gemini.
- Memory: lets the agent remember earlier messages in the conversation.
- Tools: actions the agent can choose to take, like an HTTP request to an API, a Google Sheets lookup, or another n8n workflow.
- Output: where the result goes: a chat reply, a Slack message, a CRM update.
The agent reads the request, decides which tool to call, looks at the result and decides what to do next. That is what makes it an n8n agentic workflow rather than a fixed automation.
Build your first n8n AI agent in 6 steps
Example: a support agent that answers order questions from a spreadsheet and hands anything else to a person.
1. Start with a chat trigger
Add a chat trigger so you can test the agent by typing to it inside n8n. Later you can swap it for a website chat, Slack or email trigger.
2. Add the AI Agent node and a chat model
Connect the AI Agent node to the trigger, then attach a chat model with your API key. Start with a fast, low-cost model while you test.
3. Write the agent’s instructions
In the agent’s system message, state its job, the tools it has, what it must not do and when to hand off. For example: “You answer order status questions using the Orders tool. Never promise refunds. If the question is not about an order, say a person will follow up.”
4. Attach memory
Add a simple memory so the agent remembers the last few messages. That way, a customer doesn’t have to repeat their order number.
5. Give it one or two tools
Add a Google Sheets (or database) tool that looks up an order by number. Describe the tool clearly, because the agent uses the description to decide when to call it. Keep tools read-only at first.
6. Test with real questions
Type 20 realistic questions, including tricky ones: a wrong order number, a refund demand, an off-topic question. Use n8n’s execution log to see which tool the agent called and why. Fix the instructions and tool descriptions, then test again.
Make your n8n agent safe enough for real work
- Human approval: before the agent sends, refunds or changes anything, route it to a person (for example, a Slack or email message that waits for approval).
- Error handling: set an error workflow so failures alert you instead of failing silently.
- Limits: cap how many steps the agent can take per run, and give it a clear fallback reply.
- Logging: save each request, tool call and answer to a sheet or database, so you can review mistakes weekly.
n8n agentic workflow ideas to build next
- Lead qualification agent that researches a new signup and drafts a first email for approval.
- Inbox agent that sorts support email, drafts replies and escalates complaints.
- Research agent that pulls sources on a topic and writes a cited brief.
- Meeting agent that turns transcripts into tasks in your project tool.
See each one broken down in our AI workflow examples.
n8n AI agents: common questions
Can n8n build AI agents?
Yes. n8n has an AI Agent node that connects to a chat model, memory and tools, so you can build agents that choose their own steps inside a workflow.
Do I need to code to build an AI agent in n8n?
No. You can build a full agent with n8n’s visual nodes. Some code helps for custom data handling, but it isn’t required.
What is the difference between an n8n workflow and an n8n AI agent?
A normal n8n workflow runs the same steps every time. An n8n AI agent decides which tools to use and in what order, based on the request.
Where can I get n8n AI agent training?
The n8n AI Agents Workshop is hands-on n8n training where you build one real agentic workflow from start to finish. Teams can also book AI agent training for teams.
Build a working n8n AI agent this week
Hands-on, online, and you finish with a workflow you can use.
Not ready to enroll? Start with the free AI Agent Starter Kit.
Score your agent idea, decide what it may do alone, and write its instructions with three free tools. Then unlock six templates from our courses.