AI Messaging
Building an AI Reply Agent for Messenger, Instagram, and WhatsApp Without Breaking Meta Policies
AI agents can answer customers instantly, but messaging platforms have strict rules. How I design AI reply systems that stay compliant and safe in production.
AI replies follow the same Meta messaging rules
Meta's messaging rules do not change because a reply was written by a model. Messaging windows, template requirements, Human Agent rules, and commerce policies still apply. I design the AI agent as one sender inside a policy-aware messaging service, not as something that calls the Graph API directly.
This framing solves most compliance problems before they appear. The model decides what to say. The messaging service decides whether, how, and through which mechanism it can be said.
AI reply agent architecture
- Webhook ingestion validates, stores, and queues incoming messages.
- A conversation service loads history, customer context, and window state.
- The AI agent proposes a reply, using tools for bookings, orders, or knowledge base lookups.
- A policy layer checks the proposal: window open, allowed content, no sensitive data, correct sender type.
- The messaging service sends the reply and records it with the model, prompt version, and tools used.
The policy layer in code
The policy layer is small, deterministic, and tested like any other business rule:
def approve_ai_reply(conversation, reply):
if conversation.automation_paused:
return Reject("handed to human")
if not conversation.standard_window_open():
return Reject("window closed: AI cannot reply")
if contains_sensitive_data(reply.text):
return Reject("sensitive data")
if reply.confidence < settings.AI_MIN_CONFIDENCE:
return Escalate("low confidence")
return Approve(sender_type="ai")Note that the AI path never adds the HUMAN_AGENT tag and never sends templates. Those decisions belong to humans and to business events.
Meta policy guardrails for AI replies
- AI replies never use the Human Agent tag.
- The agent cannot send templates on its own. Templates are triggered by business events such as a confirmed booking.
- Clear escalation rules: complaints, payments, and repeated confusion go to a human.
- Customers can ask for a human at any time, and automation pauses when they do.
- Rate limits and fallbacks when the model provider is slow or unavailable.
- Tool inputs from the model are validated before they reach business services.
Escalation to human agents
Escalation is a feature, not a failure. When the agent escalates, the conversation is assigned to a queue, automation pauses, and the agent sees a short AI-written summary plus the full history. The customer receives an honest message that a person will reply.
Agents can hand the conversation back to automation when the issue is resolved. I log every handoff with its reason, which becomes the best source of ideas for improving prompts and tools.
Transparency for users and App Review
The privacy policy should say that message content is processed by an AI provider. In the App Review screencast, show both the automated reply and the handoff to a human. In my experience, being explicit about automation makes approval easier, not harder.
Cost and reliability
AI calls are the most expensive part of each conversation. Structured interactions such as buttons, lists, and WhatsApp Flows can replace many AI turns, as described in designing a WhatsApp booking bot. For the remaining AI calls, I set timeouts, retry with a fallback model, and send a safe holding message if both fail.
Testing an AI messaging agent before launch
I test the AI agent at three levels. Unit tests cover the policy layer and tool validation, which are deterministic. Scenario tests replay saved conversations, with personal data removed, against the agent and check that it calls the right tools, escalates when it should, and never produces replies the policy layer rejects. Finally, a small group of internal users talks to the agent on a test number before real customers do.
The scenario set grows from production: every escalation or mistake becomes a new test case. Over time this becomes the most valuable asset of the project, because it lets you change models or prompts with confidence instead of hoping nothing broke.
Measuring AI reply quality in production
- Resolution rate: conversations completed without a human.
- Escalation rate and escalation reasons.
- Time to first response and time to resolution.
- Customer messages that signal frustration, such as repeated questions or requests for a human.
- Cost per resolved conversation.
Prompt changes are versioned and compared on these metrics. An agent that answers fast but escalates poorly creates more work for operations, not less.
Frequently asked questions
Can an AI chatbot reply after the 24-hour window?
Not with free-form messages. Outside the window, WhatsApp requires approved templates, and Messenger and Instagram require an allowed message tag. AI replies should only run inside the standard window.
Can AI replies use the Human Agent tag?
No. The Human Agent tag is only for messages written and sent by a real person.
Do I need to tell users they are talking to AI?
Being transparent is strongly recommended and expected in many markets. Mention AI processing in your privacy policy and make it easy to reach a human.
How do I stop the AI from making up booking details?
Let the model call validated tools for facts, such as availability and prices, and reject replies that include data not returned by those tools.