How to Stop an AI Agent From Emailing 400 Customers at 3AM: Budget Caps, Idempotency & a Kill Switch in n8n
说明与用途
在 n8n 中实现保护模式,包括幂等键、月度预算、速率限制和杀死开关,防止了 400 封错误邮件的批量发送并控制了 LLM 成本。
问题
An unattended AI agent sent 400 incorrect emails at 3 AM, causing operational chaos.
结果
The guard pattern stopped unintended mass emailing, enforced budget limits, and added a kill switch, reducing operational risk.
工作流
- 1. Generate SHA‑256 idempotency key from client, action type, recipient, payload.
- 2. Insert key into guard_actions ledger in Postgres.
- 3. Query ledger for monthly cost per client and compare to cap.
- 4. Count actions in last hour and compare to rate cap.
- 5. If any check fails, send Slack alert, stop workflow with Error node; otherwise proceed with LLM call and outbound action.
证据
put one guard step in front of every LLM call and every outbound action
SHA-256 of client, action type, recipient, payload
SUM(cost_usd) by client and month vs cap
COUNT(*) of actions in last hour vs cap
Slack alert, then Stop and Error node
- 记录日期: 2026-11-02T09:14:17.545Z