Building an AI Agent Node Workflow in n8n
Build a production-shaped n8n path: trigger → AI Agent (model + tools) → action, with retries, naming, and a stop on failure that humans can operate.
Search across all documentation pages
Build a production-shaped n8n path: trigger → AI Agent (model + tools) → action, with retries, naming, and a stop on failure that humans can operate.
Use n8n's AI Agent node as the control loop host, attach a chat model (preferably via OpenRouter), grant one to three tools, and terminate in a deterministic action node rather than leaving the answer only in execution logs.
triage-support-email, not My workflow 12).Conceptual graph (node names you can mirror in the UI):
[Webhook]
path: /support-triage
method: POST
body: { "from": "...", "subject": "...", "body": "..." }
↓
[AI Agent]
system: |
You triage inbound support mail.
Use lookup_order only when an order id like ORD-12345 appears.
Final answer must be JSON:
{"label":"BILLING|TECH|OTHER","reply":"...","needs_human":true|false}
tools:
- lookup_order (HTTP GET https://api.example.com/orders/{{order_id}})
model: OpenRouter Chat Model → openai/gpt-4o-mini (verify at build)
↓
[IF needs_human === true]
true → Slack #support-leads with full payload
false → Helpdesk "Create ticket" or "Send reply" node
↓
[Respond to Webhook] 200 { "ok": true, "label": "..." }Expression hygiene tips:
{{ $('Webhook').item.json.body.subject }})."false" is truthy in some expression contexts.Optional Code node to normalize JSON:
// n8n Code node (JavaScript) - run once per item
let text = $input.first().json.output
?? $input.first().json.text
?? $input.first().json.message?.content
?? "";
text = String(text).trim();
if (text.startsWith("```")) {
text = text.replace(/^```(?:json)?\n?/i, "").replace(/\n?```$/i, "");
}
const parsed = JSON.parse(text);
return [{ json: parsed }];| Pattern | Behavior | Prefer when |
|---|---|---|
| Chat Model → IF → Action | You own every step | Classification, fixed drafts |
| AI Agent + tools | Model chooses tool calls in a loop | Lookup-then-answer, multi-step research lite |
| Sub-workflow tools | Agent calls reusable workflows | Shared connectors across bots |
Start fixed when the plan is known. Move to AI Agent when the presence of tool use depends on the input.
lookup_order_by_id, not http).| Trigger | Watch-outs |
|---|---|
| Webhook | Auth (header secret), payload size, idempotency on retries |
| Schedule | Overlap if a run exceeds the interval; disable concurrent runs if needed |
| Email / IMAP | Duplicate processing; store message ids |
| App trigger | Vendor rate limits; partial payloads |
Use separate credentials for pilot vs prod. Do not reuse a personal OAuth token for a team-critical bot.
If self-hosting n8n, treat the instance like an app server: SSO if available, restricted network egress, encrypted credentials store, and backups of workflow JSON.
| Approach | Pros | Cons |
|---|---|---|
| AI Agent node + tools | Flexible mid-run decisions | Harder to test; loop risk |
| Fixed Chat Model chain | Predictable, easy logs | Rigid for variable tool need |
| Zapier AI actions | Familiar for business ops | Different limits/pricing model |
| HTTP to custom agent API | Full control in code | You own deploy and auth |
| Sub-workflows only | Reuse and clarity | More graph navigation overhead |
No. You need clear prompts, credentials, and data mapping. LangChain-shaped concepts appear in some node names, but you configure them visually.
One, then three maximum for a pilot. Each tool multiplies failure modes and bad call risk.
Prefer the agent producing structured output and a dedicated Slack node sending it. Delivery stays visible and retryable without re-invoking the model.
Use Manual Trigger, pinned sample payloads, and a pilot Slack channel or dry-run sheet. Swap credentials only after golden cases pass.
Typical n8n automations are request/response or async side effects. Product-grade token streaming usually belongs in a web app or dedicated agent service.
System field of the agent/model node, or a static markdown doc loaded once into a Set node. Keep user turns for untrusted variable content.
Fix credentials and token refresh first. Then set retries on the HTTP node or fail the workflow to Error Trigger rather than letting the agent invent success.
Yes for small pure transforms. If Code nodes dominate, you are signaling a migration toward a real service.
Store files in object storage or helpdesk, pass references/ids into the agent, and summarize rather than pasting megabytes into the prompt.
Yes, sequentially or on branches. Keep a single "owner" of the user goal and clear handoff fields so you do not build accidental multi-agent chaos.
Related: No/Low-Code Orchestration Basics
Related: Connecting OpenRouter as n8n's Model Backend
Related: When Visual Workflow Tools Beat Writing Custom Agent Code
Related: From No-Code Prototype to Custom Code: A Migration Path
Stack versions: Pins from the category manifest (verify at build): OpenRouter (~315+ models, July 2026 pricing/fees); LangGraph 1.0+; CrewAI 1.14+; Microsoft Agent Framework 1.0; Vercel AI SDK 6; Pydantic AI (latest); LlamaIndex (latest); OpenAI Agents SDK (latest + MCP); MCP (Linux Foundation governance); A2A (HTTP+SSE+JSON-RPC 2.0); Solana
@solana/web3.js+@solana/spl-token.
Reviewed by Chris St. John·Last updated Jul 16, 2026