Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

Multi-Agent Customer Support System

A plug-and-try multi-agent customer support pipeline. Bring your own knowledge base (PDFs), connect your Slack, and the system handles triage, resolution, and human escalation automatically — no code changes required.

Built with LangGraph, FastAPI, Qdrant, and Supabase.


Architecture

Customer Message
       │
       ▼
┌─────────────┐
│    Triage   │  Classifies intent / urgency / sentiment
└──────┬──────┘
       │
  ┌────┴────────────────┐
  │                     │
  ▼                     ▼
Out of scope?      Requires human?
  │                     │
  ▼                     ▼
Deflect           Escalation ◄──── Resolver confidence < 0.7
                       │
                       ├── Log to Supabase
                       └── Ping Slack
       │
       ▼
  Resolver (RAG)
       │
  confidence ≥ 0.7
       │
       ▼
  Final Response

Agents

Agent Trigger Output
Triage Every message intent, urgency, sentiment, requires_human
Resolver requires_human=False RAG answer + confidence score
Escalation requires_human=True OR confidence < 0.7 Handoff summary → Supabase + Slack
Deflect intent=out_of_scope Polite off-topic response, no KB lookup

Screenshots

Agent Pipeline Tracer — watch every routing decision in real time

Agent Pipeline Trace

RAGAS Evaluation Dashboard — per-sample metric breakdown

RAGAS Evaluation


Stack

Component Technology
LLM gemini-2.0-flash via langchain-google-genai
Embeddings models/embedding-001 (GoogleGenerativeAIEmbeddings)
Structured Output response_schema JSON mode
Agent Orchestration LangGraph StateGraph
Vector Store Qdrant
Conversation Memory Supabase PostgreSQL
Escalation Audit Supabase
Notifications Slack Web API (Block Kit)
API FastAPI + Uvicorn
Evaluation RAGAS

Plug-and-try

No code changes needed to adapt this to your use case:

  1. Drop your product documentation PDFs into data/
  2. Fill in .env with your API keys
  3. Set your Slack channel in SLACK_ESCALATION_CHANNEL
  4. Call POST /ingest to load your KB
  5. Done — the agents work with whatever content you provide

Quick Start

1. Prerequisites

  • Python 3.11+
  • Qdrant running locally or on Qdrant Cloud
  • Supabase project (free tier works)
  • Google AI API key
  • Slack bot token (optional)

2. Install

pip install -r requirements.txt

3. Configure

cp .env.example .env
# Fill in your keys

4. Set up Supabase

Run scripts/supabase_schema.sql in your Supabase SQL Editor.

5. Start Qdrant

docker run -p 6333:6333 -p 6334:6334 \
  -v $(pwd)/qdrant_storage:/qdrant/storage:z \
  qdrant/qdrant

6. Ingest your knowledge base

python run.py

curl -X POST http://localhost:8000/ingest \
  -F "files=@data/your_docs.pdf"

7. Open the frontend

Page Purpose
frontend/trace.html Watch the full agent pipeline execute in real time
frontend/admin.html Ingest PDFs, manage the knowledge base
frontend/eval.html Run RAGAS evaluation against a ground truth dataset

API Reference

POST /chat

{
  "session_id": "user-123",
  "message": "Where is my order?"
}

Response includes intent, urgency, sentiment, confidence, escalated, and retrieved_chunks.

POST /ingest

Upload one or more PDFs to the knowledge base.

curl -X POST http://localhost:8000/ingest \
  -F "files=@returns_policy.pdf" \
  -F "files=@shipping_guide.pdf"

GET /history/{session_id}

Conversation history for a session.

GET /kb-gaps

Questions the resolver failed to answer confidently, ranked by frequency. Use this to identify what content to add to your KB.

POST /evaluate

Run RAGAS evaluation. Returns faithfulness, context precision, context recall, and answer relevancy per sample.

curl -X POST http://localhost:8000/evaluate \
  -H "Content-Type: application/json" \
  -d '{"limit": 5}'

GET /health

Qdrant and Supabase connectivity check.


Escalation triggers

  • Triage flags the message as requiring a human (anger, legal threats, fraud, account security)
  • Resolver confidence falls below the configured threshold (default 0.7)
  • Either agent fails — safe fallback always escalates rather than returning a bad answer

When escalation fires, a handoff summary is logged to Supabase and a rich Block Kit card is posted to your Slack channel with full session context and a recommended action.


Evaluation (RAGAS)

The system includes a full RAG evaluation pipeline built on RAGAS. It measures whether the retrieval and answer generation are actually working — not just whether the API returns a 200.

How it works

For each question in the ground truth dataset, the pipeline:

  1. Retrieves the top-K chunks from Qdrant
  2. Generates an answer through the Resolver agent
  3. Scores the result across 4 metrics using RAGAS

Metrics

Metric What it measures Method
Faithfulness Answer stays within the retrieved context — no hallucination Token overlap between answer and retrieved chunks
Context Precision Retrieved chunks are ranked correctly — most relevant first Ranked chunk relevance vs ground truth
Context Recall Retrieved chunks cover the ground truth answer Sentence coverage of ground truth in retrieved chunks
Answer Relevancy Answer directly addresses the question asked LLM generates candidate questions from the answer, cosine similarity to original

How to try it

Step 1 — Generate the ground truth dataset

The repo ships with a 50-question dataset generator. Run it once after ingesting your KB:

python scripts/generate_eval_dataset.py

This creates data/eval_dataset.json — 50 questions with ground truth answers spanning shipping, returns, payments, edge cases, and out-of-KB questions (to verify escalation fires correctly).

Step 2 — Run evaluation via API

# Full run (all 50 samples — slow, makes ~200 LLM calls)
curl -X POST http://localhost:8000/evaluate \
  -H "Content-Type: application/json" \
  -d '{}'

# Quick run (5 samples — good for a first check)
curl -X POST http://localhost:8000/evaluate \
  -H "Content-Type: application/json" \
  -d '{"limit": 5}'

Step 3 — Or use the visual dashboard

Open frontend/eval.html in your browser. Set a sample limit and click Run Evaluation to see per-sample scores, a confidence bar per metric, and expandable answer/ground-truth comparisons.

Bring your own dataset

To evaluate against your own KB, edit scripts/generate_eval_dataset.py — replace the EVAL_DATASET list with your own question/ground_truth pairs and re-run the script.


Project structure

├── app/
│   ├── agents/
│   │   ├── triage.py          # Intent / urgency / sentiment classification
│   │   ├── resolver.py        # RAG retrieval + answer generation
│   │   └── escalation.py      # Handoff summary + Supabase + Slack
│   ├── graph/
│   │   ├── state.py           # LangGraph SupportState TypedDict
│   │   └── graph.py           # StateGraph: routing, deflect, finalize nodes
│   ├── rag/
│   │   ├── ingestion.py       # PDF → chunk → embed → Qdrant
│   │   ├── qdrant_store.py    # Qdrant client + retrieval
│   │   └── evaluator.py       # RAGAS evaluation pipeline
│   ├── db/
│   │   └── supabase_client.py # Conversation memory + escalation log + KB gaps
│   ├── services/
│   │   └── slack.py           # Slack Block Kit notifications
│   ├── utils/
│   │   └── rate_limiter.py    # API rate limiting
│   ├── config.py              # Pydantic Settings (all config from .env)
│   └── main.py                # FastAPI app + all endpoints
├── frontend/
│   ├── trace.html             # Live agent pipeline tracer
│   ├── admin.html             # KB ingestion dashboard
│   └── eval.html              # RAGAS evaluation dashboard
├── scripts/
│   ├── generate_faq_pdf.py    # Sample FAQ PDF generator
│   ├── generate_kb_pdfs.py    # Extended KB generator
│   ├── generate_eval_dataset.py
│   └── supabase_schema.sql    # Table definitions + RLS policies
├── tests/                     # Pytest suite (6 test files)
├── run.py
├── requirements.txt
└── .env.example

Environment variables

Variable Required Description
GOOGLE_API_KEY ✅ Google AI API key
SUPABASE_URL ✅ Supabase project URL
SUPABASE_SERVICE_KEY ✅ Supabase service role key
QDRANT_URL ✅ Qdrant URL (default: http://localhost:6333)
QDRANT_API_KEY — Qdrant Cloud API key (leave empty for local)
SLACK_BOT_TOKEN — Slack bot token — notifications disabled if unset
SLACK_ESCALATION_CHANNEL — e.g. #support-escalations
RESOLVER_CONFIDENCE_THRESHOLD — Escalation threshold (default: 0.7)
RETRIEVAL_TOP_K — Max chunks retrieved (default: 5)
MAX_HISTORY_TURNS — Conversation turns from Supabase (default: 10)

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages