Your First AI Agent in n8n: The AI Agent Node with a Local or Cloud Model

 

When an automation flow must decide for itself instead of following a track

An ordinary automation flow works like a railway: a trigger comes in, steps run in order, a result comes out. That pattern holds as long as every decision is drawn in advance. Trouble starts when the input cannot be predicted — a user message in free language, a support ticket with mixed contents, or data that sometimes needs checking against an API before a decision. Drawing branches for every possibility bloats the workflow, and some case always slips through.

The AI Agent node in n8n flips the approach: you give the agent one goal, one model, and a few tools, and the agent itself decides which tool to use and when to stop. You no longer draw every branch; you write clear instructions and let the model reason between steps. This guide builds a first agent like that — a small agent that answers questions with an HTTP tool — using a local Ollama model, with a cloud model as an alternative if you prefer one.

Prerequisites

Prepare an n8n instance already running, through Docker or another install, that you can open in a browser. If you do not have one yet, install it from the n8n self-hosting guide first. Also prepare one Ollama server reachable from n8n, with a model that supports tool calling — a small model without tool support will make the agent fail to call any tool, and the symptom looks like a "lazy" agent when the problem is really the model.

Finally, prepare one simple public API to use as a trial tool, for example a weather API or a sample JSON data API. A trial tool whose output you can check yourself makes testing the agent far easier than a tool with abstract output.

Step 1: Create a new workflow and add a trigger

Sign in to n8n, create a new workflow, and add a trigger node. For the first trial, use a Manual Trigger — it runs the workflow with one click and does not depend on an external webhook. Later, once the agent proves itself, this trigger can be swapped for a Chat Trigger or webhook without changing the rest of the workflow.

Click Execute step on the trigger alone first and confirm the workflow runs up to the trigger with no errors. Testing one node before adding the next saves a large amount of debugging time, because you always know which node was added last when something fails.

Step 2: Add the AI Agent node

Add an AI Agent node to the canvas and connect the trigger's output to its input. Open the node settings and notice its three connectors: model, memory, and tools. They are not mere options — they are how the agent thinks, remembers, and acts. The node will not run without a model, so the next step is connecting one before testing anything.

In the agent prompt field, write specific instructions, not just "answer questions". An example of a good instruction:

You are a support assistant answering questions about service
status. When a question needs current data, use the available
tools. When data is not found, say plainly that it does not
exist — never invent numbers. Answer briefly, in the same
language as the question.

Vague instructions produce a vague agent. Write what is allowed, what is not, and what to say when data is missing — those three things decide most of the agent's quality.

Step 3: Connect the Ollama chat model

Click the model connector on the AI Agent node and add an Ollama Chat Model sub-node. Create a new credential with the base URL that is correct from the n8n container's point of view:

  • If Ollama runs on the same host as Docker-based n8n: http://host.docker.internal:11434
  • If Ollama and n8n share one Compose file: http://ollama:11434
  • If n8n runs natively on the same host: http://localhost:11434

Pick a model from the list, for example qwen3:8b or another tool-capable model on your machine. Expected result: the model list appears in the dropdown — if the dropdown is empty, the credential cannot reach the Ollama server, and there is no point continuing until this address is right. Test from inside the n8n container if needed:

docker exec -it n8n curl http://host.docker.internal:11434/api/tags

Step 4: Add conversation memory

Click the memory connector on the AI Agent node and add Window Buffer Memory. Set how many messages to remember, for example the last 10 messages. This memory lets the agent keep context within one conversation session: a follow-up like "what about the second one?" can be answered without the user repeating the whole context.

One limit to understand: this memory is per session and limited to the window you set. It is not a long-term database and not a replacement for conversation storage — if you need a permanent record, save the workflow result to a database through a separate node after the agent answers.

Step 5: Add one HTTP tool

Click the tool connector and add an HTTP Request Tool. Point it at your trial API, for example a GET request to a sample data endpoint, and give it a clear name and description — the description is what the agent reads when deciding whether this tool is relevant. A good description example: "Fetches the latest sample data by ID; use when the question mentions a specific ID."

Do not add five tools at once to a first agent. One tool makes the agent's behavior predictable and testable: you know exactly when it should call the tool and when it should not. Once one tool proves itself, add the second.

Step 6: Test, read the reasoning trace, and fix the instructions

Run the workflow with a question that genuinely needs the tool, for example one whose answer only exists in the trial API. Open the execution and read the agent's trace: which tool was called, with which arguments, and how the result was used in the final answer. This trace is the agent's main debugging tool — without reading it, you are only guessing why an answer is wrong.

If the agent answers without calling the tool when it should have, fix two things: instructions that state when tool use is mandatory, and a tool description that explains its use more explicitly. If the agent calls the tool with wrong arguments, fix the tool parameter description, not the model — most argument errors come from ambiguous descriptions, not from a bad model.

Step 7: Activate and limit what the agent can do

Once testing is satisfying, save the workflow and press Active if your trigger is a webhook or chat — for a Manual Trigger, activation is irrelevant since executions stay manual. Before opening access to real users, put three safeguards in place: limit tools to read-only operations for the first trial, add a human-approval step in front of tools that change data, and limit who can trigger the workflow.

The third safeguard is often skipped: an agent anyone can trigger, holding tools that can change data, is a dangerous combination. Start read-only, prove its behavior, and only then open write operations one by one with human approval in front of them.

AI agents versus LLM chains and rigid workflows

AspectRigid workflowLLM chainAI agent
Who decides the stepYou, in advanceYou, fixed orderThe model, at runtime
Uses tools as neededNoLimitedYes, chosen by the agent
Handles unexpected inputFails, or needs a new branchOne-way answerReasons and picks tools
Debugging easeEasy, path visibleMediumRequires reading the agent trace
Best forProcesses that never changeOne text taskTasks with decisions in the middle

That last row is the deciding factor. An agent does not replace rigid workflows — it is the tool for the part of a workflow that genuinely needs decisions at runtime, while steps that never change are still better drawn as fixed paths.

Common mistakes and how to fix them

SymptomMost likely causeFix
Empty model dropdownWrong Ollama address from the n8n containerUse host.docker.internal or the Compose service name
Agent never calls toolsVague instructions or tool descriptionState when tool use is mandatory, improve the description
Agent calls tools with wrong argumentsUnclear parameter descriptionWrite parameters and example values in the tool description
Agent invents dataInstructions do not forbid inventingAdd a rule: say it does not exist when data is not found
Answers forget contextMemory missing, or window too smallAdd Window Buffer Memory, raise the message count
Slow execution or timeoutLarge model, or cold startUse a smaller model, raise the node timeout
Agent changes data without permissionWrite tools open without approvalAdd a human-approval step before write tools
Active workflow does not respondTrigger is not a webhook or chatReplace Manual Trigger with a matching trigger

The recurring pattern: most first-agent problems are not about the model, but about a wrong model address, vague instructions, and tool descriptions that do not explain when the tool should be used.

Final checklist

  • A new workflow runs up to the trigger with no errors.
  • The AI Agent node connects to a tool-capable chat model.
  • Agent instructions are specific: what is allowed, what is not, and what to say when data is missing.
  • Window Buffer Memory is attached with a sensible window.
  • One HTTP tool is attached with a clear name and description.
  • Execution traces are read and tool behavior matches expectations.
  • Write tools are limited or gated by human approval before real users get access.

Which task would you hand to an agent first — one that has been too branchy to draw as a rigid workflow? Share it in the comments, so other readers can compare their first agents with yours.

Read also: Qdrant on Docker for RAG Vector Storage and "n8n Self-Host: Otomasi Server Sendiri Tanpa Coding" for the n8n install basics this guide builds on.

Diskusi

Ada pertanyaan atau pengalaman yang ingin dibagikan?

0komentar

Komentar ditinjau sebelum ditampilkan. Mari berdiskusi dengan sopan dan sesuai topik.