- Updated the `dashboard` function in `analyst.py` to include additional metrics for different user roles, improving data visibility for analysts, customers, advisors, and risk officers. - Introduced a new `prepare_customer_stream` function in `customer_service.py` to facilitate streaming responses for customer interactions, enhancing the chat experience. - Added new API endpoints in `analyst.ts` for fetching dashboard metrics and managing analyst assets, streamlining data handling and user interactions. - Updated frontend components to support new dashboard features and asset management, ensuring a cohesive user experience across the application. This update significantly improves the functionality and usability of the analyst and customer service features, providing users with enhanced tools for data analysis and interaction.
146 lines
18 KiB
Markdown
146 lines
18 KiB
Markdown
# TODO
|
||
|
||
> 大任务开始时更新;完成一步打钩并验证后再往下。
|
||
> **新 Agent:** 先看 `MEMORY.md` §0 交接清单,再从此处取下一项。
|
||
|
||
## 进行中
|
||
|
||
**2026-09-09 批次**:P1 收尾 + P2 analyst + customer SSE + risk_demo · 待复制发群稿 · 口径种子 SQL 本机执行
|
||
|
||
## 待办(统筹 · P1 推荐顺序)
|
||
|
||
- [x] **代销平台 API v0.1 实现**(2026-09-08)
|
||
- [x] **`web/` P0 脚手架 + 主链路真接**(2026-09-09)
|
||
- [x] **`web/src/api/risk.ts` 补 `X-Agent-Type: risk`**(2026-09-09)
|
||
- [x] **同步 `MEMORY/REQUIREMENTS/FRAMEWORK`**(analyst S3 · 773 基线 · D-01~D04)
|
||
- [x] **接口契约发群稿**(`docs/项目管理/接口契约发群-2026-09-09.md` — 待你复制到群)
|
||
|
||
### 前端 `web/` · P0 收尾
|
||
|
||
> 主链路已通;以下为 polish / 文档 / 已知接缝缺口。
|
||
|
||
- [x] 四角色 Dashboard · 平台只读 · ChatPanel · 游客试聊 · 行情 · 风控台账页 · 问数工作台(`AnalystQueryPage`)
|
||
- [ ] **Vitest 补测**(可选):`useChatPanel` · `api/analyst.ts` mock
|
||
- [x] **simulate 交易 UI**:风控菜单「模拟交易」+ `RiskSimulatePage` + `api/simulate.ts`(演示说明 · A-3/A-1 预设)
|
||
- [x] **接口契约发群稿**(见 `docs/项目管理/接口契约发群-2026-09-09.md` · 复制到群即完成)
|
||
|
||
## 待办(模块侧开放项)
|
||
|
||
### 客服 Agent · S2 接缝(2026-09-09 已接线 · 并行分流)
|
||
|
||
> 清单:`docs/项目框架设计/客服Agent-合并说明.md` §3–§4 · 原则只增不盖、不覆盖 `main.py`/`chat.py`/`agent_service.py` 整体。
|
||
|
||
- [x] **跑迁移 SQL**:`scripts/agent/migrate-customer-agent-cs-c11.sql`(`conversation_archive` · `customer_notes`)(2026-09-09 本机已执行)
|
||
- [x] **挂游客路由**:`POST /api/chat/visitor` → `main.py`
|
||
- [x] **编排接缝(并行)**:`X-Agent-Type: customer` → `customer_service.run_customer_chat`;其余 Agent 仍 `agent_service.chat`
|
||
- [x] **Wave 3 测试解禁**:`test_wave3_customer_service.py` 19 例绿 · 基线 **554 passed**
|
||
- [x] **Wave 1/2 解禁**:`test_wave1_*` · `test_wave2_*` 已移出 `collect_ignore` 并绿(132+ 例)
|
||
- [x] **Wave 3 profile / 4 / 5 解禁**:`test_wave3_profile_service` · `test_wave4_e2e` · `test_wave5_notes` · 基线 **730 passed**
|
||
- [x] **客服 KB 第二套(fin_*)· Ollama 灌库**(2026-09-09 本机):
|
||
1. `ollama pull bge-m3` ✓
|
||
2. Ollama 服务 `http://127.0.0.1:11434` ✓
|
||
3. **Windows**:`MILVUS_URI` 须英文绝对路径(如 `C:/Users/Windows/.jinrong/milvus/milvus.db`),中文项目路径 faiss 会炸
|
||
4. `python scripts/kb/build_collections.py --rebuild`(原料 `data/kb_collections/`)✓ 9 块
|
||
5. `python scripts/kb/test_search.py` ✓
|
||
- [x] **客服 RAG 接 fin_* 三库**:`VisitorRagService` → `search_cs_knowledge`(`fin_product` / `fin_policy` / `fin_faq`);宿主 Tool 仍走 `kb_product_rules`(T-21)
|
||
- [x] **tool 层实现 + 种子文档**:`document_parser` / `embedding_tool` / `milvus_tool` + `data/kb_collections/*`(2026-09-09)
|
||
|
||
### 数据分析 Agent · S3 接缝(2026-09-09 已接线)
|
||
|
||
> 清单:`docs/项目框架设计/数据分析Agent-合并说明.md` · **773 passed** · 冒烟 `scripts/dev/smoke_analyst.py`
|
||
|
||
- [x] merge + 接缝(`analyst_router` · `analyst_auth_adapter` · 问数走 `get_platform_auth_context`)
|
||
- [x] customer `self` 域 + 「AI 分析有风险」尾注
|
||
- [x] Wave6 测试 · 迁移 `migrate-analyst-d07-d11.sql` · 重置 `reset-analyst-d07-d11.sql`
|
||
- [x] 前端问数页 · Scope B 冒烟 19/19
|
||
- [x] **P2 · D-11 资产沉淀 UI**(`AnalystAssetsPage` · `POST /api/analyst/assets`)
|
||
- [x] **P2 · 问数页 dashboard 卡片**(`GET /api/analyst/dashboard` · `AnalystQueryPage` 顶部 metrics)
|
||
- [x] **P2 · 口径字典种子**(`scripts/agent/seed-analyst-metric-dict.sql` · 本机需手工执行)
|
||
- [x] **customer Chat SSE**(`chat.py` stream → `prepare_customer_stream` · 前端 `mode="stream"`)
|
||
- [x] **STAFF-30001/30002 追加 risk_demo**(`jwt_service.py` · 模拟交易页可造预警)
|
||
|
||
### 风控 Agent · 前端/运维(盘点 2026-09-09 · 部分已与 P0 重叠)
|
||
|
||
**HTTP · 前端**
|
||
|
||
- [x] **`RiskAlertsPage`**:列表 + 处置 UI · JWT 已带 `X-Agent-Type: risk`
|
||
- [ ] **`GET /api/risk/alerts` 筛选 UI 补全**(`alert_type` / `customer_id` / 日期窗 — 页面目前部分参数)
|
||
- [ ] **`POST /api/compliance/suitability-check`** · **`POST /api/risk/suitability/check`**:前端未接
|
||
- [ ] **`POST /api/risk/aml/scan`** · **`POST /api/simulate/trade`**:无 UI(Swagger/curl)
|
||
|
||
**对话 Tool(risk Chat SSE 触达)**
|
||
|
||
- [x] risk Chat SSE 前端已接(`ChatPanel` · `X-Agent-Type: risk`)
|
||
- [x] **`alert_query` / `customer_context` / `suitability_check` / `aml_lookup` / `query_overdue_alerts`**(后端 C1 已注册)
|
||
- [x] **`query_agent_behavior`**:已写入 `RISK_TOOL_REGISTRY`(2026-09-09)
|
||
|
||
**运维 / 动态演示(无 UI · 见 `演示SOP-风控模块.md`)**
|
||
|
||
- [ ] **`scripts/demo/subscribe_alerts.py`**:订阅 Redis `risk:pub:alert` 实时推送(Pub/Sub 无持久化,须先开订阅再发交易)
|
||
- [ ] **`scripts/cron/escalation_scan.py`**:超期未处置升级(FR-9 · 需库内已有 `pending_review` 且 `created_at` 超阈值)
|
||
- [ ] **`scripts/cron/agent_behavior_scan.py`**:代理人行为链扫描(FR-10 · 需 audit_log 先积累越权/诱导交易痕迹)
|
||
- [ ] **`scripts/demo/rebuild_alerts.py`**:按 `trade_id` 幂等重放引擎(engine_error 补偿)
|
||
|
||
**演示种子 / 测试数据补充(测未接接口 · 非 everyday `reset.ps1`)**
|
||
|
||
> Core reset 后 **`risk_alert` 为空**、AML/测评可能未就位;测预警/处置/推送/FR-9/FR-10 须先补数据。
|
||
|
||
- [ ] **`scripts/agent/seed-aml-list.sql`**:8 条 AML 名单(A-5:`CUST-1002` 展示名故意命中)
|
||
- [ ] **`scripts/demo/prepare_risk_demo.sql`**:6 客户测评刷新(可交易);`CUST-1004` 保持过期(FM-03 阻断演示)
|
||
- [ ] **风控走查重灌(SOP §2)**:双库 DROP + agent 表 + 上两项 + `sync_advisor_rel`(`reset.ps1` **只重建 core**)
|
||
- [ ] **动态造预警 · A-1~A-5**:`POST /api/simulate/trade`(Swagger/curl)— A-3 `CUST-3001`/`PROD-510300`/50 万 · A-4 `CUST-9527` 连发 4 笔 · A-5 `CUST-1002`/`PROD-005828`/100
|
||
- [ ] **Redis 实时推送演示**:终端 1 `subscribe_alerts.py` → 终端 2 发 simulate/trade(Pub/Sub 无持久化)
|
||
- [ ] **FR-9 超期升级**:库内 `pending_review` 且 `created_at` 超 `RISK_ESCALATION_L1_HOURS`(默认 4h)→ `escalation_scan.py`
|
||
- [ ] **FR-10 代理人行为链**:A-12 ① 同一 `X-Debug-Actor=STAFF-10087` 发 3 组赎回+申购 + 越权 audit → `agent_behavior_scan.py`
|
||
- [ ] **L3 监测档数据**:A-5 AML 命中后 `customer_profile_l3.monitor_tier=high`(测 `customer_context` Tool / Dashboard 高风险客户数)
|
||
- [ ] **适当性阻断样例**:A-1 `CUST-1001`/`PROD-161725`/1 万 · A-2 `CUST-4001`/2 万(测 handle/台账 suitability 单)
|
||
- [ ] **引擎补偿**:`rebuild_alerts.py <trade_id>`(engine_error 场景)
|
||
- [ ] **可选 dev 静态预警 seed**:2~3 条 `pending_review` 样例(免每次 simulate;与集成测试当日窗冲突须文档说明)
|
||
- [ ] **链式 reset 脚本**:AML + prepare 并入 `reset.ps1` 或新增 `scripts/demo/prepare_all.ps1`
|
||
|
||
### 画像 Redis · cache-aside(2026-09-09)
|
||
|
||
- [x] **L3 热读**:`get_profile_l3` cache-aside(读 Redis miss → MySQL → SET EX 5m;写 upsert DEL)· `customer_context` Tool 已走此路径
|
||
- [ ] **L1 热读/写**:`ProfileHotCache` 仅在客服线 `customer_service.py` · 宿主 `POST /api/chat` 未接
|
||
- [ ] **L2 热读/写**:表与 JWT scope 已有 · Repository/Redis **未实现**
|
||
|
||
|
||
- [ ] chat 链路 `risk_suitability_log.actor_id` 暂落 SYSTEM(run_tool 统一透传需动 core_tools/kb_tools 冻结 func 契约,发起者留痕已由 agent_tool_call 覆盖)——AL-06 遗留,动 Tool 契约前先出方案
|
||
- [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 绿**。遗留:无心跳帧、断连留空会话待清理
|
||
- [x] chat 同步/流式落库免责声明口径统一(2026-09-09):`chat.py` `_assistant_content_for_persist` · sync/stream 共用 · `test_chat` 回归
|
||
- [x] 2026-09-05 memory 文件夹更新(新 Agent 交接清单)
|
||
|
||
> **AL-09 已完成(2026-09-08)**——见 `docs/项目框架设计/合并注意事项-风控模块并入main.md` 执行记录。
|
||
|
||
- [x] **【AL-09】合并接线**(2026-09-08):JWT 统一 · 模块 chat 恢复 · auth_adapter · test_module_boundary 绿 · **502 pytest 绿**
|
||
|
||
- [x] T-04 Core RO 封装为 Tool 节点;A-01 归属校验(chat Tool 接入 + agent_tool_call 落库)—— **完成(2026-09-07)**:`app/tool/core_tools.py`(L0/持仓/流水三只读 Tool + TOOL_REGISTRY 白名单)+ `app/service/tool_service.py`(关键词意图仅 customer/advisor;归属校验对齐 deps.assert_customer_access 口径——Tool 层拒绝不抛 403 而 blocked 留痕,纵深防御;run_tool 执行+落库,落库失败降级)+ agent_service 图 tool 节点(START→tool→llm→guard;结果注入 LLM 上下文,降级回复带摘要)+ session_repository.insert_tool_call(message_id 一期 NULL)。**A-01 口径:本任务只做 Tool 层归属校验语义(customer 本人/advisor assigned/risk_officer 全量/其余拒),A-01 完整场景(代理人画像)仍归 T-20**;risk 分支四 Tool 归 C1 复用 run_tool。**评审闭环(2026-09-07):首评 P1×2+P2×3+P3×2 → 修复 `40a9ee2` → 复审 P2×1+P3×4 → 修复 `1216d26`,pytest 321 绿;入参白名单+days 钳制、公共鉴权双写 `utils/authz.py`、list_holdings LIMIT 均落地**
|
||
- [x] T-21 Milvus Lite + kb_product_rules 首批入库 —— **完成(2026-09-07,commits e34973f~535c8a0 共 6 个 + 评审闭环 9cc2e59)**:`app/service/embedding.py`(Ollama bge-m3 批量 /api/embed 1024 维,四类失败一律 EmbeddingError 不静默降级)+ `app/service/milvus_service.py`(kb_product_rules 幂等建集合+upsert+search_kb 溯源/effective_date 合规过滤)+ `data/kb/` 6 只种子产品手册(prospectus/fee/rule/risk 四节 24 块)+ `scripts/kb/build_kb.py`(--dry-run/--kb-dir)+ `app/service/rag_service.py` 落地(search_knowledge→chunks+source_refs,异常上抛防 LLM 编造)+ `app/tool/kb_tools.py` 挂注册表第三层(**ToolSpec 新增 skip_access_check**:公开知识无归属语义,advisor 无绑定客户可查;意图层限定 customer/advisor,risk 不开放——用户拍板)+ tool_node 按 spec 白名单注入 query + summarize 溯源口径。**真库验收:24 块入库,search_knowledge("基金申购") Top3 命中申赎规则(score 0.73+),溯源完整**。三坑收口:Milvus Lite 跨进程重开须显式 load / faiss 不支持中文路径(本机 .env 改 C:/Users/YUAN/.jinrong/milvus/)/ build_kb sys.path 引导。知识库 API(上传/重建端点)一期不做(knowledge.py 仍空壳,用户拍板),425 绿
|
||
- [x] T-03 输入防护规则(F-03:prompt_injection/oversize/限流)—— **完成(2026-09-07,commits 497554d/65b45aa/cc6f34f/207fc79)**:`app/service/input_guard.py`(注入短语词表 42 条四类纯函数检测 + `inspect_message` oversize 4000 先于 injection + `check_rate_limit` Redis INCR 固定窗口 actor 级 30 次/分 fail-open)+ chat 路由接入(顺序:鉴权→准入→空白→限流 429→注入/超长 400→归属→会话;被拒 fail-fast 不建会话不落消息,blocked 落 input_guard_log,留痕降级不改拒绝语义;Pydantic 硬顶 20000,业务限 4000 移 guard 层换留痕)+ redis_gateway.incr + settings.guard_rate_limit_*;拍板:命中即拒不清洗、仅 blocked 留痕、词表代码常量可审计。**独立 AI 评审 PASS with findings(P0=0;P2×3 已收口:词表断言修正/补 7 条同构变体/窗口 TTL 断言+EXPIRE 失败取舍锁定;P3 已收 session_id 截断,挂账对抗变体扩表)**,378 绿
|
||
- [x] 风控阶段 C(C0 pytest-asyncio / C1 chat_tools / C2 risk 分支 StateGraph / C3 A-6 验收)—— **完成(2026-09-07)**:`app/service/risk/chat_tools.py` 四只读 Tool(alert_query/customer_context/suitability_check/aml_lookup)挂 `RISK_TOOL_REGISTRY`;`tool_service.run_tool` 改查 core+risk 统一注册表 `get_registered_tool` 且恒传 `risk_repo`;`_normalize_params` 读 spec 白名单;`match_intent` 按 agent 分组扩 risk 关键词;`agent_service.tool_node` 守卫放宽(`requires_customer=False` 允许无绑定客户,支撑 A-6 全量待审);A-6 验收+诱导处置边界(无处置 Tool、系统提示禁自动处置、诱导只触发只读且预警状态不变);**独立 AI 评审 PASS(P0=0,P2 补 advisor 归属/空 product_id 单测已收口),345 绿,tag `risk-m3`**
|
||
|
||
### 风控模块(PRD v1.0 已冻结 · `docs/PRD/PRD-风控监测Agent.md`,事件驱动线不依赖 T-07 可先行)
|
||
|
||
- [x] T-30 风控事件线 —— **全部完成(B1~B9b,M2 tag risk-m2)**:规则引擎/预警聚合/L3/AML/交易网关/4 API/演示走查 11/11 PASS + 核查单①~⑥收口,均经独立 AI 评审闭环;scan_all 幂等读后写无锁留痕(接批量时 run_locked)
|
||
- [x] T-31 `service/suitability.py` 公共校验(SUIT-001~008)+ `POST /api/risk/suitability/check` —— **交付=suitability 服务函数+单测(77 例;check API 随 B6 带鉴权+直调审计);MySQL 手工 SQL 对照(阶段 A 评审 P2-8)2026-09-07 收口:4 组演示组合真库 SQL 推导与函数判定逐项一致(演示 SOP 核查单附行)。【2026-09-07 阶段一退役】SUIT-001~008 编号体系已随 AL-05 换核退役,判定内核改为 main 的 core_ro.check_suitability(C×R 矩阵 + JR-AST/FM 契约),测试按 main 契约重写(原 77 例作废,全量基线 425→406)**
|
||
- [x] T-32 预警台账与人工处置 API + 对话线 —— **台账/处置 API 已由 B6 覆盖并复审通过(A-7/A-9 用例绿);交付=对话线,归阶段 C(C1~C3,T-07 已就绪)**
|
||
|
||
## 已完成
|
||
|
||
- [x] 2026-09-07 风控 M2 收尾(M4 复核):MEMORY/TODO 状态与边界文字对齐(任务映射 T-30/T-31/T-32 口径确认;B7 复审留痕「成功响应不包裹外壳」演进口径维持并登记开发计划 M4 节)——风控阶段 B 正式完结
|
||
- [x] 2026-09-07 T-01 JWT 鉴权(commit 36f476f + 评审闭环 61711cb):`app/service/auth_service.py` Auth SDK(HS256 dev/RS256 生产、必填 claims 显式校验、jti 吊销 fail-open、RS256/HS256 算法白名单互斥)+ `deps.get_auth_context` 工厂替换(Bearer 全环境优先;debug 头降级 dev 兜底,双闸门=APP_ENV+无 RS256 公钥)+ X-Agent-Type 交叉校验(手册 §4.6/§5.4 AGENT_ACCESS_MATRIX)+ `scripts/dev/issue_dev_token.py` 签发 CLI + lifespan 改验 jwt_ready
|
||
- [x] 2026-09-07 T-02 审计中间件(commit 3cec034):`app/api/audit_middleware.py` http_access 全量访问审计(actor 经 request.state.auth,排障路径/OPTIONS 跳过,写库失败降级)+ 独立 request_id(X-Request-Id 贯通,B7 复审 P3-4)+ 422/404/405/500 统一错误体(500 由 trace 中间件兜底回写 trace 头,B7 复审 P2-2)+ input_guard_log 双写(挂账⑧收口;401 归 platform、四 Agent 入口写 guard)
|
||
- [x] 2026-09-07 T-07 LangGraph 骨架(commit fb18c04):`agent_service` StateGraph(llm→guard)+ DeepSeek/langchain-openai(无 key 降级明确标注)+ 四 Agent 边界 system prompt + customer/risk 免责声明(has_disclaimer)+ 单测 mock LLM 不依赖外网
|
||
- [x] 2026-09-07 T-06 chat 最小闭环(commit ee5c78a):`api/chat.py` POST /api/chat(X-Agent-Type 分流+准入+归属校验+SessionGuard AUTH_403_SESSION_AGENT+closed 409)+ `session_repository`(agent_session/agent_message)+ `memory_service`(Redis 窗口 sess:{agent}:{id}:msgs TTL2h N≤20,miss/异常回源 MySQL)+ main 挂载
|
||
- [x] 2026-09-07 Wave 0 独立 AI 评审有条件通过→闭环(commit 61711cb):P2×5(python-jose>=3.5.0 防 CVE / audit 降级测试 / JWT 通道 chat 用例 / debug 兜底纵深防御 / 留痕失败降级显式化)+ P3×11 顺手,273 测试绿
|
||
- [x] 2026-09-05 init 项目记忆目录 + `app/` 脚手架(api/service/tool/model/config/utils)
|
||
- [x] 2026-09-05 需求拆解文档(业务场景/矩阵/合规)
|
||
- [x] 2026-09-05 表设计 + 技术选型 + JWT 手册
|
||
- [x] 2026-09-05 Core 模拟库 `scripts/core/*` + `reset.ps1` + 文档
|
||
- [x] 2026-09-05 `core_ro.py` + `settings.mysql_core_database` + sync 脚本
|
||
- [x] 2026-09-05 Agent 编排依赖改为 LangGraph(requirements.txt)
|
||
- [x] 2026-09-05 memory 文件夹更新(新 Agent 交接清单)
|
||
- [x] 2026-09-09 数据分析 Agent S3 合并接线 + 问数页 + 迁移/冒烟(`773 passed` · commit `af9fb71`)
|
||
- [x] 2026-09-09 数据分析 Agent 需求规格定稿 v1.1(`docs/需求拆解/01-数据分析Agent需求规格.md`)
|