Tutorial
n8n AI Agent Tutorial for Beginners
A beginner's n8n AI agent tutorial: what n8n is, how to run it for free, and how to build a working AI agent with a chat model, memory and tools — without writing code. Then the part most n8n tutorials skip: what each n8n node is doing in code, and when to build the agent in code instead.
By Abdul Rahman Azam, founder of AI Season · Updated
Key facts
| What n8n is | A visual workflow-automation tool with built-in AI agent nodes |
|---|---|
| Cost | Self-hosted Community edition is free; n8n Cloud has a free trial, then paid plans |
| You need | Node.js 20.19–24.x (or Docker) and an API key for a chat model |
| You will build | A chat agent with a model, memory, a calculator and Wikipedia as tools |
| Time | About 30–45 minutes |
What is n8n?
n8n is a workflow-automation platform: you connect apps and services as nodes on a canvas, and data flows from one node to the next. It has hundreds of integrations — Gmail, Google Sheets, Slack, Telegram, databases, webhooks — and a set of AI nodes, built on LangChain concepts, for chat models, agents, memory, vector stores and tools.
It is fair-code: you can self-host the free Community edition, or use the paid n8n Cloud service. Freelancers in Pakistan and India use it widely because clients pay for automations — lead capture, email triage, report generation — and n8n builds them quickly.
How an n8n AI agent works
In a workflow, an AI agent is the AI Agent node. It is a *root* node that needs *sub-nodes* plugged into it:
- Chat model — the LLM that reasons, for example the OpenAI Chat Model or Google Gemini Chat Model node.
- Memory — keeps the conversation, for example Simple Memory (in n8n) or Postgres Chat Memory (in a database).
- Tools — actions the agent may take: Calculator, Wikipedia, an HTTP request, Google Sheets, another workflow, or an MCP server. The AI Agent node needs at least one tool.
The agent runs the same loop as any AI agent: read the message, decide whether to call a tool, read the result, repeat, then answer. If that loop is new to you, what AI agents are explains it in plain language.
n8n is also rolling out a separate Agent Builder for standalone agents (in preview at the time of writing). This tutorial uses the AI Agent node inside a workflow, which is stable and the most common way to build agents in n8n.
Step 1: Run n8n
The quickest way on your own laptop is npm. Install Node.js (n8n needs a version between 20.19 and 24.x), then run:
npx n8nOpen http://localhost:5678 in your browser and create the local owner account. Prefer not to install anything? Start an n8n Cloud free trial instead — the steps below are the same.
Step 2: Add a chat trigger and the AI Agent node
- Create a new workflow.
- Add the Chat Trigger node ("When chat message received"). It gives you a chat box for testing and can later become a public chat page.
- Add the AI Agent node after it. In its settings, add a system message such as: "You are a study assistant for university students. Use tools for maths and facts; say when you are not sure."
Step 3: Connect a chat model
Under the AI Agent node, click the Chat Model connector and pick a model node — for example OpenAI Chat Model. Create a credential with your API key, choose a model that supports tool calling, and save. Any supported provider works; Google Gemini is a common choice for students because of its free tier.
Step 4: Add memory
Click the Memory connector and add Simple Memory. It keeps the last few messages of each chat session so the agent can answer follow-up questions. For production, switch to a database-backed memory such as Postgres Chat Memory so history survives restarts.
Step 5: Give the agent tools
Click the Tool connector and add Calculator and Wikipedia. The agent reads each tool's name and description to decide when to use it — exactly how tool calling works in code.
Now open the chat and test: *"What is 18% of 45,000?"* should trigger the Calculator; *"Who founded the Indian Institute of Science?"* should trigger Wikipedia. Open the execution log to see every step the agent took — that log is your best debugging tool.
Step 6: Make it useful
- Real data — add Google Sheets or a database tool so the agent can look up and update records.
- Your documents — add a vector store and embeddings so it answers from your files (this is RAG).
- Channels — swap the Chat Trigger for Telegram, Slack or a webhook so people can reach the agent where they already are.
- MCP — connect an MCP server as a tool to reach many services through one standard. See the MCP guide.
- Safety — require human approval before sensitive tools run, and never give an agent write access it does not need.
What each n8n AI node is doing in code
n8n's AI nodes are built on LangChain concepts, so every box on the canvas matches something you can write in Python. Knowing the code version is what lets you debug an n8n agent that misbehaves — and build agents n8n can't.
| In n8n | What it is in code | Learn it |
|---|---|---|
| AI Agent node | The agent loop — create_agent in LangChain, or a hand-written loop | Build an AI agent in Python |
| Chat model sub-node | A model client — init_chat_model("provider:model") | LangChain tutorial |
| Simple Memory | A checkpointer keyed by a thread or session ID | LangChain tutorial: memory |
| Tool sub-nodes | Functions with a name, description and JSON schema the model can call | Build an AI agent: tools |
| Vector store and embeddings nodes | A RAG pipeline: chunking, embeddings, retrieval and citations | RAG for AI agents |
| MCP Client Tool node | An MCP client connecting the agent to an MCP server | MCP guide |
| Human approval for tools | A human-in-the-loop interrupt, as in LangGraph | LangChain vs LangGraph |
n8n or code? An honest comparison
| n8n (no-code) | Code-first (LangChain / LangGraph) | |
|---|---|---|
| Speed to first agent | Minutes | An hour or two |
| Integrations | Hundreds built in | You write or install them |
| Complex logic and state | Possible, gets hard to manage | Full control with LangGraph |
| Testing and versioning | Built-in evaluations; workflows are JSON | Normal code tests, Git and CI |
| Best for | Business automations, freelancing, quick prototypes | Custom products, AI engineering jobs, complex agents |
Many developers use both: n8n for glue and integrations, code for the agent's core. If you want an AI engineering career, learn the code-first path too — start with the LangChain tutorial and see AI agent frameworks compared.
Learn to build agents properly
AI Season does not teach n8n. It teaches the code underneath every node on this page — LangChain, LangGraph, RAG, tool calling, MCP, guardrails and deployment — so you can build any agent, in n8n or out of it. The AI Season bootcamp runs 12 live sessions over 6 weeks, explained in Urdu, coded in English. Cohort 02 starts 1st January 2027.
Frequently asked questions
What is n8n used for?
n8n automates work between apps: moving data, sending emails and messages, updating spreadsheets and databases, and — with its AI nodes — building AI agents and chatbots that can use tools.
Is n8n free?
The self-hosted Community edition is free to run on your own machine or server. n8n Cloud, the hosted version, has a free trial and then paid plans. Either way you pay separately for the AI model you call, unless you use a free tier or a local model.
Can I build an AI agent in n8n without coding?
Yes. Add a Chat Trigger, an AI Agent node, a chat model, memory and at least one tool, and you have a working agent without writing code. Code helps once you need custom logic.
Is n8n better than LangChain?
They solve different problems. n8n is faster for integrations and business automations; LangChain and LangGraph give more control for custom, complex agents. n8n's AI nodes are themselves built on LangChain concepts, so learning one helps with the other.
Is n8n good for freelancing in Pakistan and India?
Yes — automation and AI-agent gigs built with n8n are in steady demand. Understanding how agents work in code as well lets you take on larger, better-paid projects.
Does AI Season teach n8n?
No. AI Season teaches building AI agents in code — LangChain, LangGraph, RAG, tool calling and MCP. Those are the same concepts n8n's AI nodes are built on, so the course makes n8n easier to use well, but n8n itself is not part of the curriculum.