How to Trigger an n8n AI Agent With a Webhook
A webhook is the front door. The AI Agent is the worker. Here is what each piece does and how the reply gets back to the caller.
- published
Some client projects need an agent that wakes up only when something calls it. A form posts data. A chat app sends a message. In n8n, the pairing for that is a Webhook node in front of an AI Agent node. The webhook is the front door. The agent is the worker behind it. If you want the wider picture first, read how n8n AI agents work.
What a webhook-triggered agent is
The docs say the Webhook node receives data from apps and services when an event occurs. It also triggers workflows from services that have no dedicated app trigger node. So a service with no dedicated trigger node can still start your workflow.
The docs say the AI Agent node lets you build an AI agent in n8n. Put the Webhook node first, then the agent, and the request that arrives becomes the input the agent works from. The docs say the Webhook node can also return the data a workflow generates, like an API endpoint. That last part is what makes this pairing more than a one-way pipe.
How the Webhook node works
The docs say the Webhook node has two URLs, test and production. They serve different jobs.
The test URL is for building. The docs say a test webhook shows the incoming data in the workflow. So while you wire things up, send requests to the test URL and watch what arrives. That tells you the exact shape of the data before you write any expressions.
The production URL is the real one. The docs say n8n registers a production webhook when you publish the workflow. Until you publish, the production URL does nothing. If a client says the endpoint returns nothing, check that the workflow is published.
After it is live, the docs say you can view production webhook runs in the workflow's Executions tab. That is where you go when a run failed and you need to see what the caller sent.
The docs say the Webhook path is a randomly generated URL path by default. You can set a fixed path instead, which the docs say is useful when prototyping an API. The node also supports standard HTTP request methods, so pick the one the calling service uses.
What the agent does once triggered
The agent does not run a fixed script. The docs say the AI agent uses external tools and APIs to perform actions and retrieve information. It can understand what different tools do and decide which one fits the task.
So when the webhook fires, the agent reads the incoming data and your instructions, then picks a tool. The docs say an agent decides which tool to use based on your instructions and the task. The docs also say you must connect at least one tool sub-node to an AI Agent node. For what to connect, see tools for n8n AI agents.
Instructions carry most of the weight here. The docs say to keep agent instructions specific, and to refine them first if the agent misbehaves. Before you publish, the docs say you can preview an agent to test it without publishing.
Getting the answer back to the caller
The docs describe several ways to respond, and they suit different jobs.
The docs say the Webhook node can answer right away with the message Workflow got started. That is for when the caller only needs to know the run began.
The docs say the When Last Node Finishes option returns the response code and the output of the last node. That works when the agent's output should be the reply, and the caller can wait for it.
The docs say the Respond to Webhook node lets the workflow define the response. Use that when you want to shape the reply yourself, or send something other than the last node's raw output.
The docs say the Webhook Response Code can be a common code or a custom one. Pick the code that tells the caller the truth about what happened.
Streaming is also possible. The docs say the Webhook streaming response needs nodes with streaming support, like the AI agent node. So a long answer can reach the caller as it is written rather than all at once at the end.
One quirk to know. The docs say n8n wraps HTML responses to webhooks in iframe tags as a security mechanism. If the caller expects plain HTML, expect the wrapper.
Securing the webhook
A production webhook is a public endpoint that runs your client's workflow. Treat it like one.
The docs say a webhook can use Basic auth, Header auth, or JWT auth for any service calling the URL. Pick the kind the calling service can send.
Beyond auth, the node offers filters. The docs say the IP(s) Allowlist option limits who can invoke a Webhook trigger URL. The docs say the Ignore Bots option ignores requests from bots like link previewers and web crawlers. The docs say the Only Run If option runs the workflow only when an expression on the request returns true. Use it to reject payloads that are missing fields.
For browser callers, the docs say the Allowed Origins (CORS) option sets the permitted cross-origin domains. For odd payloads, the docs say the Webhook Raw Body option receives data in a raw format, such as JSON or XML. The docs say the Binary Property option lets the Webhook node receive binary data like an image or audio file.
Self-hosting notes
The docs say webhooks for external trigger nodes need n8n to be reachable from the web. If your n8n copy sits on a laptop, outside services cannot reach it, so the webhook never fires.
For local development, n8n offers a tunnel. The docs say the tunnel is for local development and is not safe to use in production. Use it to test, then host n8n somewhere reachable before the client goes live.
Where to go next
The webhook gets the request in. The agent does the work. The pieces that shape the work are the agent's tools and its memory. Read about memory in n8n AI agents to decide if the agent should recall earlier calls. See the n8n AI Agent page for the node's own settings. If your agent instead needs to run on a clock, look at how the n8n Schedule Trigger picks its time.