n8n AI Agent Tutorial for Beginners: Build Your First AI Agent Step by Step
To build an AI agent in n8n, create a workflow with three parts: a Chat Trigger (where messages come in), an AI Agent node (the brain), and the sub-nodes it needs: a chat model such as Google Gemini, Simple Memory so it remembers the chat, and at least one tool, such as the Calculator. Write the agent's rules in its System Message, test it in the chat panel, then Publish the workflow. Self-hosted n8n Community Edition is free; you pay only for your server and the AI model's usage.
A chatbot only talks. An agent can also do things: look up a sheet, calculate a number, send an email. That is why "n8n AI agent" is one of the most searched automation topics today. In this guide we will build one small, useful agent from zero, for a coaching class that gets the same fee questions every day. You do not need to write code. You need about 45 minutes, a free Google AI Studio API key, and this page open next to n8n.
Full course chapter
This guide builds a chat agent with memory and a Calculator tool. The course chapter builds 3 business workflows: an email summary into Google Sheets, a WhatsApp enquiry reply with your approval, and a daily news digest. Read it here: Build an AI Agent in n8n Without Coding (Free, Step by Step).
Related guide
Choosing Zapier, Make or n8n first in India? Zapier vs Make vs n8n for AI Automation in India (Which to Learn First) compares Free meters and the same Gmail to Sheet job.
What you will learn in this guide
- What an AI agent is in n8n
- Run n8n free with Docker
- Get a Gemini API key
- Build Chat, Agent, Model, Memory
- Add a Calculator tool
- Test, fix and publish
1. Suppose we run a coaching class in Kolhapur
Suppose we are Amit Patil. We run "Patil Computer Classes" in Kolhapur. Every day, parents and students send the same WhatsApp questions:
- "What are the batch timings for Python?"
- "What is the fee? Can I pay in 3 parts?"
- "If I pay the full fee now, what is the discount?"
Answering these takes an hour a day. We want a small assistant that answers from our fee list and does the fee maths correctly.
A normal chatbot might guess the fee or do the maths wrong. An agent with a Calculator tool reads our fee list, decides it needs to calculate, uses the calculator, and replies with a correct number.
2. What is an AI agent in n8n?
An AI agent is an AI model that can decide which tool to use to finish a task. In n8n it is built from small blocks called nodes:
| Block | Job | In our example |
|---|---|---|
| Chat Trigger | Receives each message | A parent types a question |
| AI Agent node | Reads the message and the rules, decides what to do | Decides: "I need the fee and a calculation" |
| Chat model (sub-node) | The language model that thinks and writes | Google Gemini |
| Memory (sub-node) | Remembers the last few messages | Knows "it" means the Python course |
| Tool (sub-node) | Does a real job the model cannot do well alone | Calculator for instalments and discounts |
Figure 1. How the agent answers one message: the Chat Trigger passes the question to the AI Agent, the agent reads its rules and memory, calls the Calculator tool when it needs maths, and then writes the reply.
The n8n docs say you must connect at least one tool to an AI Agent node. That is what makes it an agent and not just a chat.
3. Step 1: run n8n (free, with Docker)
You have two choices:
| Option | Cost | Best for |
|---|---|---|
| n8n Cloud | Paid subscription (see n8n's pricing page for current plans and any trial) | No setup, always online |
| Self-hosted Community Edition | Free software; you pay for your own computer or server | Learning, and full control |
For learning, run it on your own laptop with Docker Desktop installed. Open a terminal and run these two commands from the n8n docs (we set the time zone to India):
docker volume create n8n_data
docker run -it --rm --name n8n -p 5678:5678 \
-e TZ="Asia/Kolkata" -e GENERIC_TIMEZONE="Asia/Kolkata" \
-e N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true \
-v n8n_data:/home/node/.n8n n8nio/n8n
Expected result: after a minute the terminal shows that n8n is ready. Open http://localhost:5678 in your browser and create the owner account.
The n8n_data volume keeps your workflows and saved credentials safe when you stop and start n8n. For a real business server, the n8n docs recommend Docker Compose instead of this single command.
4. Step 2: get a free Gemini API key
- Go to Google AI Studio (aistudio.google.com) and sign in with your Google account.
- Open the API keys page and copy your key (Google creates a project and key for new users; you can also click Create API key).
- Keep the key private, like a password. Do not paste it in WhatsApp groups or screenshots.
The free tier has rate limits. A paid tier raises the limits and needs Cloud Billing. For this small agent, the free tier is enough to learn.
5. Step 3: build the workflow (Chat, Agent, Model, Memory)
- In n8n, click Create workflow.
- Add the first node: search for Chat Trigger ("When chat message received"). Leave Make Chat Publicly Available off while you build.
- Click + after the Chat Trigger and add AI Agent.
- Under the AI Agent you will see small inputs: Chat Model, Memory and Tool.
- Click Chat Model, choose Google Gemini Chat Model, create a new credential, and paste your API key.
- In the model list, pick a current Flash model (for example
gemini-3.8-flash, the current stable Flash model in Google's docs in October 2026). - Click Memory and add Simple Memory. Keep the default Context Window Length (the number of past messages it remembers).
6. Step 4: write the System Message (the agent's rules)
Open the AI Agent node, find Options → System Message, and paste this:
You are the friendly front-desk assistant of Patil Computer Classes, Kolhapur.
Answer only from the facts below. If something is not in the facts, say:
"Please call the office at [OFFICE PHONE] for this."
Facts:
- Python batch: Mon-Wed-Fri, 7 to 9 pm. Fee Rs 18,000.
- Excel batch: Tue-Thu-Sat, 6 to 8 pm. Fee Rs 9,000.
- Fees can be paid in 3 equal instalments.
- Full payment at admission gets 5% discount.
Rules:
- For any fee calculation, ALWAYS use the Calculator tool. Never do maths in your head.
- Reply in simple English, under 60 words.
- Never ask for card numbers, UPI PIN, OTP or Aadhaar.
Why each part matters: the facts stop guessing, the "use the Calculator" rule forces the tool, and the safety rule protects parents.
7. Step 5: add the Calculator tool and test
- Click the Tool input under the AI Agent and add Calculator. It needs no settings.
- Click Open chat (the chat panel at the bottom of the canvas).
- Type:
What is the Python fee if I pay in 3 parts?
Expected reply (yours will be similar, not the same):
The Python course fee is Rs 18,000. In 3 equal instalments, you pay Rs 6,000 each time.
- Now test memory. Type:
And if I pay it in full today?
Expected reply:
If you pay the full Python fee at admission, you get 5% off: Rs 18,000 - Rs 900 = Rs 17,100.
The agent knew "it" meant the Python course (that is memory), and it used the Calculator for 5% of 18,000.
-
Open the execution log of the AI Agent node. You can see each step: the model's decision, the Calculator call with the input, and the result. This is how you check that the tool really ran.
-
Now test the boundary. Type:
Do you have a Java batch?The agent should say to call the office, because Java is not in the facts.
Ravindra Bagale's Tip
Students test only the happy question and publish. Always test three types: a normal question, a follow-up (to test memory) and a question that is NOT in your facts (to test that it does not invent). If the agent invents a Java batch, make the "answer only from the facts" rule stronger.
8. Step 6: publish and share the chat
- Open the Chat Trigger and turn on Make Chat Publicly Available.
- Choose Hosted Chat mode. Add an Initial Message, such as "Namaskar! Ask me about batches and fees."
- For Authentication, choose Basic Auth if only your staff should use it, or None for a public page.
- Click Publish at the top. n8n saves your edits as a draft automatically; Publish makes this version live.
- Copy the Chat URL from the Chat Trigger and open it on your phone.
Important for a laptop setup: localhost works only on your own computer. To share the chat with parents, n8n must run on a server with a public address (n8n Cloud, or a small cloud server). The n8n docs also say every chat message counts as one workflow execution, so check your plan's limits on n8n Cloud.
9. Make it better: next steps
- Read real data from a sheet: add the Google Sheets tool so the agent reads batch timings from a sheet you update, instead of the System Message.
- Ask a human before acting: n8n supports human approval before an agent runs certain tools. Use it before any tool that sends messages or changes data.
- Know the newer "Agents" feature: from n8n 2.32.3, n8n also has Agents as their own items in a project (in Preview). The AI Agent node in this guide still works and is the easiest way to learn.
10. Common errors and fixes
| Problem | Likely reason | Fix |
|---|---|---|
| Error says a tool is needed | No tool connected to the AI Agent | Add at least one tool, like Calculator |
| Credential error from Gemini | Wrong or expired API key | Create a new key in AI Studio and update the credential |
| "Too many requests" or quota error | Free tier rate limit | Wait and retry, or test with fewer messages |
| Agent forgets the last message | No memory, or memory not connected | Add Simple Memory under the AI Agent |
| Wrong maths | The model did the maths itself | Add "ALWAYS use the Calculator tool" to the System Message |
| Agent invents facts | Rules too weak | Add "Answer only from the facts below" and a fallback line |
| Chat link does not open on phone | n8n is on localhost | Host n8n on a server or use n8n Cloud |
11. Try at home
Try at home
- Run n8n with Docker and open http://localhost:5678.
- Build the workflow: Chat Trigger, AI Agent, Google Gemini Chat Model, Simple Memory, Calculator.
- Change the facts in the System Message to your own small business, hostel mess or tuition.
- Test three questions: normal, follow-up, and one not in your facts.
- Open the execution log and find the Calculator step.
- Bonus: add a Google Sheets tool and move your facts into a sheet.
Recap
In short
- An n8n AI agent = Chat Trigger + AI Agent node + chat model + memory + at least one tool.
- Self-hosted Community Edition is free; run it with two Docker commands and open localhost:5678.
- A free Google AI Studio API key connects the Google Gemini Chat Model.
- The System Message holds your facts and rules; tell the agent to use tools for maths.
- Test a normal question, a follow-up and an out-of-scope question, and read the execution log.
- Turn on the public chat and Publish; host n8n on a server to share it.
Build the coaching-class agent tonight exactly as shown, then change only the facts to your own business. One working agent teaches you more than ten videos.
Before this guide: Prompt Engineering for Beginners: Role, Task, Context and Format · Next idea: How to Build a RAG Chatbot from a PDF
Ravindra Bagale, trainer: linkedin.com/in/ravindra-bagale. Patil Computer Classes, its batches and fees are made up for learning. n8n node names, editions, the Docker command and the Agents preview were checked in the n8n docs on 19 October 2026; the Gemini model name was checked in Google's Gemini API docs the same day. Both change often. AI replies change every time, so yours will be similar, not the same.
Frequently asked questions
Is n8n free?
The self-hosted Community Edition is free to use for your own work; you pay for your server and the AI model. n8n Cloud is a paid subscription.
What is the difference between a chatbot and an AI agent in n8n?
A chatbot only replies with text. An AI agent can decide to use tools, such as a calculator, a Google Sheet or an email node, to complete a task.
Which AI model can I use in n8n?
The AI Agent node works with many chat model sub-nodes, such as Google Gemini, OpenAI and Anthropic. You need an API key from the provider.
Why must I add a tool to the AI Agent node?
The n8n docs say an AI Agent node needs at least one tool sub-node. Tools are what let the agent act, not just talk.
Can I share my n8n chat with customers?
Yes. Turn on Make Chat Publicly Available in the Chat Trigger, publish the workflow, and share the Chat URL. n8n must run on a server that others can reach.
Related: Build an AI Agent in n8n Without Coding (Free, Step by Step)