How to Stop an AI Agent From Emailing 400 Customers at 3AM: Budget Caps, Idempotency & a Kill Switch in n8n
Описание и применение
Внедрение паттерна защиты в n8n, включающего ключ идемпотентности, контроль месячного бюджета, ограничение скорости и kill‑switch, предотвратило массовую рассылку 400 неверных писем и обеспечило контроль расходов.
Задача
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