# WhatsApp Cloud AI Handoff & Output Guardrails

> Meta WhatsApp HMAC verifier, currency-bound bot reply auditor, and SQLite WAL handoff state machine.

WhatsApp Cloud AI Handoff & Output Guardrails is a paid AI agent skill on Agensi by Víctor Betancourt, in Agents & Orchestration. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: $15 (one-time purchase)
- Creator: [Víctor Betancourt](https://www.agensi.io/creators/mc3yohan)
- Category: [Agents & Orchestration](https://www.agensi.io/skills/agents-orchestration)
- Version: 1.0
- Last updated: 2026-11-27
- Security: scan passed (2026-11-27); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/whatsapp-cloud-ai-handoff-output-guardrails
- Tags: ai-agents, api, automation, whatsapp, chatbot, guardrails, hmac, fastapi

## About this skill

Integrating LLMs with the WhatsApp Business Cloud API often results in double-replies during webhook retry storms and expensive price hallucinations. This skill implements a strict three-layer Deterministic Sandwich architecture to ensure webhooks are verified, messages are deduplicated, and bot outputs are audited against real catalog data before delivery.

### What it does
- **HMAC Verification** validates Meta `X-Hub-Signature-256` headers using `compare_digest` to prevent unauthorized webhook injection.
- **Idempotency Control** uses SQLite WAL and atomic `wamid` claiming to stop duplicate replies during provider retry storms.
- **Burst Debouncing** consolidates rapid-fire messages into a single agent turn using a 4-second idle window.
- **Output Guardrails** audits candidate LLM replies against `Decimal` catalog prices and stock counts to block delivery of hallucinated quotes.
- **Handoff Orchestration** enforces a fail-closed state machine that locks out the bot when a human operator is active.

### How it works
1. **Verify Webhooks** using the `verify_meta_webhook.py` script to sign and validate synthetic or live Meta payloads.
2. **Audit Output** by running `audit_bot_reply.py` against a local catalog JSON to ensure the LLM hasn't drifted from ground-truth pricing.
3. **Manage State** by implementing the provided SQLite patterns to track `HUMAN_PENDING` and `HUMAN_ACTIVE` conversation locks.

### Frameworks & tools
Built for Python 3.10+ using only the standard library and SQLite for maximum portability. Optimized for FastAPI raw-body handling and LLM-agnostic integration.

### Why this beats prompting it yourself
LLMs cannot reliably perform HMAC verification or atomic database operations, and system prompts frequently fail to prevent price hallucinations under pressure. This skill offloads critical security, idempotency, and financial accuracy tasks to deterministic code that fails closed if the LLM errs.

### Use cases
- Preventing bots from quoting incorrect prices or out-of-stock items in WhatsApp commerce flows.
- Stopping duplicate bot responses caused by Meta's aggressive webhook retry logic.
- Building a reliable human-in-the-loop takeover system for customer support.

### Known limitations
Requires access to raw HTTP request bytes for signature verification. Database deduplication requires a persistent SQLite volume or equivalent ACID store.

## Requires

- Python 3.10+

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the WhatsApp Cloud AI Handoff & Output Guardrails skill from Agensi" and describe your task.
3. Buy it on the listing or let your agent ask you first; your agent then loads it from Agensi when it needs it. Every paid skill has a money-back guarantee: https://www.agensi.io/docs/money-back-guarantee

## Frequently asked questions

### What specific WhatsApp integration problems does this skill address?

This skill solves 'double-reply' bugs caused by WhatsApp's retry logic, prevents unauthorized webhook spoofing, and acts as a financial guardrail to block the AI from hallucinating incorrect product prices.

### Is this skill compatible with specific AI agents or LLMs like GPT-4 or Claude?

The skill is LLM-agnostic and framework-portable; while optimized for FastAPI and Python 3.10+, it can be integrated into any AI agent workflow that handles raw HTTP request bytes.

### What assets are included in the purchase?

You receive the complete implementation logic, including the HMAC verification scripts, the SQLite state management patterns for human handoffs, and the deterministic price auditing module.

### Can I use this to switch between an automated bot and a live customer support agent?

Yes, the 'Handoff Orchestration' module implements a state machine that locks out the AI whenever a human agent is active, ensuring the customer never receives conflicting messages.

### Does this require a complex database setup to handle message deduplication?

No external heavy databases are required; the skill is designed to run using Python's standard library and a lightweight SQLite instance for ACID-compliant message deduplication.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
