Observability for n8n AI Workflow Agents: Tracing Every LLM Call with Nexus
n8n's AI Agent node lets you drop a ReAct agent into any workflow with no code — but when the agent loops on a tool call, burns tokens retrying a bad prompt, or silently returns a hallucinated answer, your workflow logs show nothing. Here's how to wrap every n8n AI Agent execution with Nexus traces using HTTP Request nodes and n8n expressions, so you get span-level visibility into LLM calls, tool use, and token spend across every workflow run.
What n8n's AI Agent Node Does
n8n is an open-source workflow automation platform — think Zapier with a self-hostable option and a visual canvas for wiring together HTTP calls, databases, and business logic. The AI Agent node (added in n8n v1.19) drops a full ReAct agent into any workflow: give it a system prompt, connect tool nodes (web search, SQL, HTTP Request, custom functions), and it will autonomously loop through tool calls until it reaches an answer.
That's powerful for automating support tickets, lead qualification, document analysis, and dozens of other back-office workflows. The problem is that n8n's execution log shows you the final output and whether the run succeeded — nothing else. If the agent looped six times before answering, burned 4,000 tokens on a bad subquery, or called the wrong tool twice, you won't know unless you instrument it yourself.
Why n8n AI Agents Need External Observability
n8n execution history records node inputs and outputs at the workflow level, but the AI Agent node is a black box from n8n's perspective. The agent's internal reasoning — which tools it called, in what order, with what arguments, how many tokens each step consumed — is not surfaced in the execution log. You get the final answer or a top-level error. Nothing in between.
This matters in production because:
- Tool call loops — the agent retries a failing tool indefinitely, burning tokens and delaying the workflow, with no alert
- Silent hallucinations — the agent returns a confident answer without calling any tools; your log shows "success"
- Token spend spikes — a single complex workflow run can cost 10× the average; there's no built-in budget alert
- Multi-agent coordination — workflows with chained agents give you no visibility into which agent was the bottleneck
Nexus solves this with a REST API you can call directly from n8n's HTTP Request node — no SDK, no code nodes required for basic tracing.
The Approach: HTTP Request Nodes Around Every Agent
Because n8n is a no-code tool, the integration pattern is different from Python or TypeScript: instead of wrapping agent calls in code, you add three HTTP Request nodes to your workflow — one to start the trace, one to start the span, and one to end both after the agent finishes. n8n's expression engine lets you extract the agent's output, token counts, and tool call history from the AI Agent node's output JSON.
Here's the node sequence:
- HTTP Request: Start Trace — POST to
/v1/tracesbefore the AI Agent node - AI Agent node — runs normally
- HTTP Request: Start Span — POST to
/v1/spansreferencing the trace ID - HTTP Request: End Span — PATCH
/v1/spans/:idwith the agent output and token counts - HTTP Request: End Trace — PATCH
/v1/traces/:idwith overall status
Step 1: Start the Trace
Add an HTTP Request node at the very beginning of your workflow, before any AI Agent node. Configure it as a POST to https://nexus.keylightdigital.dev/v1/traces with your API key in the Authorization header. Pass the workflow name and any context you want to see in the Nexus dashboard as metadata.
curl -X POST https://nexus.keylightdigital.dev/v1/traces \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "n8n_agent_run",
"metadata": {
"workflow": "Customer Support Agent",
"trigger": "webhook"
}
}'
# Response:
# { "trace_id": "tr_abc123", "status": "started", "started_at": "2026-05-06T10:00:00Z" }
Store the response JSON — you'll need the trace_id in every subsequent node. In n8n, reference it with {{ $('Start Trace').item.json.trace_id }}.
Step 2: Start a Span for the Agent Node
Add a second HTTP Request node immediately before the AI Agent node (or right after, to capture the model name from the AI node's output). POST to /v1/spans and pass the trace_id from step 1. Include the agent's input prompt and the model name.
curl -X POST https://nexus.keylightdigital.dev/v1/spans \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"trace_id": "tr_abc123",
"name": "ai_agent_node",
"metadata": {
"node": "AI Agent",
"model": "gpt-4o",
"input": "User asked: How do I reset my password?"
}
}'
# Response:
# { "id": "sp_xyz789", "trace_id": "tr_abc123", "status": "started" }
Step 3: End the Span with Agent Output
After the AI Agent node succeeds, add a PATCH request to /v1/spans/:id. Use n8n expressions to extract the agent's output, token counts, and the number of intermediate steps (tool calls) from the AI Agent node's output:
// n8n HTTP Request node — Body (JSON)
// Place this node immediately AFTER your AI Agent node.
// Use the "Expression" toggle on each field.
{
"status": "success",
"metadata": {
"output": "{{ $('AI Agent').item.json.output }}",
"tokens_input": "{{ $('AI Agent').item.json.usage.input_tokens }}",
"tokens_output": "{{ $('AI Agent').item.json.usage.output_tokens }}",
"tool_calls": "{{ $('AI Agent').item.json.intermediateSteps.length }}",
"model": "{{ $('AI Agent').item.json.model }}"
}
}
The exact field paths depend on your n8n version and the model provider (OpenAI, Anthropic, Ollama). Check the AI Agent node's output in n8n's "Input/Output" panel to find the right expression paths for token counts and intermediate steps.
curl -X PATCH https://nexus.keylightdigital.dev/v1/spans/sp_xyz789 \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"status": "success",
"metadata": {
"output": "Click Account > Forgot Password and follow the email link.",
"tokens_input": 312,
"tokens_output": 27,
"tool_calls": 0
}
}'
Step 4: End the Trace
Finally, close the trace with a PATCH to /v1/traces/:id. Pass the overall status and any summary metadata you want to see at the top level in Nexus:
curl -X PATCH https://nexus.keylightdigital.dev/v1/traces/tr_abc123 \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"status": "success",
"metadata": {
"total_tokens": 339,
"duration_ms": 1840
}
}'
Handling Errors: The "On Error" Branch
n8n lets you connect an "On Error" output from any node. Wire the AI Agent node's error output to an HTTP Request node that patches the span and trace with status: "error". Without this branch, a failed agent run will leave the trace open in Nexus and you'll never see the error.
// In the "On Error" branch of your AI Agent node,
// add an HTTP Request node with this body to record failures:
{
"status": "error",
"metadata": {
"error": "{{ $('AI Agent').item.json.error.message }}",
"tool_calls_attempted": "{{ $('AI Agent').item.json.intermediateSteps.length }}"
}
}
After patching the span, add a second HTTP Request to end the trace with status: "error" as well. Then let the error branch continue to whatever notification flow you have (Slack, email, PagerDuty).
Multi-Agent Workflows: Nested Spans
Many production n8n workflows chain multiple AI Agent nodes — a classifier agent routes the request, then a specialized responder agent handles it. Start one trace at the beginning, then start a new span for each agent node and end it before the next agent starts. All spans share the same trace_id, so Nexus groups them into a single trace with the full call chain.
// For workflows with multiple AI Agent nodes,
// start one span per agent and nest them under the same trace_id.
// Span for first agent (Classifier):
POST /v1/spans
{
"trace_id": "{{ $('Start Trace').item.json.trace_id }}",
"name": "classifier_agent",
"metadata": { "node": "Classifier", "model": "gpt-4o-mini" }
}
// Span for second agent (Responder), started after classifier finishes:
POST /v1/spans
{
"trace_id": "{{ $('Start Trace').item.json.trace_id }}",
"name": "responder_agent",
"metadata": {
"node": "Responder",
"model": "gpt-4o",
"category": "{{ $('End Classifier Span').item.json.metadata.output }}"
}
}
In the Nexus trace detail view, you'll see each agent as a separate span with its own latency, token count, and status — making it easy to identify which agent is the bottleneck.
Token Budget Monitoring with a Scheduled Workflow
One of the most useful things you can do with Nexus from n8n is build a token budget alert — a separate scheduled workflow that queries your traces every hour and fires a Slack message if token spend exceeds a threshold. No custom code required beyond a simple Code node calculation:
// Schedule this n8n workflow to run every hour.
// HTTP Request node → GET /v1/traces?limit=100&status=success
// Then use a Code node to compute token spend:
const traces = $input.all().map(t => t.json)
const totalTokens = traces.reduce((sum, t) => {
return sum + (t.metadata?.total_tokens ?? 0)
}, 0)
// If over budget, trigger a Slack or email notification
if (totalTokens > 50000) {
return [{ json: { alert: true, tokens: totalTokens } }]
}
return [{ json: { alert: false, tokens: totalTokens } }]
Wire the alert: true output to a Slack or email node with the total token count. This gives you a real-time spend signal without touching any of your agent workflows.
What You'll See in Nexus
Once your first instrumented workflow runs, the Nexus dashboard shows:
- Trace list — every workflow run as a trace, with pass/fail status and total duration
- Span timeline — each AI Agent node as a span, with start time, end time, and latency
- Token counts — input and output tokens per span, and rolled up per trace
- Tool call count — how many intermediate steps (tool calls) the agent made before answering
- Error traces — failed agent runs with the error message, isolated from successful runs
Get Started
Sign up for a free Nexus account at nexus.keylightdigital.dev/pricing to get your API key. The free plan covers 10,000 spans per month — enough for a busy n8n automation environment. Then add the HTTP Request nodes to your first AI Agent workflow and you'll have trace-level visibility into every LLM call within minutes.
For a deeper integration (custom tool-level spans, token budget enforcement mid-workflow, or alerting on specific tool error patterns), see the Nexus REST API docs — all endpoints accept the same Authorization header you're already using.