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
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.
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.
(Input: typical support ticket โ Output: classification + priority + drafted reply)
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) |
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
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ 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
git clone https://github.com/chenweilie/ai-support-copilot.git
cd ai-support-copilot
cp .env.example .env
# Edit .env with your API keysdocker-compose up -dThe dashboard will be live at http://localhost:8000
API docs at http://localhost:8000/docs
# 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 8000Copy .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_KEYis required. Sheets and Slack are optional integrations.
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
}Process up to 20 tickets concurrently.
curl -X POST http://localhost:8000/tickets/batch \
-H "Content-Type: application/json" \
-d '{"tickets": [...]}'Current processing statistics and recent ticket history.
Prometheus metrics endpoint.
# 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 -sai-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
| 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 |
- 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
MIT ยฉ 2025 โ See LICENSE for details.
