8000
Skip to content

Nazir2608/ai-whatsapp-agent-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ai-whatsapp-agent-service

Production-grade WhatsApp AI Agent built using:

  • Spring Boot 3
  • Ollama (Local LLM – FREE)
  • MySQL
  • Redis
  • Qdrant (Vector DB)
  • Docker
  • Prometheus + Grafana

System Architecture

                         ┌─────────────────────────┐
                         │     WhatsApp User       │
                         └────────────┬────────────┘
                                      │
                                      ▼
                         ┌─────────────────────────┐
                         │  Meta WhatsApp Cloud    │
                         │       (Free Tier)       │
                         └────────────┬────────────┘
                                      │ Webhook
                                      ▼
┌────────────────────────────────────────────────────────────────┐
│                 ai-whatsapp-agent-service                      │
│                                                                │
│  ┌──────────────────────────────────────────────────────────┐  │
│  │                  Webhook Controller                      │  │
│  └──────────────────────────┬───────────────────────────────┘  │
│                             │                                   │
│                             ▼                                   │
│  ┌──────────────────────────────────────────────────────────┐  │
│  │                    Agent Service                          │  │
│  │                                                          │  │
│  │  1. Rate Limiting                                       │  │
│  │  2. Load Memory (Redis + MySQL)                         │  │
│  │  3. Tool Detection                                      │  │
│  │  4. RAG Search                                          │  │
│  │  5. Prompt Builder                                      │  │
│  │  6. LLM Call (Ollama)                                   │  │
│  │  7. Save Conversation                                   │  │
│  └───────────────┬───────────────┬─────────────────────────┘  │
│                  │               │                            │
│                  ▼               ▼                            │
│         ┌─────────────┐   ┌───────────────┐                   │
│         │   Redis     │   │    MySQL      │                   │
│         │ Short-Term  │   │ Long-Term DB  │                   │
│         └─────────────┘   └───────────────┘                   │
│                                                                │
│                  ▼                                              │
│         ┌──────────────────────────┐                           │
│         │        Qdrant            │                           │
│         │     (Vector Search)      │                           │
│         └──────────────────────────┘                           │
│                                                                │
│                  ▼                                              │
│         ┌──────────────────────────┐                           │
│         │         Ollama           │                           │
│         │     (Llama3 Model)       │                           │
│         └──────────────────────────┘                           │
│                                                                │
│                  ▼                                              │
│         ┌──────────────────────────┐                           │
│         │   WhatsApp Send API      │                           │
│         └──────────────────────────┘                           │
└────────────────────────────────────────────────────────────────┘

Feature Overview

Core Features

  • WhatsApp Webhook Integration
  • Local LLM (Ollama – llama3)
  • RAG (Retrieval Augmented Generation)
  • Tool Calling (Inventory, FAQ, Orders)
  • Redis Short-Term Memory
  • MySQL Persistent Memory
  • Rate Limiting (Bucket4j)
  • Structured Logging
  • Global Exception Handling
  • Monitoring with Prometheus
  • Dockerized Deployment

Project Structure

ai-whatsapp-agent-service/
│
├── controller/
├── service/
├── llm/
├── rag/
├── repository/
├── model/
├── config/
├── exception/
├── monitoring/
│
├── docker-compose.yml
├── Dockerfile
├── pom.xml
└── README.md

Infrastructure Setup

1️. Start Infrastructure

docker compose up -d

Services started:

  • MySQL
  • Redis
  • Qdrant
  • Ollama

2️. Install LLM Models

docker exec -it ollama ollama pull llama3
docker exec -it ollama ollama pull nomic-embed-text

WhatsApp Setup

  1. Create Meta Developer Account

  2. Add WhatsApp product

  3. Get:

    • Phone Number ID
    • Access Token
  4. Set Webhook URL:

ngrok http 8080

Use generated HTTPS URL as webhook.


Agent Processing Flow

User Message
     ↓
Webhook Controller
     ↓
Validate Signature
     ↓
Rate Limit Check
     ↓
Load Redis 
5F4A
Memory
     ↓
RAG Vector Search
     ↓
Tool Detection
     ↓
Build Prompt
     ↓
Call Ollama (LLM)
     ↓
Save Conversation
     ↓
Send WhatsApp Reply

About

This service receives WhatsApp messages, processes them using a local LLM, supports RAG-based knowledge retrieval, maintains conversation memory, and sends responses back to WhatsApp.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

0