Build a No-Code AI Agent with n8n and Ollama Locally
Why n8n and Ollama make a good pair
Most AI agents live in the cloud: you send a prompt to someone else's server and pay per token. n8n flips that around. It is an open-source workflow tool with a visual canvas, more than 400 integrations, and a built-in AI Agent node. Point it at Ollama, and the model doing the thinking runs on your own hardware.
The result is a real agent: you give it a goal, connect tools it can call, and it plans its own steps — search the web, read a file, check a calendar, then write up the answer. This guide builds a research agent that takes a topic, searches the web, and saves a summary to a file.
Source: Collabnix — an n8n AI Agent node wired to an Ollama Chat Model, Simple Memory, and Gmail and Calendar tools.
What you need
- At least 8 GB of RAM (16 GB is better for an 8B model).
- Docker and Docker Compose installed.
- About 10 GB of free disk space for the containers and the model.
Step 1: Start the stack with the official starter kit
n8n publishes a self-hosted AI starter kit on GitHub: a Docker Compose template that wires together four services — n8n, Ollama, the Qdrant vector store, and PostgreSQL.
git clone https://github.com/n8n-io/self-hosted-ai-starter-kit.git
cd self-hosted-ai-starter-kit
cp .env.example .env
docker compose --profile cpu upSource: n8n — the self-hosted AI starter kit demo.
That last command starts the CPU profile. With an Nvidia GPU and the container toolkit set up, use docker compose --profile gpu-nvidia up instead. Mac users can run plain docker compose up. Edit the passwords in .env before you expose anything beyond localhost.
When the logs settle, open http://localhost:5678 and create your n8n owner accou
Step 2: Pull a model that can call tools
Two solid picks are qwen3:8b and qwen2.5:7b, both reliable at calling tools on a CPU. Pull one:
docker exec ollama ollama pull qwen3:8b
One setting matters more than model choice. Ollama defaults to a 4,000-token context window on GPUs with less than 24 GB of VRAM, and its docs recommend at least 64,000 tokens for agents. Set OLLAMA_CONTEXT_LENGTH=65536 before starting Ollama, and restart the container if you change it later.
Step 3: Connect n8n to Ollama
In n8n, create a new Ollama credential under Credentials. The only required field is the base URL, and the right value depends on where each service runs:
- Both on the host machine:
http://localhost:11434 - n8n in Docker, Ollama on the host:
http://host.docker.internal:11434 - Both in the same Compose project:
http://ollama:11434
That middle case trips up almost everyone: inside a container, localhost means the container itself, not your computer. If the credential test fails, the base URL is the first thing to check. If Ollama runs on the host and n8n is in Docker, start Ollama with OLLAMA_HOST=0.0.0.0 so it listens beyond the loopback interface.
Step 4: Build the agent
Create a new workflow and add a Chat Trigger node, which gives you a chat box for testing. Connect it to an AI Agent node, then attach three sub-nodes to the agent:
- Ollama Chat Model, with the credential from Step 3. Use the Chat Model node, not the plain Ollama Model node, because only the chat variant supports tool calling.
- Simple Memory, so the agent remembers earlier turns in the same session.
- At least one tool. The AI Agent node refuses to run without one. For the research agent, add a Wikipedia tool and an HTTP Request tool pointed at a search API.
Give the agent a short system message: "You are a research assistant. Search for facts, cite the sources you used, and say when you could not verify a claim." Keep the temperature low, around 0.2 to 0.3, so the agent sticks to what its tools return.
Step 5: Test it with a job that needs a tool
Open the chat panel at the bottom of the canvas and ask something the model cannot answer from memory alone, such as "What did n8n announce this week?" Watch the execution log: a healthy run shows the agent calling the search tool, reading the results, and then writing the summary. If the answer arrives with no tool call at all, ask a question tied to current information.
Once the chat version works, swap the Chat Trigger for a Schedule Trigger and save the output to a file. The starter kit mounts a shared folder at /data/shared inside the n8n container, so a local file node can save summaries there.
Troubleshooting
Connection refused when testing the Ollama credential. Check the base URL against the table in Step 3. On Linux, host.docker.internal may not resolve; use your host LAN IP instead. If you see an ECONNREFUSED ::1 error, switch localhost to 127.0.0.1.
The agent answers without calling any tool. The model probably lacks tool support. Pull qwen3:8b or llama3.1:8b and select it in the Ollama Chat Model node. Small models also drop tool calls when the context window is too short, so check Step 2.
Replies are slow. An 8B model on a CPU answers at a few tokens per second. That is fine for a nightly job and painful for a chat. A GPU, a smaller model such as qwen2.5:7b, or a shorter system message all help. If the agent invents sources, lower the temperature: agents hallucinate most when they answer without a tool result in front of them.
Where to go from here
This setup covers the core loop: a local model, a trigger, memory, and tools. Swap the Wikipedia tool for your own API and the agent files tickets instead of summaries; add the Qdrant node and it answers from your own documents. For comparison, our Ollama quickstart covers model choice and VRAM, our LangGraph tutorial builds the same kind of agent in Python, and our CrewAI guide shows how several agents divide the work. Get one tool call working end to end, then add a second tool.


Comments
Post a Comment