Urgent.News

the world's headlines, one feed

Editions

AI

Building a Production WhatsApp AI Agent: Architecture That Actually Works

Everyone demos a WhatsApp chatbot. Few run one in production with real customers sending real messages 24/7. After 18 months of running SARA — an open-source WhatsApp AI agent serving businesses across 20 industries — here's what we learned about architecture that survives contact with reality. Why WhatsApp? The numbers are simple: 2B+ monthly active users 60% of SMB customers prefer messaging…

Building a WhatsApp AI Agent in Production: Architecture Lessons from SARA

Despite the growing popularity of WhatsApp, building a production AI agent handling real customer messages 24/7 is a challenging feat. After 18 months of running an open-source WhatsApp AI agent named SARA for businesses across 20 industries, the team has gathered crucial insights on the architecture that can withstand the realities of real-world usage.

WhatsApp's Unique Challenges

WhatsApp is not just another chat channel, it has unique constraints that can break naive implementations. With over 2B monthly active users, 60% of SMB customers prefer messaging over calling, and a remarkable 98% open rate (compared to just 20% for email), WhatsApp presents a lucrative opportunity for businesses to engage with their customers. However, these unique constraints require a specialized architecture to handle them effectively.

SARA's Architecture Overview

SARA's architecture consists of several key components working together:

1. WhatsApp (WAHA) → Bridge (:3008) → SARA API (:3006) → AI Provider Chain → Tool Dispatcher ↓ Groq → Cerebras → SambaNova → Mistral

2. Provider Fallback Chain: Single-provider AI is a production risk, so SARA uses a 4-provider chain: Primary (Groq), Fallback 1 (Cerebras), Fallback 2 (SambaNova), and Fallback 3 (Mistral - paid, always works). Each provider receives 2 retries with exponential backoff before failover, resulting in a 99.7% uptime over 6 months with $0 inference cost (thanks to free tiers).

3. Tool Calling: SARA doesn't just answer questions; she also executes actions like creating reservations, checking inventory, generating invoices, and scheduling appointments. The dispatcher maps 30+ tools to handlers with an autonomy gate, ensuring low-risk actions are executed immediately, medium-risk actions are executed with notification to an owner, and high-risk actions require confirmation from a human. This prevents the AI agent from booking a catering order for 500 people without human approval.

4. PII Handling: WhatsApp messages contain sensitive information like names, phone numbers, and addresses. SARA anonymizes this data before sending it to the LLM, processes it with anonymized data, and only de-anonymizes tool calls for actual reservations. PII is never logged in plain text.

5. Session Management: WhatsApp doesn't have traditional sessions, just a stream of messages. SARA manages context using a sliding window (last 20 messages), business context injection (CRM data, menu, pricing), and cross-conversation memory (remembering the last time you ordered risotto). This enables the agent to maintain context across conversations.

6. Self-Hosting vs Cloud: SARA runs on a single VPS with 4 vCPU and 8GB RAM. The total system footprint is only 3GB, with no GPU needed. Inference is offloaded to cloud providers like Groq, Cerebras, SambaNova, and Mistral.

7. Open Source: SARA is AGPL-3.0 licensed and available on GitHub (github.com/Alessandro114/sara). The self-hosted version is open source, while the cloud-only features (multi-tenant, white-label, analytics) are available in the commercial version. The project also includes 20 industry-specific agent definitions (scala-agent-definitions, Apache-2.0).

Key Learnings and Challenges

Running AI in production is 10% model quality and 90% engineering. Some of the hardest lessons learned include:

1. WhatsApp session contention: Running two instances of SARA with the same number results in instant logout for both. This was a hard lesson learned the hard way.

2. Date parsing: Handling dates across languages, timezones, and business hours requires extensive tuning and development time.

3. Message ordering: WhatsApp doesn't guarantee delivery order, so the bridge must queue and reorder messages by timestamp to ensure accurate processing.

4. Intent classification: SARA must classify user messages accurately to determine the appropriate action to take. This requires a well-designed intent classification system.

5. Risk assessment: Proper risk assessment is crucial for determining whether an action should be executed immediately, with notification to an owner, or require human confirmation. This helps prevent the AI agent from making potentially dangerous decisions.

With these lessons learned, SARA continues to evolve and improve, serving businesses across various industries. The open-source nature of SARA allows for customization and extension, enabling businesses to build their own vertical agents on top of the existing framework. As SARA demonstrates, building a production WhatsApp AI agent is possible, but it requires careful planning, engineering expertise, and a deep understanding of the unique challenges presented by the platform.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — it may contain errors, so check the original before relying on it.

Read the original at dev.to →

More in AI

AI to change education in Japan, reshape needed skills: Team Mirai leader

TOKYO -- The rapid evolution of generative artificial intelligence (AI) is poised to fundamentally change the meaning of learning in Japan. In an inte

  • AI will transform Japanese education by altering needed skills.
  • Memorization less important as AI handles intellectual tasks.
  • Creativity, communication, goal-setting vital for future success.

How to stop a Claude Code agent writing outside a directory

When you're sitting in front of an agent, "don't touch anything outside src/ " is enforced by you noticing. Unattended, it has to be enforced by something that runs whether or not anyone is watching.

  • Claude Code agents require restrictions when unattended
  • Declarative rules in settings.json use deny and allow lists
  • Code-based PreToolUse hook denies writes outside project directory