{"product_id":"debug-ai-agent-tool-calls-with-openrouter-calculator-webhook","title":"Debug AI Agent Tool Calls with OpenRouter, Calculator \u0026 Webhook","description":"\u003ch3\u003eDebug tool calls in your n8n AI support agent—using Calculator, a simulated Order Lookup, and an incoming Webhook\u003c\/h3\u003e\n\u003cp\u003eThis n8n workflow helps you verify whether your AI Agent correctly calls tools, by comparing a correct arithmetic result, a found order response, and an empty order lookup that can still “succeed.” It’s Exercise 4 from the \u003cstrong\u003en8n Production AI Playbook on Audit \u0026amp; Trace\u003c\/strong\u003e.\u003c\/p\u003e\n\n\u003ch3\u003eWhat this workflow does\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003e\n\u003cstrong\u003eReceives a POST Webhook\u003c\/strong\u003e with a natural-language query.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eRuns “Support Agent”\u003c\/strong\u003e, an \u003cstrong\u003eAI Agent using an OpenRouter chat model\u003c\/strong\u003e, which decides whether to call a tool.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eUses the Calculator tool\u003c\/strong\u003e to handle arithmetic questions (e.g., “47 times 89”).\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eUses the Order Lookup Tool\u003c\/strong\u003e to return a \u003cem\u003esimulated\u003c\/em\u003e order record, or an \u003cstrong\u003eempty string when the order does not exist\u003c\/strong\u003e—useful for tracing “empty lookup” behaviors.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eResponds back to the webhook caller\u003c\/strong\u003e with the agent’s final answer.\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003ch3\u003eUse cases\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003e\n\u003cstrong\u003eAudit \u0026amp; Trace tool calling\u003c\/strong\u003e: confirm the agent calls Calculator for math and Order Lookup for order questions.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eDetect misleading “success”\u003c\/strong\u003e: compare replies when an order lookup returns an empty value (e.g., ORD-8888) versus a found record (e.g., ORD-1001).\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eSupport automation QA\u003c\/strong\u003e: validate end-to-end behavior before deploying a tool-using agent in production.\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003ch3\u003eTechnical details\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003e\n\u003cstrong\u003en8n nodes\u003c\/strong\u003e: \u003ccode\u003ewebhook\u003c\/code\u003e, \u003ccode\u003en8nn8n-nodes-langchainagent\u003c\/code\u003e (Support Agent), \u003ccode\u003erespond to webhook\u003c\/code\u003e, and tool nodes including \u003ccode\u003en8nn8n-nodes-langchaintool code\u003c\/code\u003e and \u003ccode\u003en8nn8n-nodes-langchaintool calculator\u003c\/code\u003e.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eOpenRouter integration\u003c\/strong\u003e: add an \u003cstrong\u003eOpenRouter API credential\u003c\/strong\u003e to “OpenRouter - Agent” and choose a \u003cstrong\u003emodel that supports tool calling\u003c\/strong\u003e.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eOptional tracing\u003c\/strong\u003e: enable \u003cstrong\u003eOpenTelemetry tracing\u003c\/strong\u003e in Settings \u0026gt; OpenTelemetry to view spans per tool call.\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003ch3\u003eQuick setup \u0026amp; customization\u003c\/h3\u003e\n\u003cp\u003eTest via the Webhook Test URL using queries like \u003ccode\u003e{\"query\":\"What is 47 times 89?\"}\u003c\/code\u003e and \u003ccode\u003e{\"query\":\"How much was order ORD-8888? Tell the customer the amount.\"}\u003c\/code\u003e. For clearer outcomes, you can customize the Order Lookup Tool to return \u003cstrong\u003e\"No order found\"\u003c\/strong\u003e instead of an empty string.\u003c\/p\u003e","brand":"N8N Commerce","offers":[{"title":"Default Title","offer_id":46157933609139,"sku":"N8N-20346","price":17.99,"currency_code":"GBP","in_stock":true}],"thumbnail_url":"\/\/cdn.shopify.com\/s\/files\/1\/0749\/6279\/6723\/files\/gnC_jU4HMqJ4LNhyrmrtE_j7ZnxnXB.png?v=1791018861","url":"https:\/\/buyflowscripts.com\/products\/debug-ai-agent-tool-calls-with-openrouter-calculator-webhook","provider":"N8N Commerce","version":"1.0","type":"link"}