feat(advisor-agent): Integrate advisor agent functionalities and migration scripts

- Merged the `integrate/advisor-agent` branch into the `merger`, enhancing the advisor agent's capabilities with compliance, KYC, and script templates.
- Updated the testing baseline to reflect 926 passed tests, with 65 failures concentrated in the advisor agent's `test_sprint*` cases.
- Introduced new migration scripts for advisor-related database structures, ensuring smooth integration and data management.
- Enhanced documentation to include the new API structure and integration details, providing clarity for future development.

This update significantly advances the advisor agent's functionality while maintaining a structured approach to integration and testing.
This commit is contained in:
2026-09-12 16:37:29 +08:00
parent 70aa861983
commit d394686a3b
8 changed files with 40 additions and 21 deletions
+15 -9
View File
@@ -9,9 +9,9 @@
**项目是什么:** 金融四 Agent(客户财富 / 代理人 / 数据分析 / 风控)共用数据层与合规底座;**不**互调 LLM,跨 Agent 走 L1/L2/L3 画像与预警表。
**当前进度:** 需求与表设计已定 · **861 pytest** · **27 Vitest** · **Redis @ 6380** · **`merger` 未 commit** · **⚠️ 代理人 Agent 未完整接入**
**当前进度:** 需求与表设计已定 · **926 pytest passed**(全量 · **65 failed** 均为顾问 `test_sprint*` 集成)· **896 passed**(排除 `test_sprint*` · 仅 **`test_agent_kb_eval`** 红)· **27 Vitest** · **Redis @ 6380** · **`merger` 未 commit** · **投资顾问 Agent:接缝已挂(`integrate/advisor-agent` · OpenAPI **62** 路径 · 待合入 `merger`)**
**工作分支:** 团队开发在 **`merger`**;历史 `risk-control-agent` 交付冻结。
**工作分支:** 主线 **`merger`**;顾问合并进行中 **`integrate/advisor-agent`**(自 `merger` 拉出 · 源 `xinghuo/advisor-agent`);历史 `risk-control-agent` 交付冻结。
**仓库地图:**
@@ -25,6 +25,9 @@
| `app/api/chat.py` `audit_middleware.py` | **已实现** | POST /api/chat · **POST /api/chat/stream(customer 分流 → prepare_customer_stream)** · visitor · sessions 三端点 |
| `app/api/customers.py` `products.py` `advisors.py` `staff.py` `compliance.py` | **已实现(v0.1 + 行情历史)** | 代销平台 REST;`get_platform_auth_context`;**`GET /api/products/{id}/nav/history`**(RBAC · compliance 拒) |
| `app/api/analyst.py` `analyst_auth_adapter.py` | **已实现(S3+D-06 + N-03/N-07 + analyze)** | 问数/chat · **`POST /analyze`** · interpret · sample · escalate · dashboard |
| `app/api/advisor_*.py` `kyc.py` `market.py` `copy.py` 等 | **接缝已挂(integrate/advisor-agent)** | 对外 **`/api/advisor-agent/*`**(合规 · 话术 · 异动 · KYC · 复制门闸 · guard · dashboard/allocation ping);鉴权 **`advisor_auth_adapter`** + `get_platform_auth_context`;**不迁** `/api/v1` · demo_ui · `admin/audit-logs` |
| `app/advisor_db.py` `entities_advisor.py` `advisor_schemas.py` | **接缝已挂** | 顾问 ORM/会话工厂 · 与 merger `entities.AgentSession` 共用 `metadata_` 列名 |
| `scripts/agent/migrate-advisor-agent-sprint1-3.sql` | **已新增(待本机执行)** | 顾问专用表(compliance_rule · kyc_session · market_alert · script_template 等) |
| `app/api/ready.py` | **已实现(2026-09-11)** | `GET /api/ready`:Redis + 关键路由自检;前端 `DevReadyBanner` |
| `app/service/analyst_agent.py` `template_service.py` `cache_service.py` `analyst_chart.py` | **已实现(S3+D-06 + D-11)** | NL2SQL · **published few-shot 仅库** · `_nl_sql_hints` 双极值 UNION · 模板 · **`reload_published_assets`** · **`clarify` 结构化** · analyze 图表 |
| `app/api/knowledge.py` `admin.py` | 空壳 | 待审计查询台与知识库 API(T-21 拍板一期只做脚本入库,上传/重建端点不做) |
@@ -50,7 +53,8 @@
| `scripts/core/*.sql` + `reset.ps1` | **已实现** | Core 模拟库 DDL + 种子 · **`07-seed-nav-history.sql`(14 产品 ×364 日)** · 再生 `seed_nav_history.py --export-sql` |
| `scripts/agent/` `scripts/demo/` `scripts/dev/` | **已实现** | **`prepare_all.ps1`** · **`push_threshold_alerts.py`** · **`seed_analyst.ps1`** · **`sandbox_risk_test.py`** · `run_query_battery.py`(**不入库**) |
| `scripts/sync/*.py` | **已实现** | 归属同步 + Neo4j 全图 |
| `tests/` | **已实现** | **861 用例** 1 skipped · 问数包 [TEST-LOG-2026-09-12-AN-002](tests/2026-09-12-analyst-template-phrases/TEST-LOG-2026-09-12-AN-002.md) |
| `tests/` | **已实现** | **926+ 用例**(含顾问 sprint)· merger 回归 **896 绿**(`-k 'not test_sprint'` 口径:`--ignore-glob=test_sprint*.py`)· 问数 [AN-002](tests/2026-09-12-analyst-template-phrases/TEST-LOG-2026-09-12-AN-002.md) |
| `docs/项目框架设计/理财顾问Agent-合并说明.md` | **实施中** | D1–D9 拍板 · 接缝清单 · 与 `docs/superpowers/plans/2026-09-12-advisor-agent-merge.md` 对齐 |
| `docs/答辩/` | **答辩提纲 + Demo SOP** | `答辩知识点清单.md` · **`DEMO-SOP-答辩全流程.md`** · `DEMO-SOP-问数.md` · spec `docs/superpowers/specs/2026-09-11-defense-stable-package.md` |
| `docs/course/` | **交互课程集** | 导览中心 + 总览 **8 模块** + 问数 **5 模块**(D-06)+ 风控深潜 **7 模块** · 与答辩清单同步 |
| `docs/PRD/PRD-风控监测Agent.md` | **已冻结(v1.1)** | 风控 PRD v1.0 + v1.1 追加 FR-8/9/10(§4A)+ 规则表附录 |
@@ -72,16 +76,18 @@
3. .\scripts\core\reset.ps1 # 建 jinrong_core(含 07 净值历史 ~365 日/产品)
4. mysql … < 01-mysql-共用底座.sql # jinrong_agent 共用 11 表
mysql … < 02-mysql-agent专用.sql # 风控四表 + risk_aml_list
mysql … < scripts/agent/migrate-advisor-agent-sprint1-3.sql # 投资顾问专用表(合并后必跑)
5. mysql … < scripts/agent/seed-aml-list.sql # AML 名单(Windows 乱码:`python scripts/dev/fix_utf8_seed.py`)
python scripts/seed/import_compliance_rules.py # 顾问合规规则(源:`docs/开发文档/20-Sprint1首批合规规则数据集.md`)
(风控演示:`.\scripts\demo\prepare_all.ps1` 或 `prepare_risk_demo.sql` · PRD §10.2)
6. python scripts/sync/sync_advisor_rel.py && python scripts/sync/sync_neo4j.py
7. `docker compose up -d redis`(或 `.\scripts\dev\start-redis.ps1`)→ **REDIS_URL=redis://127.0.0.1:6380/0**(Docker Redis 7;避开本机 Windows Redis 占 6379)
8. uvicorn … · python -m pytest(**861 绿**);问数答辩:`docs/答辩/DEMO-SOP-问数.md` · 模板种子 **`scripts/agent/seed-analyst-query-templates.sql`**
8. uvicorn … · python -m pytest(**merger 回归 ~896 绿**;全量含 sprint **926 passed / 65 failed**);问数答辩:`docs/答辩/DEMO-SOP-问数.md` · 模板种子 **`scripts/agent/seed-analyst-query-templates.sql`**
```
**AL-09 合并后架构(一句话):** 宿主 `gateway/` + 模块 `deps.py` **双栈并存**;对外登录/token **统一**;chat/risk 均走模块鉴权;接缝 S2 用 `auth_adapter`。
**下一步(见 TODO · §2026-09-11 接续):** git commit `merger`(含问候修复 + **问数/解读拆分**)· 前端加载体验 · battery · 客服验收 · **分析对话菜单可下线/强引导** · D-12 往后排
**下一步(见 TODO):** **`integrate/advisor-agent` → merger**(sprint 测全绿 · 本机跑迁移 SQL · 文档「已接线」)· git commit `merger` · battery · 客服验收 · D-12 往后排
**⚠️ 前端 E2E 未跑测试(2026-09-10):** 该轮走查**只做到「25 路由能渲染 + 无 console/HTTP 错误」,不是逐功能详测** —— 数字/图表/交互正确性、**接口错误态**、对话多轮与会话管理、适当性通过路径、交易拦截路径等**均未验证**(CHAT-1~4 就是这样漏掉的)。**未跑清单见 `TODO.md` §「前端 E2E · 未跑测试」**,报告见 `docs/整体测试/前端整体测试交接.md`。
@@ -110,8 +116,8 @@
## 1. 项目简介
- **名称:** JinRong 金融四 Agent 智能管家
- **当前阶段:** **代销平台 v0.1 + AL-09 + 客服 S2 Wave3 + 数据分析 S3/P2/D-06 + 前端 P0 Demo(2026-09-10)**
- **当前优先级:** merger 提交 · battery 跑分 · 客服验收 · analyst 多轮/溯源/转人工(规格缺口)· 客服 L1/L2 Redis(风控仅 L3)
- **当前阶段:** **代销平台 v0.1 + AL-09 + 客服 Wave3 + 问数 D-06/D-11 + 投资顾问 Agent 接缝(integrate/advisor-agent · 2026-09-12)**
- **当前优先级:** 顾问 merge 收尾(DB 迁移 · sprint pytest · 合入 merger)· merger commit · battery · 客服验收
------
@@ -192,7 +198,7 @@ Core 模拟:scripts/core/reset.ps1 · 文档 docs/项目框架设计/Core模
依赖:requirements.txt(LangGraph + langchain-core/openai + FastAPI + SQLAlchemy)
启动:uvicorn app.main:app --reload → GET /health · **GET /api/ready**(环境自检)
Redis:`docker compose up -d redis` · `REDIS_URL=redis://127.0.0.1:6380/0` · `scripts/dev/start-redis.ps1`
测试:python -m pytest(**861 绿**;集成需本机 MySQL + AML + 风控演示数据)
测试:python -m pytest(**926 passed / 65 failed / 1 skipped** 全量 · **896 passed** 不含 `test_sprint*`;集成需 MySQL + 顾问迁移 SQL + AML + 风控演示数据)
风控沙盘:`python scripts/dev/sandbox_risk_test.py`(TEST-RISK-001)
前端:cd web && npm run dev · npm run build/test/lint(**27** Vitest)· 四角色 Demo 见 **`docs/frontend/FRONTEND-HANDOFF.md` §8** · 本地后端 **`scripts/dev/restart-dev.ps1 -Backend Local`**
问数模板:mysql … < scripts/agent/seed-analyst-query-templates.sql
@@ -244,6 +250,6 @@ RBAC 联调账号:scripts/dev/rbac-seed-reference.md
2. 改动属于 api / service / tool / repository 哪一层?
3. 是否需 customer_id 归属与 JWT RBAC?
4. Core 是模拟库只读还是 agent 库读写?
5. 如何验证?(`python -m pytest` · `cd web && npm run test` **27 绿** · Redis **6380** · `/api/ready` · 问数 **clarify 点选口径** · 沉淀 **`seed_analyst.ps1` 灌库后重启后端** · 网页发布 **reload 不重启** · 日志 [AN-002](tests/2026-09-12-analyst-template-phrases/TEST-LOG-2026-09-12-AN-002.md))
5. 如何验证?(`python -m pytest` · 顾问冒烟 **`tests/test_sprint0_foundation.py`** · **`from app.main import app`** → OpenAPI **62** 路径 · `cd web && npm run test` **27 绿** · Redis **6380** · `/api/ready` · 问数 [AN-002](tests/2026-09-12-analyst-template-phrases/TEST-LOG-2026-09-12-AN-002.md) · 合并说明 **`docs/项目框架设计/理财顾问Agent-合并说明.md`**)
大任务:FRAMEWORK/FLOW 与实现状态不符时先更新 memory 再编码(用户确认跳过除外)。