# PRESENTATION: AI AGENT PHÂN TÍCH DOANH THU - BIZFLY CLOUD
---
## SLIDE 1: TỔNG QUAN DỰ ÁN
```mermaid
mindmap
root((AI Agent<br/>Analytics))
[Mục tiêu]
Truy vấn linh hoạt bằng ngôn ngữ tự nhiên
Phân tích xu hướng tự động
Cảnh báo thông minh
[Timeline]
9 ngày làm việc
T2 20/01 → T4 29/01
[Công nghệ]
MCP Server
Telegram Bot
Airflow
[Deliverables]
Dimension Table mới
MCP API với 2 tools
Telegram Bot với Alert
Scheduled Analysis
```
**Key Points:**
- **Vấn đề:** Dashboard cố định không đáp ứng câu hỏi tức thời
- **Giải pháp:** AI Agent trả lời bằng ngôn ngữ tự nhiên qua Telegram
- **Thời gian:** 9 ngày (20-29/01)
- **Team size:** 1 developer full-time
---
## SLIDE 2: TIMELINE TỔNG QUAN
```mermaid
gantt
title Timeline Dự Án AI Agent Analytics
dateFormat YYYY-MM-DD
section Phase 1
Transform Data :p1, 2026-01-20, 1d
Tạo dim_billing_plan :2026-01-20, 3h
Refactor reports :2026-01-20, 4h
Testing :2026-01-20, 2h
section Phase 2
MCP Server :p2, 2026-01-21, 3d
Setup project :2026-01-21, 4h
DB Client :2026-01-21, 2h
MCP Resources :2026-01-21, 3h
Tool: query_revenue :2026-01-22, 5h
Tool: analyze_trend :2026-01-22, 5h
Testing :2026-01-23, 4h
section Phase 3
Telegram Bot :p3, 2026-01-24, 3d
Setup bot :2026-01-24, 2h
MCP Client :2026-01-24, 4h
Revenue handler :2026-01-25, 4h
Trend handler :2026-01-25, 4h
Alert approval :2026-01-26, 3h
Deploy :2026-01-27, 4h
section Phase 4
Orchestration :p4, 2026-01-28, 2d
Airflow DAG :2026-01-28, 4h
MCP Client Script :2026-01-28, 2h
Testing :2026-01-29, 4h
```
---
## SLIDE 3: PHASE 1 - TRANSFORM DATA (1 NGÀY)
```mermaid
flowchart LR
A[Hiện tại:<br/>Logic DUPLICATE<br/>trong 2 files] --> B[Tạo Dimension<br/>Centralized]
B --> C[dim_billing_plan_mapping]
C --> D[Refactor<br/>report_cloud_server]
C --> E[Refactor<br/>report_non_cloud_server]
C --> F[Update<br/>report_new_revenue]
D --> G[Testing &<br/>Validation]
E --> G
F --> G
G --> H[✓ Deploy T2 20/01]
style C fill:#4A90E2,color:#fff
style H fill:#50C878,color:#fff
```
**Deliverables:**
- ✅ Bảng mới: `dim_billing_plan_mapping` (plan_id → on_demand/subscription)
- ✅ 3 reports refactored (loại bỏ duplicate logic)
- ✅ Data quality validated
**Impact:** Centralized mapping, dễ maintain, scale cho các services khác
---
## SLIDE 4: PHASE 2 - MCP SERVER (3 NGÀY)
```mermaid
graph TB
subgraph MCP["🧠 MCP Server - Core Engine"]
direction TB
T1[Tool 1:<br/>query_revenue]
T2[Tool 2:<br/>analyze_trend]
R1[Resource 1:<br/>Revenue Schema]
R2[Resource 2:<br/>Service Mapping]
C1[SQL Query Builder]
C2[Trend Analyzer]
C3[DB Client]
end
subgraph Input["Input Filters"]
F1[billing_cycle]
F2[service_type]
F3[billing_plan]
F4[email/sale]
end
subgraph Output["Output"]
O1[Revenue Data]
O2[Trend Analysis]
O3[Anomaly Alerts]
end
Input --> T1
Input --> T2
T1 --> C1 --> C3
T2 --> C2 --> C3
R1 -.Context.-> C1
R2 -.Context.-> C2
C3 --> Output
style MCP fill:#E8F4F8
style T1 fill:#FFE5B4
style T2 fill:#FFE5B4
```
**Deliverables:**
- ✅ MCP Server (TypeScript/Node.js)
- ✅ 2 Tools: `query_revenue` + `analyze_trend`
- ✅ 2 Resources: Schema + Service Mapping
- ✅ Tested với Claude Desktop
**Công nghệ:** MCP Protocol, PostgreSQL, Connection Pooling
---
## SLIDE 5: PHASE 3 - TELEGRAM BOT (3 NGÀY)
```mermaid
sequenceDiagram
actor Manager as 👤 Manager
participant Bot as 🤖 Telegram Bot
participant MCP as 🧠 MCP Server
participant DB as 🗄️ postgres-ana
Manager->>Bot: "Có bao nhiêu KH<br/>active tháng 12?"
Bot->>Bot: Parse query<br/>(NLP)
Bot->>MCP: call_tool("query_revenue",<br/>{cycle: "01-12-2025"})
MCP->>DB: SELECT ... WHERE<br/>billing_cycle = '01-12-2025'
DB-->>MCP: Results
MCP-->>Bot: {total: 1303,<br/>revenue: 5.2B}
Bot->>Bot: Format response
Bot-->>Manager: 📊 Kết quả:<br/>- 1,303 KH active<br/>- Revenue: 5.2B VND
Note over Manager,DB: Human-in-the-loop Alert Flow
MCP->>Bot: Detect churn risk<br/>(5 customers)
Bot->>Manager: 🔔 Gửi alert<br/>đến Sales?<br/>[Yes] [No]
Manager->>Bot: [Yes]
Bot->>Bot: Send to<br/>Sales group
```
**Deliverables:**
- ✅ Telegram Bot với natural language parsing
- ✅ Integration với MCP Server
- ✅ Alert approval system (human-in-the-loop)
- ✅ Deploy với PM2
**User Experience:** Hỏi bằng tiếng Việt → Nhận kết quả ngay lập tức
---
## SLIDE 6: PHASE 4 - ORCHESTRATION (2 NGÀY)
```mermaid
flowchart TB
subgraph Scheduler["⏰ Airflow Scheduler"]
DAG[revenue_trend_analysis_daily<br/>Schedule: 9 AM]
end
subgraph Tasks["Tasks"]
T1[1. Analyze Trend<br/>Call MCP Server]
T2{2. Check Alert<br/>Required?}
T3[3. Send to Manager<br/>for Approval]
T4[4. Log No Alert]
end
subgraph Approval["👤 Human Approval"]
M1[Manager<br/>Telegram]
M2{Approve?}
end
subgraph Action["Action"]
A1[Send Alert to<br/>Sales Group]
A2[Log Rejection]
end
DAG --> T1
T1 --> T2
T2 -->|Yes| T3
T2 -->|No| T4
T3 --> M1
M1 --> M2
M2 -->|Yes| A1
M2 -->|No| A2
style DAG fill:#17BECF,color:#fff
style T2 fill:#FFD700
style M2 fill:#FFD700
style A1 fill:#FF6B6B,color:#fff
```
**Deliverables:**
- ✅ Airflow DAG chạy daily 9 AM
- ✅ Tự động phân tích xu hướng
- ✅ Alert workflow với human approval
**Automation:** Không cần manual check, AI tự phát hiện bất thường
---
## SLIDE 7: KIẾN TRÚC HỆ THỐNG
```mermaid
graph TB
subgraph Users["👥 Users"]
U1[Manager]
U2[Sales]
U3[Analyst]
end
subgraph Interface["🎨 Interface Layer"]
I1[Telegram Bot]
I2[Claude Desktop]
I3[Cursor IDE]
end
subgraph Agent["🤖 AI Agent Layer"]
MCP[MCP Server<br/>TypeScript]
subgraph Tools
T1[query_revenue]
T2[analyze_trend]
end
subgraph Resources
R1[Schema]
R2[Mapping]
end
end
subgraph Orchestration["⚙️ Orchestration"]
AIR[Airflow DAG]
end
subgraph Data["💾 Data Layer"]
DB[(postgres-ana)]
subgraph Tables
TB1[report_new_revenue]
TB2[dim_billing_plan_mapping]
TB3[report_ibs_sales_revenue]
end
end
Users --> Interface
Interface -->|MCP Protocol| MCP
AIR -.Scheduled.-> MCP
MCP --> Tools
MCP --> Resources
Tools --> DB
DB --> Tables
style MCP fill:#4A90E2,color:#fff
style DB fill:#50C878,color:#fff
style AIR fill:#17BECF,color:#fff
```
**3 Layers:**
1. **Interface:** Telegram (primary), Claude Desktop, Cursor
2. **AI Agent:** MCP Server với tools/resources
3. **Data:** PostgreSQL với reports optimized
---
## SLIDE 8: DATA FLOW
```mermaid
flowchart LR
subgraph Raw["Raw Data (Billing DB)"]
direction TB
R1[bills]
R2[bill_lines]
R3[v4_subscriptions]
R4[plans]
end
subgraph Transform["Transform (dbt)"]
direction TB
D1[dim_billing_plan_mapping<br/>NEW]
D2[dim_accounts]
D3[dim_first_cycle]
end
subgraph Reports["Reports"]
direction TB
REP1[report_new_revenue<br/>UPDATED]
REP2[report_cloud_server<br/>REFACTORED]
REP3[report_ibs_sales_revenue]
end
subgraph MCP["MCP Tools"]
direction TB
M1[query_revenue]
M2[analyze_trend]
end
subgraph Output["Output"]
O1[Telegram Response]
O2[Alert to Sales]
end
Raw -->|dbt run| Transform
Transform -->|JOIN| Reports
Reports -->|SQL Query| MCP
MCP --> Output
style D1 fill:#FFD700
style REP1 fill:#FFE5B4
style REP2 fill:#FFE5B4
style MCP fill:#4A90E2,color:#fff
```
**Key Changes:**
- **NEW:** `dim_billing_plan_mapping` (centralized)
- **UPDATED:** `report_new_revenue` (add billing_plan)
- **REFACTORED:** 2 reports (remove duplicate logic)
---
## SLIDE 9: USER INTERACTION EXAMPLES
```mermaid
graph TB
subgraph Q1["Câu hỏi 1: Query Revenue"]
Q1A["Manager: 'Có bao nhiêu KH<br/>active tháng 12?'"]
Q1B[Bot parse:<br/>billing_cycle = '01-12-2025']
Q1C[MCP: query_revenue]
Q1D["Response:<br/>1,303 KH<br/>Revenue: 5.2B VND"]
end
subgraph Q2["Câu hỏi 2: Filter by Service"]
Q2A["Manager: 'Doanh thu cloud server<br/>on-demand tháng 12'"]
Q2B[Bot parse:<br/>service = 'cloud_server'<br/>billing_plan = 'on_demand']
Q2C[MCP: query_revenue]
Q2D["Response:<br/>523 KH<br/>Revenue: 2.1B VND"]
end
subgraph Q3["Câu hỏi 3: Trend Analysis"]
Q3A["Manager: 'Phân tích<br/>xu hướng tháng 1'"]
Q3B[Bot parse:<br/>current_cycle = '01-01-2026']
Q3C[MCP: analyze_trend]
Q3D["Response:<br/>⚠️ 5 KH nguy cơ churn<br/>📈 8 KH tăng trưởng cao"]
end
Q1A --> Q1B --> Q1C --> Q1D
Q2A --> Q2B --> Q2C --> Q2D
Q3A --> Q3B --> Q3C --> Q3D
style Q1D fill:#50C878,color:#fff
style Q2D fill:#50C878,color:#fff
style Q3D fill:#FF6B6B,color:#fff
```
**Natural Language → Structured Query → AI Response**
---
## SLIDE 10: ALERT WORKFLOW
```mermaid
stateDiagram-v2
[*] --> Monitoring: Daily 9 AM<br/>(Airflow)
Monitoring --> Analyzing: Query data
Analyzing --> NoAnomaly: Change < 20%
Analyzing --> AnomalyDetected: Change ≥ 20%
NoAnomaly --> [*]: Log only
AnomalyDetected --> PendingApproval: Generate alert<br/>Send to Manager
PendingApproval --> Approved: Manager clicks<br/>[Yes]
PendingApproval --> Rejected: Manager clicks<br/>[No]
Approved --> SendToSales: Send Telegram<br/>to Sales group
SendToSales --> Logged: Log alert sent
Rejected --> Logged: Log rejection
Logged --> [*]
note right of PendingApproval
Human-in-the-loop
Prevent false alerts
end note
note right of SendToSales
🚨 ALERT: Churn Risk
- customer1@: -35%
- customer2@: -28%
Action: Contact ASAP
end note
```
**Smart Alerting:**
- ✅ Tự động phát hiện bất thường (>20% thay đổi)
- ✅ Human approval required (không spam Sales)
- ✅ Actionable alerts với customer details
---
## SLIDE 11: RISKS & MITIGATION
```mermaid
mindmap
root((Risks))
[HIGH: Breaking Changes]
Mitigation: Tạo report_revenue_v2 riêng
Mitigation: Backward compatible view
Mitigation: Inform stakeholders trước
[MEDIUM: Performance]
Mitigation: Add indexes
Mitigation: Query result caching
Mitigation: Pagination
[MEDIUM: NLP Accuracy]
Mitigation: Phase 1 Regex-based
Mitigation: Phase 2 Integrate LLM
Mitigation: Provide example queries
[LOW: Bot Downtime]
Mitigation: PM2 auto-restart
Mitigation: Uptime monitoring
Mitigation: Health check endpoint
```
**Risk Management:**
- **Ưu tiên:** Backward compatibility (không ảnh hưởng hệ thống hiện tại)
- **Performance:** Indexes + caching ready từ đầu
- **Accuracy:** Iterative improvement (regex → LLM)
---
## SLIDE 12: DELIVERABLES & SUCCESS METRICS
```mermaid
graph LR
subgraph D["📦 Deliverables"]
D1[1. dim_billing_plan_mapping<br/>Dimension table]
D2[2. MCP Server<br/>2 tools + 2 resources]
D3[3. Telegram Bot<br/>với Alert system]
D4[4. Airflow DAG<br/>Daily automation]
end
subgraph M["📊 Success Metrics"]
M1[Response Time<br/>< 3 seconds]
M2[Query Accuracy<br/>> 95%]
M3[Alert Precision<br/>> 90%]
M4[Uptime<br/>> 99%]
end
subgraph V["✅ Value"]
V1[Giảm 80% thời gian<br/>manual analysis]
V2[Phát hiện churn risk<br/>sớm 1 tuần]
V3[Tăng flexibility<br/>trả lời mọi câu hỏi]
end
D --> M
M --> V
style D fill:#E8F4F8
style M fill:#FFE5B4
style V fill:#50C878,color:#fff
```
**KPIs:**
- **Technical:** Response < 3s, Accuracy > 95%, Uptime > 99%
- **Business:** Save 80% analysis time, Early churn detection (+1 week)
---
## SUMMARY: TIMELINE & OWNERSHIP
| Phase | Duration | Deadline | Owner | Output |
|-------|----------|----------|-------|--------|
| **Phase 1: Transform** | 1 ngày | T2 20/01 | Data Engineer | dim_billing_plan_mapping + 3 reports refactored |
| **Phase 2: MCP Server** | 3 ngày | T5 23/01 | Backend Dev | MCP Server với 2 tools |
| **Phase 3: Telegram Bot** | 3 ngày | T2 28/01 | Backend Dev | Bot + Alert system deployed |
| **Phase 4: Orchestration** | 2 ngày | T4 29/01 | Data Engineer | Airflow DAG scheduled |
**Total:** 9 ngày làm việc | **Team:** 1 developer full-time
**Go-live:** T5 30/01/2026
---
## NEXT STEPS
```mermaid
gantt
title Action Plan - Week 1
dateFormat YYYY-MM-DD
section Approval
Lãnh đạo review :milestone, m1, 2026-01-17, 0d
Sign-off :milestone, m2, 2026-01-19, 0d
section Execution
Kickoff meeting :2026-01-20, 1d
Phase 1 Development :2026-01-20, 1d
Phase 2 Development :2026-01-21, 3d
Weekly review :milestone, m3, 2026-01-24, 0d
```