Integrating AI Agents into SaaS Products: WhatsApp Bot + RAG Pipeline
How I built an AI-powered WhatsApp assistant with intent classification, agent orchestration, and a RAG pipeline for PharmacyHub.
By Hafiz Syed Muhammad Usman
PharmacyHub needed more than a static chatbot. Pharmacy students and professionals ask domain-specific questions that require context — drug interactions, exam preparation, marketplace decisions. I built an AI assistant that combines intent classification, agent orchestration, and retrieval-augmented generation.
Architecture: from message to answer
- WhatsApp message arrives via Evolution API
- BotDecisionEngine checks rate limits and mode
- IntentRouter classifies the question (general Q&A, MCQ generation, summarization, dev tools)
- AgentOrchestrator routes to the right executor — OpenAI Codex or Claude CLI
- Response goes back through Evolution API to WhatsApp
RAG for domain knowledge
Generic LLMs do not know your specific pharmacy curriculum, marketplace catalog, or community guidelines. The RAG pipeline in PharmacyHub indexes domain documents, retrieves relevant context at query time, and feeds it into the prompt. This turns a general-purpose model into a pharmacy domain expert without fine-tuning.
Commands that actually get used
- @bot <question> — general pharmacy Q&A with context retrieval
- /mcq <topic> — generates multiple-choice questions for pharmacy education
- /summary — summarizes the current chat thread
- /dev logs, /dev review, /dev patch — developer tools for the team
What I would do differently
Intent classification should be a lightweight local model, not an API call. The round-trip to classify intent before routing to the main LLM adds latency. Role-based access (DEVELOPER+ for advanced commands) was the right call from the start — it prevents abuse without blocking power users.