Skip to content

Latest commit

ย 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿค– AI Support Copilot

CI Python FastAPI OpenAI Docker License: MIT Code style: ruff

Intelligent customer support ticket automation โ€” classification, reply drafting, structured field extraction, CRM write-back, and human-in-the-loop approval.

Live Demo ยท API Docs ยท Architecture


โœจ What It Does

A production-ready AI agent that processes support tickets through a 3-step pipeline in 4โ€“8 seconds โ€” replacing 60%+ of manual triage work:

๐Ÿ“ง Ticket IN
    โ”‚
    โ”œโ”€ [1] Classify    โ†’ billing / bug / feature / urgent / general  (+ confidence)
    โ”‚
    โ”œโ”€ [2] Draft Reply โ†’ professional email reply (category-specific prompt)
    โ”‚
    โ””โ”€ [3] Extract     โ†’ priority ยท sentiment ยท action items ยท key entities
                โ†“
    ๐Ÿ“Š Google Sheets  โ†โ†’  ๐Ÿ’ฌ Slack (approve/reject)  โ†โ†’  ๐Ÿ“ˆ Prometheus

Human-in-the-Loop gate: If confidence < 75%, the ticket is flagged for Slack review with โœ…/โŒ buttons before any reply is sent.


๐Ÿง‘โ€๐Ÿ’ป My Role

I designed and implemented the full pipeline, prompts, API integration, and reliability strategy. Built the end-to-end architecture from LLM agent orchestration to the frontend dashboard.


๐Ÿ“ธ Live API Test

(Input: typical support ticket โ†’ Output: classification + priority + drafted reply)

FastAPI Process Ticket Result


๐Ÿ“Š Performance Metrics

Evaluated on a labeled test set of 100 tickets spanning all 5 categories.

Metric Value
๐ŸŽฏ Classification Accuracy 92%
โšก Avg End-to-End Latency ~5.2s
๐Ÿ“ˆ P95 Latency ~8.1s
๐Ÿ‘€ Human Review Trigger Rate 12% (confidence < 0.75)
โฑ Estimated Time Saved / Ticket ~4 min (63%) vs. manual triage
๐Ÿšจ Urgent Detection Recall 100% (0 missed urgents)

๐Ÿ”’ Error Handling & Reliability

LLM Call Fails
  โ”‚
  โ”œโ”€ Retry ร— 3 (exponential backoff: 1s โ†’ 2s โ†’ 4s)
  โ”‚
  โ”œโ”€ Fallback to generic reply draft
  โ”‚
  โ””โ”€ confidence=0 โ†’ needs_review=true โ†’ Slack human queue

Google Sheets Unreachable
  โ””โ”€ Local JSONL fallback โ†’ logs/sheets_fallback.jsonl

Low Confidence (< 0.75%)
  โ””โ”€ Slack Block Kit message with โœ… Approve / โŒ Reject buttons
     โ””โ”€ SLA: 30min manual review window

๐Ÿ— Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    FastAPI Application                    โ”‚
โ”‚  POST /tickets      POST /tickets/batch   GET /metrics   โ”‚
โ”‚  GET /              POST /webhook/slack   GET /stats      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                           โ”‚
              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
              โ”‚     Pipeline (async)     โ”‚
              โ”‚                         โ”‚
              โ”‚  1. Classify Ticket      โ”‚  โ† GPT-4o-mini JSON mode
              โ”‚     โ†“ (parallel)        โ”‚
              โ”‚  2. Draft Reply   โ”€โ”€โ”   โ”‚  โ† Category-specific prompts
              โ”‚  3. Extract Fields  โ”˜   โ”‚  โ† Structured output
              โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                           โ”‚
           โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
           โ–ผ               โ–ผ              โ–ผ
    Google Sheets      Slack Bot     Prometheus
    (gspread API)   (Block Kit UI)  (/metrics)
                           โ”‚
                    โœ… Approve / โŒ Reject
                           โ”‚
                    POST /webhook/slack

๐Ÿš€ Quick Start

1. Clone & Configure

git clone https://github.com/chenweilie/ai-support-copilot.git
cd ai-support-copilot

cp .env.example .env
# Edit .env with your API keys

2. Run with Docker (recommended)

docker-compose up -d

The dashboard will be live at http://localhost:8000
API docs at http://localhost:8000/docs

3. Run Locally

# Create virtual environment
python -m venv .venv
source .venv/bin/activate  # Windows: .venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Start the server
uvicorn app.main:app --reload --port 8000

โš™๏ธ Configuration

Copy .env.example to .env and fill in your credentials:

Variable Required Description
OPENAI_API_KEY โœ… Your OpenAI API key
GOOGLE_CREDS_JSON Optional Service account JSON (inline)
GOOGLE_SHEET_ID Optional Target spreadsheet ID
SLACK_BOT_TOKEN Optional Slack bot token (xoxb-...)
SLACK_CHANNEL Optional Target channel (default: #support-copilot)
CONFIDENCE_THRESHOLD Optional Review threshold (default: 0.75)

Minimum setup: Only OPENAI_API_KEY is required. Sheets and Slack are optional integrations.


๐Ÿ“ก API Reference

POST /tickets

Process a single ticket through the full pipeline.

curl -X POST http://localhost:8000/tickets \
  -H "Content-Type: application/json" \
  -d '{
    "ticket_id": "TKT-001",
    "subject": "Cannot access billing portal after payment",
    "body": "Hi, since I paid for the Pro plan yesterday I still cannot access the billing section. It shows Access Denied.",
    "customer_email": "john@company.com"
  }'

Response:

{
  "success": true,
  "ticket_id": "TKT-001",
  "category": "billing",
  "confidence": 0.94,
  "needs_review": false,
  "status": "pending",
  "reply_draft": "Hi John,\n\nThank you for reaching out...",
  "priority": "high",
  "sentiment": "negative",
  "action_items": [
    "Verify upgrade was processed correctly in billing system",
    "Check account access permissions for billing module",
    "Apply Pro plan access privileges manually if upgrade didn't propagate"
  ],
  "latency_ms": 4821.3
}

POST /tickets/batch

Process up to 20 tickets concurrently.

curl -X POST http://localhost:8000/tickets/batch \
  -H "Content-Type: application/json" \
  -d '{"tickets": [...]}'

GET /stats

Current processing statistics and recent ticket history.

GET /metrics

Prometheus metrics endpoint.


๐Ÿงช Testing

# Run unit tests (no API key needed)
pytest tests/ -k "TestModels or TestFixtures" -v

# Run integration tests (requires OPENAI_API_KEY)
pytest tests/ -v

# Run full 100-ticket accuracy benchmark
RUN_BATCH_TEST=1 pytest tests/test_pipeline.py::TestPipelineBatch::test_batch_accuracy -v -s

๐Ÿ“ Project Structure

ai-support-copilot/
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ main.py                 # FastAPI entry point, all routes
โ”‚   โ”œโ”€โ”€ models.py               # Pydantic schemas
โ”‚   โ”œโ”€โ”€ config.py               # Settings (pydantic-settings + .env)
โ”‚   โ”œโ”€โ”€ agent/
โ”‚   โ”‚   โ”œโ”€โ”€ classifier.py       # Step 1: category + confidence
โ”‚   โ”‚   โ”œโ”€โ”€ drafter.py          # Step 2: reply draft
โ”‚   โ”‚   โ”œโ”€โ”€ extractor.py        # Step 3: structured fields
โ”‚   โ”‚   โ””โ”€โ”€ pipeline.py         # Orchestrator: retry, fallback, metrics
โ”‚   โ”œโ”€โ”€ integrations/
โ”‚   โ”‚   โ”œโ”€โ”€ sheets.py           # Google Sheets write-back + fallback
โ”‚   โ”‚   โ””โ”€โ”€ slack_notifier.py   # Slack Block Kit alerts + approval flow
โ”‚   โ”œโ”€โ”€ observability/
โ”‚   โ”‚   โ”œโ”€โ”€ logger.py           # Loguru structured logging
โ”‚   โ”‚   โ””โ”€โ”€ metrics.py          # Prometheus counters/histograms
โ”‚   โ””โ”€โ”€ static/
โ”‚       โ””โ”€โ”€ index.html          # Live dashboard UI
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ fixtures/tickets.json   # 100 labeled test tickets (5 categories)
โ”‚   โ””โ”€โ”€ test_pipeline.py        # Unit tests + batch accuracy benchmark
โ”œโ”€โ”€ .github/workflows/ci.yml    # GitHub Actions: lint + test + Docker build
โ”œโ”€โ”€ Dockerfile                  # Production container
โ”œโ”€โ”€ docker-compose.yml
โ”œโ”€โ”€ .env.example                # Environment variable template
โ””โ”€โ”€ requirements.txt

๐Ÿ›  Tech Stack

Layer Technology
API FastAPI + Uvicorn
LLM OpenAI GPT-4o-mini (JSON mode)
CRM Google Sheets API v4 (gspread)
Notifications Slack SDK + Block Kit
Observability Loguru + Prometheus
Testing pytest + pytest-asyncio
Linting Ruff
Container Docker + Docker Compose
CI/CD GitHub Actions

๐Ÿ”ฎ Roadmap

  • RAG: Connect FAQ knowledge base for context-aware replies
  • Streaming: SSE push for real-time draft generation
  • Multi-language: Auto-detect language, reply in kind
  • Fine-tuning: Train classification model on historical tickets (target: 97%+)
  • Analytics: Category trend charts, team performance dashboard
  • Webhook input: Native Zendesk / Intercom / Freshdesk connectors

๐Ÿ“„ License

MIT ยฉ 2025 โ€” See LICENSE for details.

About

AI support ticket copilot with classification, reply drafting, HITL approval, and Sheets/Slack integration.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages