Building an AI agent with n8n is the fastest, cheapest way to turn a large language model into a useful worker — if you stay within its sweet spot. The honest truth, informed by the custom agents we ship, is that n8n carries a well-scoped agent further than most people expect. An LLM node, a few tool/webhook nodes and a trigger are all you need. This guide walks you through that exact workflow and, just as importantly, names the precise moment n8n stops cutting it and a custom build must take over.
What You Need Before You Start
You'll need a running n8n instance (self-hosted or cloud) and API keys for the services you want to integrate. Grab a Gemini or OpenAI key from their respective developer consoles — n8n's also gives you a one-click import to see an agent's skeleton immediately.
How to Build an AI Agent with n8n: The Core Workflow
The core is a chain of nodes: a trigger wakes the agent, an LLM node reasons, and tool/webhook nodes take action. That's the entire pattern. Here's how to assemble it.
Set the trigger Drag a Webhook node onto the canvas if you want the agent called via HTTP, or a Schedule node to run it periodically. For our example, we'll use a webhook that receives a customer question.
Add the LLM node Attach an OpenAI Chat Model (or Gemini) node. In the node's parameters, craft a system prompt that scopes the agent. For a support bot, something like:
You are a helpful support agent for our SaaS product. Use the tools provided to answer questions.
If you don't know, say you need human help.
This prompt is the boundary of the agent's autonomy. Keep it specific — vagueness leads to hallucinations.
Attach tool and webhook nodes Here's where n8n shines. Drag a Function node to run custom JavaScript (e.g., querying a database) or a HTTP Request node to call an external API. Wire them as "tools" by connecting them to the LLM node's tool output. In the LLM node settings, enable Function Calling and list each tool node by name. The model will decide which tool to invoke based on the user's message.
| Node type | Purpose | Example | |------------------|-----------------------------------|-------------------------------| | HTTP Request | Fetch live data from a REST API | Pull customer order status | | Function (code) | Run custom logic or calculations | Validate email format | | Database | Query a connected database | Look up account history | | Webhook Response | Return the final answer | Send back the LLM's reply |
Wire it together and test Connect the trigger → LLM → tool nodes → (loop back if needed) → Webhook Response. Execute the workflow manually with a sample payload. Watch the LLM reason, pick a tool, and return a coherent answer.
That's it. You now have a working AI agent. The confirms: once logic gets complex, debugging becomes a time sink.
Rubric screeners with 380-case eval sets Imagine an agent that scores candidate interviews across 12 criteria, each requiring an audit trail showing exactly which rubric point triggered a score. That demands per-criterion scoring functions, a structured output schema, and a regression suite to validate against 380 known cases. n8n's nodes can call the LLM, but they offer no native way to version prompts and re-run the entire eval set on every change. Custom code with a pipeline and a test harness is the only safe route.
At these ceilings, a custom build isn't an extravagance — it's engineering necessity. If you're already brushing against them, our .
SOCIAL SHARE CARD GENERATOR