feat(analyst): Add sample and escalate functionality to analyst API

- Introduced new endpoints `/api/analyst/query/{trace_id}/sample` and `/api/analyst/escalate` for sampling query results and escalating issues to human analysts, respectively.
- Enhanced `AnalystAgent` to support sampling of SQL results based on trace ID and to handle escalation requests, improving user experience in error scenarios.
- Updated `analyst_schemas.py` to include `EscalateRequest` for structured escalation requests.
- Added corresponding frontend API calls and UI components to facilitate user interactions with the new features.
- Implemented unit tests to ensure the reliability of the new functionalities.

This update significantly enhances the analytical capabilities of the application, allowing users to retrieve detailed query samples and escalate issues effectively.
This commit is contained in:
2026-09-11 15:18:56 +08:00
parent 0fb7d34d7a
commit 8556da489a
27 changed files with 656 additions and 42 deletions
+8 -10
View File
@@ -11,12 +11,10 @@
- [ ] **git commit `merger`**:Wave3 + analyst D-06/模板缓存 + 风控前端/灌库/深潜课7 + 问数 UI 标签 + **客服问候快路由/闲聊降级** + 答辩清单/课程 + 文档(你确认后执行)
- [x] **风控深潜课改版(方案 1 · 7 模块 · 读者 dev)**:模块 1–7 已写(含写侧并发)· `jinrong-module-risk/index.html` 已拼接
- [ ] **数据分析 · 20 题 live battery**:`uvicorn` + DeepSeek → `python scripts/dev/run_query_battery.py` → 本地写 `scripts/dev/battery_report.json`(**已拍板:不入库** · 见 `.gitignore`)
- [ ] **客服 · 手工验收**:`docs/memory/tests/2026-09-10-customer-1b-r1/MANUAL-CHECKLIST.md`(CUST-9527 持仓/sanitize/R1 种子)
- [ ] **客服 · Redis DEL**:灌 R1 种子后 `redis-cli -p 6380 DEL profile:l1:CUST-9527`(6380 未起则先 `start-redis.ps1`)
- [ ] **测试包签核**:`TEST-LOG-2026-09-10-CS-001` → 模块负责人 zhangyong 确认
- [ ] **接口契约发群稿**:`docs/项目管理/接口契约发群-2026-09-09.md`(复制到群即完成)
- [ ] **口径字典/问数模板种子**:本机执行 `seed-analyst-metric-dict.sql` · **`seed-analyst-query-templates.sql`**(若未灌)
- [ ] **数据分析 · 20 题 live battery**:`run_query_battery.py` 已加 `interpret: false` · 本机 `uvicorn` + DeepSeek 跑完写 `battery_report.json`(**不入库**)
- [x] **口径字典/问数模板种子**:`scripts/dev/seed_analyst.ps1` → `seed-analyst-metric-dict.sql` · `seed-analyst-query-templates.sql`
- [x] **接口契约发群稿**:`docs/项目管理/接口契约发群-2026-09-09.md`(复制到群即完成 · TODO 已勾)
- [x] **TEST-AN-001 签核(开发侧)**:`TEST-LOG-2026-09-11-AN-001.md` v1.3 · A/B/D 已修 · **824 pytest**
- [ ] **前端 E2E 补齐未跑测试**(见下方「前端 E2E · 未跑测试」;2026-09-10 走查只做到「路由能渲染」,**不是逐功能详测**)
### 2026-09-10 日终 · 工作清单(给用户/答辩交接)
@@ -107,7 +105,7 @@
**P0 · 演示/稳定性**
- [ ] **启动自检页或 health 条**:Redis `6380` PING + 后端是否含 `close-all`/`status` 路由(避免「功能全在但环境像坏了」)
- [x] **启动自检页或 health 条**:`GET /api/ready` + 前端 `DevReadyBanner`(Redis + close-all/问数路由)
- [ ] **PERF-1 复测**:Redis 正常后重测带 token 接口耗时,更新交接文档数字
- [ ] **E2E 最小集进仓库**:登录/退出 · 客户 Chat 多轮+F5 · 清空会话(Playwright;可替代仓库外 `e2e-jinrong`)
- [ ] **风控演示链自检**:`prepare_all.ps1` 或 SOP §2 后台账/AML/模拟是否「有故事」(`reset.ps1` 后预警常空 — 文档化进自检提示)
@@ -201,7 +199,7 @@
- [x] **STAFF-30001/30002 追加 risk_demo**(`jwt_service.py` · 模拟交易页可造预警)
- [x] **445cfbb 功能层 cherry-pick**(2026-09-10):`guardrail.py` · `dict_service.py` · wave6 测试 · `run_query_battery.py`
- [x] **D-06 双层缓存**(2026-09-10):结果缓存+表世代写侧失效 · 模板填参 · 问数页标签 · 种子 SQL
- [ ] **D-09 多轮追问** · **N-03 溯源明细** · **N-07 转人工** — 前后端均未做
- [ ] **D-09 多轮追问** · [x] **N-03 溯源明细** · [x] **N-07 转人工** — N-03/07 最小闭环(sample + escalate + 问数页按钮)
### 数据分析 Agent · 445cfbb 合入后开放项
@@ -259,7 +257,7 @@
### 客服 Agent · Wave3 开放项(2026-09-10 后)
- [ ] **C-04 push/cron**:阈值命中仅持仓查询内联提醒;无 Redis pub / 定时扫仓(**拍板**)
- [x] **C-04 push/cron(演示最小)**:`POST .../threshold-check?push=` · `scripts/demo/push_threshold_alerts.py` · 持仓页「检查阈值提醒」
- [ ] **C-05 Phase B**:`nav-snapshot` sync · 前端行情 Phase B(见 v0.2 草案)
- [ ] **C-08 偏离检测**:仅 L1 槽位,无自动调仓建议
- [ ] **Vitest**:客户 Chat 新 intent 无前端单测(后端已覆盖)
@@ -268,7 +266,7 @@
### 画像 Redis · cache-aside(2026-09-09 · **客服域,非风控**)
- [x] **L3 热读(风控)**:`get_profile_l3` cache-aside · `customer_context` Tool 已走此路径
- [ ] **L1 热读/写(客服)**:`ProfileHotCache` 仅在 `customer_service.py` · 宿主 `POST /api/chat` 未接 — **风控不做**
- [x] **L1 懒读(客服)**:`ProfileHotCache.get_style_tags_lazy` · 写侧 `warm_l1` · `customer_service` 已切懒读
- [ ] **L2 热读/写(顾问)**:表与 JWT scope 已有 · Repository/Redis **未实现** — **风控不做**
- [x] **【前端接入·方案 B】chat 拉侧三端点**(commit `8328c24`,2026-09-08):`GET /api/chat/sessions`(本人+本 Agent 线分页列表)、`GET /api/chat/sessions/{id}/messages`(历史消息升序分页,closed 仍可读)、`POST /api/chat/sessions/{id}/close`(active→closed,重复/非 active 409);chat.py 抽 `_resolve_agent_type`/`_assert_chat_entry`/`_guard_session` 三守卫供四端点共用,POST "" 行为零回归;risk_manager 在对话线数据面保持 403(PRD 4A.1)。测试 482→**494 绿**;独立评审 P0=0,P1(close 并发 rowcount 静默 200)已修复
- [x] **【前端接入·方案 C】SSE 流式对话**(commit `01ec5fc`,2026-09-08):新增 `POST /api/chat/stream`(OpenAI 兼容 chunk:首帧 meta → delta → finish_reason=stop → `[DONE]`);`agent_service.stream_chat` 生成器 + `needs_disclaimer`;`_guard_request`/`_prepare_turn` 与同步端点共用守卫;`session_repository.insert_turn` user+assistant 同事务落库(修评审 P0/P1)。测试 494→**503 绿**。遗留:无心跳帧、断连留空会话待清理
@@ -226,9 +226,9 @@
| 角色 | 姓名 | 日期 | 意见 |
| --- | --- | --- | --- |
| 模块负责人 | zhangyong | | ☐ 通过 ☐ 待改 |
| 发现人 / 测试 | Andrew | 2026-09-11 | 沙盘 + 自动化回归 |
| 修改人 | Andrew | 2026-09-11 | §7 A/B/D 已修 · 820 pytest |
| 模块负责人 | zhangyong | | ☐ 通过 ☐ 待改(开发侧 v1.3 已闭环,待负责人签) |
| 发现人 / 测试 | Andrew | 2026-09-11 | ☑ 沙盘 + 自动化回归 |
| 修改人 | Andrew | 2026-09-11 | ☑ §7 A/B/D 已修 · **824 pytest** · N-03/N-07 接续 |
---