Build an Agentic AI with Native n8n Nodes
Build an Agentic AI with Native n8n Nodes
Create a fully local, visual, and maintainable agent using Ollama and n8n’s Advanced AI nodes. No custom code chains, no hidden prompts. You’ll wire a Tools Agent that can call real functions with native tool binding.
Introduction
Older n8n agent tutorials used the basic LLM Chain and manual prompt engineering. The Advanced AI nodes change the game: the AI Agent (Tools Agent) handles reasoning, tool selection, and error recovery for you, visually.
With Ollama running locally, you get privacy, low latency, and zero API costs. With n8n, you get a debuggable canvas where every thought, tool call, and observation is inspectable.
Prerequisites
- Ubuntu (or WSL2) host with Docker
- Ollama ≥ 0.3 installed locally with model
llama3.1:8b - n8n with Advanced AI enabled (v1.38+). In n8n Cloud it’s on by default; self-hosted is fine.
172.17.0.1).
1. Prepare Ollama
Pull the model and expose Ollama on all interfaces so Docker can reach it.
ollama pull llama3.1:8b
# Stop any running service first
# Then start with host binding
OLLAMA_HOST=0.0.0.0 ollama serve
Verify: curl http://localhost:11434/api/tags should list llama3.1:8b.
OLLAMA_HOST=0.0.0.0 in /etc/systemd/system/ollama.service.d/override.conf to make it persistent across reboots on Ubuntu.
2. Prepare n8n (Docker)
We use a Docker named volume (`n8n_data`) rather than binding to the host's home directory. This prevents common UID 1000 file permission errors on Linux systems.
docker run -it --rm --name n8n \
-p 5678:5678 \
-v n8n_data:/home/node/.n8n \
n8nio/n8n:latest
Find your Docker gateway IP (from the host):
docker network inspect bridge -f '{{range .IPAM.Config}}{{.Gateway}}{{end}}'
# → usually 172.17.0.1
Open n8n at http://localhost:5678 and create a blank workflow.
Visual Architecture
The AI Agent node has three dedicated inputs: Model, Memory, and Tools. This is native tool binding. No prompt hacking.
3. Build the Workflow
- Add Chat Trigger → keep defaults.
- Add AI Agent node → set Agent to Tools Agent.
- Connect Chat Trigger → AI Agent.
- Add Ollama Chat Model, Simple Memory (Window Buffer), and Code Tool. Connect each to the matching AI Agent input.
4. Configure AI Nodes (Exact Settings)
Ollama Chat Model
Connection
- Base URL:
http://172.17.0.1:11434 - Model:
llama3.1:8b
Parameters
- Temperature: 0
- Max Tokens: 512
- Enable Use Tools / Tool Calling: ON
Window Buffer Memory
- Type: Simple Memory → Window Buffer Memory
- Window Size: 10
Why 10? That retains the last 5 user/assistant turns. This provides enough context for follow-ups without blowing the 8B model's context window.
Code Tool — get_current_time
- Name:
get_current_time - Description:
Returns current UTC time as ISO 8601 string. Use when user asks for time, date, now, today, or current UTC.
Code:
// Runs in n8n's Code Tool sandbox
return new Date().toISOString();
5. Test & Observe
- Click Activate then open the Chat panel (right sidebar).
- Ask: “What time is it in UTC right now?”
- Click the AI Agent node → Executions. Expand the run.
You should see Intermediate Steps: Thought → Action (get_current_time) → Observation (ISO string) → Final Answer. This is visual debugging in action.
Patterns: Why This Works
1. Native Tool Binding
The Model emits structured tool calls, n8n routes them to the connected Tool node, then feeds the result back. No JSON parsing in prompts.
2. Self-Correction
If a tool fails or returns unexpected data, the Tools Agent sees the observation and retries with a different tool or reformulated input automatically.
3. Visual Debugging
Every loop iteration is logged. You can inspect tokens, latency, and tool payloads without adding console logs.
Exercises
- Weather Tool: Add an HTTP Request Tool named
get_weather. Description: “Get current weather for a city. Input: city name.” Usehttps://wttr.in/{city}?format=j1. Ask: “weather in Berlin”. - Secure Calculator Tool: Do not use raw
eval()in code nodes for LLMs (this introduces remote code execution vulnerabilities). Instead, add an