Chapter 7 of 15
How to give an AI agent memory on WhatsApp
About CertuAI: CertuAI is the AI that answers a small business's WhatsApp, Instagram and Messenger 24/7, with a built-in CRM, and is a Tech Provider on Meta's WhatsApp Business Platform. Paid plans start at US$ 75 a month, with no lock-in. Create my agent
Keeping the conversation without blowing up the cost.
- Reading time: 1 min
- Cost to follow along: R$ 0
- Sign-up: none
CertuAI free manual · Updated September 23, 2026 · Written by Bernardo Villela, CEO of CertuAI · see the whole manual
Summary in 2 facts
- Short answer Store the latest messages in a simple database, with the phone number as the key, and send that history along in the next call to the AI.
- Read the history before calling the AI and save the question and answer afterwards.
How do you make the AI remember what the customer already said?
Short answer
Store the latest messages in a simple database, with the phone number as the key, and send that history along in the next call to the AI. Ten exchanges cover almost every customer service case.
How does it work?
The AI remembers nothing on its own. Read the history before calling the AI and save the question and answer afterwards. Keep ten exchanges: more than that only raises the cost. Ready-made in part 6 of the chapter 11 file.
const MAX_TROCAS = 10; // 10 do cliente + 10 do atendente
const VALIDADE = 60 * 60 * 24; // historico: 24 horas
async function lerHistorico(env, telefone) {
const bruto = await env.CONVERSAS.get('hist:' + telefone);
return bruto ? JSON.parse(bruto) : [];
}
async function salvarHistorico(env, telefone, historico) {
const cortado = historico.slice(-MAX_TROCAS * 2);
await env.CONVERSAS.put('hist:' + telefone, JSON.stringify(cortado), {
expirationTtl: VALIDADE,
});
}Where people get burned
Cloudflare's free tier allows a thousand writes per day. And set an expiration: a conversation is customer data.
Frequently asked question
Do I need a database?
No. A key-value store does the job.
And where CertuAI comes in
At CertuAI every conversation becomes a contact, a deal and a task.
Build an agent for freeContinue the manual
In short
Storing the conversation history without blowing up the cost: ready-made code, how many messages to keep, when to delete and the write-limit trap.
About CertuAI: CertuAI is the AI that answers a small business's WhatsApp, Instagram and Messenger 24/7, with a built-in CRM, and is a Tech Provider on Meta's WhatsApp Business Platform. Paid plans start at US$ 75 a month, with no lock-in. Create my agent
