Human handoff in WhatsApp AI agents
How to pass a conversation from an AI agent to a person: handoff signals, the message.echo event, Meta’s rule and how to hand it back to the bot.
Every AI agent makes mistakes, does not know something or meets a customer who wants a person. The handoff to a human is what makes the agent safe to put in production. It has three parts that must work together: detecting when to hand off, truly stopping replies and carrying the context to whoever will take over.
Why does every agent need a way out to a person?
For two reasons: customer experience and platform rules. Meta’s messaging policy, in the version consulted, says automated flows must offer prompt, clear and direct escalation paths, and cites as examples a transfer to a human agent in the conversation, a phone number, email, web channel, in-person service and a form.
In practice, an agent with no exit, or a hard one, makes customers repeat themselves, get annoyed and block or report the number, which hurts quality and, as a consequence, what you can send. The rules are summarized in the Meta chatbot rules article in this series. The AI agent guide in the docs has the simplest version of handoff, with a text marker in the prompt; this article shows the full version.
Which signals should trigger a handoff?
There are two kinds: those the agent detects and those that come from outside it. The agent’s own are the customer asking for a person, the agent not knowing the answer, the topic being on your sensitive list and repeated tool failures. The outside one is a team member taking over the conversation.
- Explicit request: the customer writes agent, human, person or the like. Do not argue and do not try to retain; hand off.
- Missing knowledge: knowledge base search found nothing or the model signals it does not know.
- Sensitive topics: complaints, cancellation, payment or whatever your business defines. List them in the system prompt.
- Failures: a tool that failed more than once, or a tool loop that hit its turn cap.
- Customer signals: repeated frustration or the same question for the third time.
Implement the decision as a tool, transferir_para_humano, with a reason field, instead of a marker in the middle of the text. That way the decision is structured, the reason is recorded and the text that goes to the customer is controlled by you, not by chance in generation.
How does the agent notice a person took over from the phone?
Through the message.echo event. On a number in coexistence, what the team types in the phone app reaches your webhook as message.echo, and that is the most reliable signal that a person took over. The agent should leave the conversation on its own.
// Signals that take the bot out of the conversation (one record per channel + contact)
async function aoReceberEvento(evento) {
const chave = evento.channel_id + ':' + (evento.data.from ?? evento.data.to)
// 1. Someone on the team replied from the phone (coexistence): message.echo
if (evento.event === 'message.echo') {
await estado.marcarHumano(chave, { origem: 'echo', em: Date.now() })
return
}
if (evento.event !== 'message.received') return
const conversa = await estado.carregar(chave)
if (conversa.humano) {
// The bot does not reply, but the customer’s message must reach the team.
return notificarEquipe(chave, evento.data.text)
}
// ...continue the normal agent flow
}
// 2. The agent itself decides to hand off (tool or marker)
async function transferir(chave, motivo) {
await estado.marcarHumano(chave, { origem: 'agente', motivo, em: Date.now() })
await notificarEquipe(chave, 'Handoff: ' + motivo)
// Line to the customer: says what happens and offers an alternative channel
return 'I will bring in a team member to continue with you. ' +
'If you prefer, we also help by email.'
}To receive the event, the webhook endpoint must subscribe to message.echo besides message.received. Event and signature details are in the webhooks reference, and coexistence explains the model of a number shared between the app and the API. Without coexistence there is no echo: whoever answers through your own panel or system must set the flag at the moment the person sends the first reply.
The snippet has a care that often goes missing: while the conversation is with a person, the customer’s messages keep arriving, and they must be delivered to the team. Stopping replies is not stopping listening. A conversation where the customer writes and nobody sees it is worse than the agent making mistakes.
What context should go to whoever takes over?
Enough that the customer does not have to repeat anything: the reason for the handoff, a short summary of what was said and the data already collected. The recipient reads it in seconds, and service starts from where the agent stopped.
- Reason: the sentence the agent recorded when handing off.
- Summary: two or three lines generated from the history, not the whole history.
- Collected data: order number, name, and what the agent already looked up with tools.
- Time and channel: which number it came from and when the 24-hour window closes, so the team knows until when free-form text works.
The last point matters: the 24-hour window counts from the customer’s last message. If the team member only replies later, free-form text fails with error 131047, and the way out becomes an approved template.
When and how do you hand the conversation back to the agent?
Only by an explicit rule, never by default. The typical bug is the bot answering again in the middle of a human conversation because the flag expired on its own or was cleared by mistake. Define what returns the conversation, and log every return.
// 3. Return to the bot: an explicit decision, never by accident
async function devolverAoBot(chave, motivo) {
await estado.limparHumano(chave, { motivo }) // 'closed-by-team' | 'no-messages-24h' | 'command'
}| Return trigger | When it makes sense | Risk |
|---|---|---|
| Conversation closed in your system | There is a clear end of conversation | Forgetting to clear the flag |
| Team command | The team wants to return to the bot | Depends on discipline |
| Time without messages | Conversations that die without closing | A short period returns it during a pause |
Whatever the trigger, the agent’s first text after a return should acknowledge that a person helped, and not restart as if it were the first time. The signals and the flag are part of the state described in the architecture article in this series. For delivery of events and credentials, see the quickstart.
Frequently asked questions
Should the agent say it is handing off to a person?
Yes. The line to the customer should say what happens next and, preferably, offer an alternative channel. Meta’s policy asks that the way out to a person be clear and direct.
Does message.echo exist on any number?
It is the event that arrives when the team replies from the phone app on a number in coexistence. Without coexistence, whoever answers through your system must signal the takeover themselves.
What if the customer writes while a person is handling it?
The agent does not answer, but the message must reach the team. Notify the team on every message received in a conversation with a human.
Can I hand the conversation back to the bot automatically after some time?
You can, if the period is chosen carefully and logged. Short periods make the bot return in the middle of a pause in service. Prefer returning when the service is closed.
Fontes
Documentação oficial da Meta, conferida em 31 de outubro de 2026.