In-houseWhatsApp AI agents
WhatsApp Agents: our service for AI WhatsApp conversations
By Sagar DavaraPublished
In productionIn short
WhatsApp Agents is Mirai Minds' own service for running AI conversations on WhatsApp. It receives messages from Meta's webhook, waits for the customer to finish typing, builds context from a rolling summary, recent messages and Mem0 memories, and answers with Gemini. One deployment serves several business numbers, and it runs iKoMatch's founder conversations.
The story
The problem
Our WhatsApp builds kept needing the same core: receive Meta's webhook, route the message to the right business account, remember the customer across weeks, answer from documents, and follow WhatsApp's rules on templates and the 24-hour window. Rebuilding that per client wasted time, so we built it once as a service.
What we built
- Message handling. A FastAPI webhook receives messages, looks up the account by phone number ID, saves the message and starts a 3-second debounce, so a burst of short messages gets one reply.
- Context building. Every 20 messages are folded into a rolling summary of at most 150 words. Each reply sees that summary, the last 20 unsummarized messages and the Mem0 memories relevant to the current message, which keeps prompts small in long conversations.
- Gemini with tools. Replies come from Gemini, with tools and document retrieval through a retrieval service shared with our Voice Agents platform. Account owners can set their own Gemini key and model.
- Media and documents. Images and files go to S3 and are described for the agent; decks are converted before reading.
- Outbound messaging. Templates, broadcasts, follow-ups and conversation stages, so campaigns stay inside WhatsApp's rules.
How it works in production
The service runs iKoMatch's founder conversations: signup, deck intake and the daily investor slates of a 45-day campaign. For every known number, iKoMatch's backend returns the founder's status with a matching prompt, which replaces the account's default prompt. Replies are split into short bubbles with natural pauses, so they read like texting. The patterns are described under WhatsApp AI agents.
What we'd change
- Put human takeover in the core service. Today the team inbox for staff replies lives in the client's dashboard, as it does for iKoMatch. Building it into the service would give every deployment the same takeover flow.
- Grade conversations every night. iKoMatch's recommendations get a nightly LLM judge; the conversations themselves deserve one too, scoring a sample of each day's chats against a fixed list of issues.
Stack
What it runs on
- AI
- Gemini (google-genai)Mem0
- Backend
- FastAPIPostgreSQLSQLAlchemy (async)Alembic
- Messaging
- WhatsApp Business Platform (Cloud API)
- Storage and documents
- Amazon S3Shared retrieval serviceunoserver