feat(report): Add battery report generation and update course documentation

- Introduced `battery_report.json` for local data analysis, excluding it from the database.
- Enhanced `AGENTS.md` to reflect updated test baseline with 795 passed tests.
- Added new metrics for trade flow in `dict_service.py`, improving transaction data analysis.
- Updated regex patterns in `guardrail.py` to better handle numeric extraction and prevent misinterpretation of tokens.
- Expanded course modules with new content on FR-8/9/10 capabilities and L3 role management.
- Improved concurrency handling in transaction processing to ensure accurate alert generation.

This update enhances data analysis capabilities and improves the overall structure and clarity of course materials.
This commit is contained in:
2026-09-10 14:32:25 +08:00
parent 4b8e11c9bd
commit 21ced4d38f
30 changed files with 1768 additions and 85 deletions
@@ -0,0 +1,93 @@
# 风控监测 Agent 深潜课 · 改版设计(2026-09-10)
> **读者:** A · 内部 dev(指挥 AI 改 `app/service/risk/*`、接前端、跑演示)
> **结构:** 方案 1 · **7 模块**(保留并刷新 1–4,新增 5–7)
> **基线:** `merger` · **795 pytest** · AL-09 双栈 · FR-1~10 已实现
---
## 模块地图
| # | 标题 | 指挥 AI 时解决什么 | 主要代码入口 |
| --- | --- | --- | --- |
| **1** | 四条能力线与鉴权 | 风控 REST 为什么要 `X-Agent-Type: risk`;Demo 账号与角色 | `risk.ts` · `deps.get_auth_context` · `risk.py` |
| **2** | 模拟交易 → 预警出单 | 事件线四段;R-02 网关阻断 vs 大额待审 | `simulate.py` · `trade_gateway.py` · `risk_engine.py` |
| **3** | REST 台账与对话 Tool | 台账 handle 状态机;6 只 Tool 只读红线 | `chat_tools.py` · `tool_service` · `agent_service` risk 分支 |
| **4** | 演示数据、缺口与硬边界 | reset 后台账空;cron 无 UI;不冻户不改 C 等级 | `prepare_risk_demo.sql` · `演示SOP` · 模块 4 缺口表 |
| **5** | FR-8/9/10 规则扩展 | 集中度/超期升级/行为链:引擎 vs Chat 查询 | `concentration` · `escalation_service` · `agent_behavior_service` · Tool |
| **6** | L3 监测档与角色矩阵 | AML→L3;officer/manager/compliance 数据面差异 | `profile_l3.py` · `aml_service` · RBAC 矩阵 |
| **7** | 写侧并发 | 同日聚合锁 · L3 乐观锁 · 处置+审计同事务;**不做 L1/L2 Redis** | `locks.py` · `alert_service.py` · `profile_l3.py` · `handle_alert` |
---
## 模块 1–4 · 刷新要点(不重写骨架)
- 基线数字 → 795 pytest;STAFF-30001 + risk_demo 保留
- 适当性:强调 **core_ro.check_suitability**(SUIT-001~008 已退役一句带过)
- 模块 2:补 **R-02 阻断** 与 **R-01 大额待审** 分叉(同网关、不同结果)
- 模块 3:确认 6 Tool 列表与 `query_agent_behavior`;Chat 走 SSE + risk 头
- 模块 4:与 `TODO.md` 风控开放项对齐;链接 `演示SOP-风控模块.md`
---
## 模块 5 · FR-8/9/10(新建)
**教学目标:** dev 改规则/演示时知道「引擎出单」和「对话只读查」的边界。
| FR | 讲什么 | 演示锚点 |
| --- | --- | --- |
| FR-8 / RISK-006 | 持仓 R4+R5 集中度 · 并入事件类聚合 | A-10 · `customer_context` 集中度字段 |
| FR-9 / RISK-007 | 超期 pending · payload 升级 · status 不变 | `query_overdue_alerts` · `escalation_scan.py` |
| FR-10 / RISK-008 | 代理人 A/B/C 条件 · actor_id 维度出单 | `query_agent_behavior` · `agent_behavior_scan.py` |
**Quiz 示例:** 「对话里能让 Agent 跑 escalation_scan 吗?」→ 否,只能查库 / 运维跑脚本。
---
## 模块 6 · L3 与角色矩阵(新建)
**教学目标:** dev 接 Tool / API 时不越权、不写降级 L3。
- L3 `monitor_tier` 合并防降级 · AML 命中写 high
- `customer_context` Tool:L0 + L3 + 待审预警(只读)
- 角色:risk_officer(handle/dispose)· risk_manager · compliance(aml 域)
- 铁律复述:审计只 INSERT · 预警默认 pending_review
---
## 模块 7 · 写侧并发(新建 · 2026-09-10 拍板)
**教学目标:** dev 指挥 AI 改写路径时,分清悲观锁(聚合串行)与乐观锁(L3 `computed_at`),不误接 L1/L2 Redis。
| 主题 | 讲什么 | 代码锚点 |
| --- | --- | --- |
| 预警聚合 | 同日同客户事件类 → `run_locked(agg:event:…)` | `alert_service.py` · `locks.py` |
| L3 upsert | `WHERE computed_at = :expected` · 失败重试 | `profile_l3.py` · `risk_repository.update_l3` |
| 处置审计 | status 变更 + audit_log **同事务** | `handle_alert` · B7 挂账⑦ 已收口 |
| 边界 | L1/L2 Redis 归客服/顾问;风控仅 L3 cache-aside | MEMORY § 已拍板 |
**Quiz 示例:** 「给风控加 L1 Redis 热读合理吗?」→ 否,L3 cache-aside 足够。
---
## 明确不讲(模块 4 一句)
- SUIT 旧编号体系细节 · 自动冻户 · cron 前端化 · SOP 11 步全文
---
## 验收
- [x] `_base.html` 7 nav dots · `build.sh` / python 拼接 `index.html`
- [x] 每模块 ≥1 quiz · translation-block 白话+代码
- [x] entity 先概览(文件/服务名第一次出现带一句职责)
- [x] 与 `docs/memory/REQUIREMENTS.md` Wave2 状态一致
---
## 待用户确认后执行
1. ~~新建 `modules/05-fr-extensions.html` · `06-l3-rbac.html`~~ ✅
2. ~~刷新 `01–04` 上述要点~~ ✅
3. ~~`python docs/course/build_all.py`~~ → `bash docs/course/jinrong-module-risk/build.sh`
4. ~~新建 `modules/07-concurrency.html` · 更新 `_base.html` nav~~ ✅(2026-09-10)