{"product_id":"n8n-log-ai-agent-runs-with-hash-chained-receipts-openai","title":"n8n Log AI Agent Runs with Hash-Chained Receipts \u0026 OpenAI","description":"\u003ch3\u003eRun an OpenAI AI agent with tamper-evident logging—every request gets a hash-chained receipt\u003c\/h3\u003e\n\u003cp\u003eThis n8n workflow exposes secure webhook endpoints that run an OpenAI-powered agent per client, then records each run into an \u003cstrong\u003en8n Data Table\u003c\/strong\u003e using a \u003cstrong\u003eSHA-256 hash chain\u003c\/strong\u003e. It also generates \u003cstrong\u003edaily integrity reports and anchors\u003c\/strong\u003e and provides a verification endpoint for clients.\u003c\/p\u003e\n\n\u003ch3\u003eWhat this workflow does\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003e\n\u003cstrong\u003eReceives webhook runs\u003c\/strong\u003e via POST with \u003ccode\u003eclient_id\u003c\/code\u003e and \u003ccode\u003eprompt\u003c\/code\u003e, validating client and prompt rules and rejecting invalid requests immediately.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eExecutes a LangChain AI agent\u003c\/strong\u003e using OpenAI Chat (with an optional Calculator tool) to produce an answer or capture an agent failure.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eCreates a logged receipt\u003c\/strong\u003e by hashing the prompt and answer (optionally storing clipped text), counting model\/tool calls, and tagging the outcome as \u003cem\u003eok\u003c\/em\u003e, \u003cem\u003erefused\u003c\/em\u003e, or \u003cem\u003eerror\u003c\/em\u003e.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eAppends a new hash-chained entry\u003c\/strong\u003e into the \u003ccode\u003eagent_run_log\u003c\/code\u003e table by linking to the latest entry’s hash, computing the next \u003ccode\u003eentry_hash\u003c\/code\u003e, and confirming canonical sequence (with short backoff retries on collisions).\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eReturns the result with integrity proof\u003c\/strong\u003e including \u003ccode\u003eseq\u003c\/code\u003e and \u003ccode\u003eentry_hash\u003c\/code\u003e. If reliable logging fails, it withholds the agent output and returns HTTP \u003cstrong\u003e503\u003c\/strong\u003e.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eNotifies the owner and verifies daily\u003c\/strong\u003e: a scheduled run recomputes and verifies all clients’ hash chains in \u003ccode\u003eagent_run_log\u003c\/code\u003e, stores anchors in \u003ccode\u003eagent_run_anchors\u003c\/code\u003e, and emails a report (or failure notice).\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003ch3\u003eUse cases\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003eSaaS operators needing \u003cstrong\u003eauditable AI responses\u003c\/strong\u003e for compliance and dispute resolution.\u003c\/li\u003e\n  \u003cli\u003eAutomation engineers implementing \u003cstrong\u003etamper-evident agent logs\u003c\/strong\u003e for multi-tenant n8n apps.\u003c\/li\u003e\n  \u003cli\u003eTeams that want \u003cstrong\u003eclient-accessible verification\u003c\/strong\u003e of each run via a dedicated endpoint.\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003ch3\u003eTechnical details\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003en8n nodes\/tools: \u003ccode\u003ewebhook\u003c\/code\u003e, \u003ccode\u003eif\u003c\/code\u003e, \u003ccode\u003eset\u003c\/code\u003e, \u003ccode\u003ecode\u003c\/code\u003e, \u003ccode\u003ewait\u003c\/code\u003e, \u003ccode\u003eswitch\u003c\/code\u003e\n\u003c\/li\u003e\n  \u003cli\u003eAI stack: LangChain AI agent with \u003cstrong\u003eOpenAI Chat\u003c\/strong\u003e and optional \u003cstrong\u003eCalculator\u003c\/strong\u003e tool\u003c\/li\u003e\n  \u003cli\u003eStorage: \u003ccode\u003eagent_run_log\u003c\/code\u003e and \u003ccode\u003eagent_run_anchors\u003c\/code\u003e n8n Data Tables\u003c\/li\u003e\n  \u003cli\u003eIntegrity: \u003cstrong\u003eSHA-256\u003c\/strong\u003e hash chaining, sequence verification, daily recomputation\/anchoring\u003c\/li\u003e\n\u003c\/ul\u003e","brand":"N8N Commerce","offers":[{"title":"Default Title","offer_id":46196346159283,"sku":"N8N-20696","price":36.99,"currency_code":"GBP","in_stock":true}],"thumbnail_url":"\/\/cdn.shopify.com\/s\/files\/1\/0749\/6279\/6723\/files\/iy9fEtJMRRAAxouao-IwG_ldKB3O5d.png?v=1791623799","url":"https:\/\/buyflowscripts.com\/products\/n8n-log-ai-agent-runs-with-hash-chained-receipts-openai","provider":"N8N Commerce","version":"1.0","type":"link"}