Files
group_xinghuo_jinrong/docs/memory/FLOW.md
T
zhanghongyu_0626 ad930c26b1 feat(frontend): Implement initial P0 scaffolding and enhance dashboard features
- Established the P0 scaffolding for the frontend, including login, layout, and routing for four roles.
- Integrated the Customer Wealth Dashboard, Advisor Clients Dashboard, Analyst Market Dashboard, and Risk Alerts Dashboard.
- Updated the API client to support fetching customer and product data, enhancing the overall functionality of the dashboard.
- Added error handling components to improve user experience during data fetching.
- Enhanced charting capabilities using Ant Design Charts for better data visualization.

This update lays the groundwork for further development of the frontend application, ensuring a robust structure for future features and integrations.
2026-09-09 15:50:33 +08:00

130 lines
7.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 实现流程
> To-Be 端到端链路;As-Is 见 `ENVIRONMENT.md`
> 画像分层见 `docs/项目框架设计/表设计/00-架构总览.md`
------
## 0. 本地 bootstrap(新环境 / 新 Agent)
```text
前置:MySQL 8、Redis、Neo4j Desktop、Ollama(bge-m3) 已安装并启动
① 配置
cp .env.example .env
必填:MYSQL_PASSWORD、NEO4J_PASSWORD、DEEPSEEK_API_KEY(对话阶段)
② 依赖
pip install -r requirements.txt
③ Core 模拟库(L0)
.\scripts\core\reset.ps1
→ 创建 jinrong_core + 28 客户 / 12 产品 / 持仓交易种子
(风控演示:再执行 scripts/demo/prepare_risk_demo.sql 刷新测评日期 · PRD §10.2)
④ Agent 共用底座(若库未建)
mysql -u root -p < docs/项目框架设计/表设计/01-mysql-共用底座.sql
(风控:再建 02-mysql-agent专用.sql 的 risk_aml_list + 灌 scripts/agent/seed-aml-list.sql)
⑤ 同步
python scripts/sync/sync_advisor_rel.py → customer_advisor_rel
python scripts/sync/sync_neo4j.py → 关系图
⑥ 验证
uvicorn app.main:app --reload
GET http://127.0.0.1:8000/health → {"status":"ok"}
python -m pytest → 530 passed 0 skipped(改路由必同步 test_all_routers_mounted)
RBAC 联调账号:scripts/dev/rbac-seed-reference.md
```
**尚未自动化:** agent 专用表已有 `02-mysql-agent专用.sql`(手工执行,含 risk_aml_list);Milvus 建 Collection 已随 T-21 自动化(`scripts/kb/build_kb.py` 可重灌)。JWT 中间件已完成(T-01:`app/service/auth_service.py` + `deps.py` 工厂;dev 联调签发 `scripts/dev/issue_dev_token.py`,debug 头兜底仅限 development 且未配 RS256 公钥)。
------
## 1. 链路总览(目标)
```text
Client → Gateway(JWT/RBAC) → api/chat → agent_service(LangGraph) → Tools → 存储 → 响应 + audit_log
```
当前:**风控全链路 + Wave 0 共用底座 + 代销平台 API v0.1 + AL-09 合并接线已完成(2026-09-08,`merger` 分支)**——B1~B9b 事件线 · C1~C6 对话/追加需求(FR-8/9/10)· 前端接入 B/C(sessions/stream)· T-03/T-04/T-21 · JWT 统一 + auth_adapter 接缝。**测试基线:`python -m pytest` → 530 passed 0 skipped**(含 `test_module_boundary` 宿主 D 类文件排除规则)。
**下一步(统筹 P1):** 前端 `web/` P0 真接(见 TODO · `docs/superpowers/specs/2026-09-09-frontend-p0-design.md` §6)· 接口契约 v0.1 发群 · 客户/代理人/分析 Agent 并行。
**本机已就位状态(2026-09-08 · 已完成上述 ①~⑤,无需重做):** `.env` 已配置(学习项目;DEEPSEEK_API_KEY 空时 chat 走降级回复;JWT 未配项时走默认 `JWT_DEV_SECRET`,**启动 warning 属预期**);`jinrong_core` + `jinrong_agent` 已灌库(33 客户/14 产品/矩阵 25 行/风评 33 / AML 8 条 / 归属 33 行);`python -m pytest` **530 绿 0 skipped**(集成测试真连本机 MySQL;Windows 中文乱码跑 `python scripts/dev/fix_utf8_seed.py`);Redis `redis://127.0.0.1:6379/0` 在跑。**演示/走查后按《演示SOP-风控模块.md》§2 重灌**(`reset.ps1` + `prepare_risk_demo.sql` 两步必跑)。
**本机已知坑:** `mysql.exe` 不在 PATH(位于 `C:\Program Files\MySQL\MySQL Server 8.0\bin`);`reset.ps1` 的交互式 `-p` 在自动化执行时会卡死——脚本化重灌用 `MYSQL_PWD` 环境变量传密码(交互执行不受影响,不把密码写进仓库脚本);**`redis` 与 `python-jose[cryptography]` 包均出现过 requirements 有而环境漏装(B9a 补装 redis、Wave 0 补装 jose,2026-09-07),重装环境后先 `python -c "import jose, redis"` 自检**。
------
## 2. 主链路 · 对话
```text
输入:Authorization + X-Agent-Type + X-Trace-Id + 用户消息
↓
Gateway:验签、角色准入、注入 AuthContext 【T-01 已做】(JWT 验签/吊销 + AGENT_ACCESS_MATRIX)
↓
输入防护:限流(429)→ 注入/超长(400) 【T-03 已做】(Redis 固定窗口 30 次/分 fail-open;被拒 fail-fast 不建会话,blocked 落 input_guard_log)
↓
api/chat:SessionGuard;创建/续 agent_session 【T-06 已做】(actor/agent_type 一致校验)
↓
memory_service:Redis 读最近 N 轮;MySQL 落盘 agent_message 【T-06 已做】(窗口 TTL2h N≤20,miss 回源;同步落盘)
↓
agent_service:LangGraph StateGraph + DeepSeek;tool(意图→Tool) → llm → guard 【T-04 + C2 已做(分组关键词意图 customer/advisor/risk;risk 分支接 C1 四 Tool)】
↓
Tool(tool_service.run_tool:白名单 → 归属校验 → 执行 → agent_tool_call 落库):
- CoreReadOnlyRepository:持仓/流水/L0(customer_id 由会话注入,不来自 LLM) 【T-04 已做 app/tool/core_tools.py 三 Tool】
- 风控四 Tool:alert_query/customer_context/suitability_check/aml_lookup 【C1 已做 chat_tools(RISK_TOOL_REGISTRY)】
- milvus_tool:产品规则 RAG + source_refs 【已做 T-21(app/tool/kb_tools.py + rag_service/milvus_service;仅 customer/advisor 意图开放)】
- memory_service:读/写 L1/L2/L3(ProfileGuard) 【窗口读写已做;画像读写待做】
↓
输出:assistant 消息 + has_disclaimer(customer/risk 固定免责,T-07 guard 节点)
↓
落库:agent_message、agent_tool_call(T-04 已接:success/blocked/error 全留痕,message_id 一期 NULL)、audit_log(http_access 已接,同 trace_id)
```
------
## 3. 主链路 · 知识库入库
```text
admin/knowledge 上传 → document_parser → embedding_tool(Ollama bge-m3)
→ milvus_tool 写入 Collection(dim=1024)
→ 元数据可选写 MySQL;原文件存 data/kb/
```
------
## 4. 分支 · 四 Agent
| X-Agent-Type | 写画像 | 特殊 |
| --- | --- | --- |
| customer | L1 | 仅本人;读 suitability 本人 |
| advisor | L2 | customer_advisor_rel 校验 |
| analyst | 无 | 仅 SELECT SQL |
| risk | L3、预警、适当性 | R-02 可 blocked |
------
## 5. 每步 I/O
| 步骤 | 输入 | 输出 | 约定 |
| --- | --- | --- | --- |
| 鉴权 | JWT | AuthContext | 失败 401/403 + audit + input_guard_log 双写(401 归 platform) |
| 会话 | session_id | Redis ctx + MySQL session | actor_id 一致(AUTH_403_SESSION_AGENT) |
| RAG | question + product_id? | chunks + source_doc_id | 必须溯源 |
| 画像读 | customer_id | L1/L2/L3 JSON | RBAC 矩阵 §8 |
| Core RO | customer_id | L0/持仓/流水 | 只读 jinrong_core |
| 审计 | 任意判定 | audit_log INSERT | 不可删改;http_access 经 audit 中间件 |
------
## 6. 关键数据约定
- Agent 库 SQL:`docs/项目框架设计/表设计/01-mysql-共用底座.sql`、`02-mysql-agent专用.sql`
- Core 模拟:`scripts/core/01-ddl.sql` · 说明 `docs/项目框架设计/Core模拟底座/01-表结构与种子说明.md`
- Redis Key:`docs/项目框架设计/表设计/02-redis-keys.md`
- Milvus:`kb_product_rules`、`kb_business_ops`;向量 **1024** 维
- 禁止:Agent 覆盖 L0 正式 C1~C5