This project implements a multi-agent customer support system for a fictional mobile carrier called FM.inc, integrated with WhatsApp via Kapso. The system routes incoming messages through a LangGraph StateGraph, dispatching them to specialized agents: one for product/service information (RAG + Pinecone) and one for technical support (tool-based ticket management via PostgreSQL). Every conversation is persisted per user phone number using an AsyncPostgresSaver checkpointer.
A complementary n8n workflow extends the system by listening to real-time database changes and notifying the support team via email, enabling them to manage ticket status directly from their inbox.
graph TD
WA["📱 WhatsApp"] --> K["Kapso"]
K -->|POST /webhook| API["FastAPI"]
API -->|BackgroundTask| G["LangGraph StateGraph"]
G --> T["🔀 Triage"]
T -->|"intent: info"| IA["📚 Info Agent<br/>(RAG + Pinecone)"]
T -->|"intent: soporte"| SA["🔧 Support Agent"]
SA -->|tool_calls?| TC{"tools_condition"}
TC -->|sí| TOOLS["⚙️ ToolNode<br/>(inject phone)"]
TOOLS -->|resultado| SA
TC -->|no| FR["📝 Format Review"]
IA --> FR
FR -->|respuesta| SUM{"should_summarize?"}
SUM -->|">6 msgs"| SC["🧠 Summarize"]
SUM -->|"≤6 msgs"| REPLY["📱 WhatsApp Reply"]
SC --> REPLY
style T fill:#f59e0b,color:#000
style IA fill:#3b82f6,color:#fff
style SA fill:#8b5cf6,color:#fff
style TOOLS fill:#6366f1,color:#fff
style FR fill:#10b981,color:#fff
style SC fill:#ec4899,color:#fff
llama-text-embed-v2, 1024 dims)Every WhatsApp message arrives as a POST request to the FastAPI /webhook endpoint via Kapso. The user's phone number is extracted and stored in the shared state — it will be used later to identify them in the database without ever trusting the LLM with it.