Files
group_xinghuo_jinrong/docs/memory/FLOW.md
T
zhanghongyu_0626 bf8f271840 feat(redis): Update Redis configuration and enhance compatibility with Docker
- Changed Redis port mapping in `docker-compose.yml` from `6379:6379` to `6380:6379` to avoid conflicts with Windows Redis.
- Updated `.env.example` to reflect the new Redis URL (`redis://127.0.0.1:6380/0`), ensuring proper configuration for Docker users.
- Enhanced Redis client initialization in `database.py` and `redis_gateway.py` to utilize a new `_redis_kwargs` function for improved compatibility with Windows Redis 3.x and Docker Redis 7.
- Added a new PowerShell script `start-redis.ps1` to facilitate starting Redis in Docker, providing a seamless setup experience for developers.

This update significantly improves the Redis integration, ensuring a smoother development process and better compatibility across environments.
2026-09-09 20:19:55 +08:00

6.3 KiB
Raw Blame History

实现流程

To-Be 端到端链路;As-Is 见 ENVIRONMENT.md
画像分层见 docs/项目框架设计/表设计/00-架构总览.md


0. 本地 bootstrap(新环境 / 新 Agent)

前置:MySQL 8、**Docker Desktop(Redis + 可选 Neo4j compose)**、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         → 关系图(需 compose neo4j 或 Desktop)

⑤b Redis(推荐 Docker)
   docker compose up -d redis
   # 或 .\scripts\dev\start-redis.ps1
   # .env: REDIS_URL=redis://127.0.0.1:6380/0  (避开本机 Windows Redis 占 6379)

⑥ 验证
   uvicorn app.main:app --reload
   GET http://127.0.0.1:8000/health  → {"status":"ok"}
   cd web && npm run dev               → 5173 代理 8000
   python -m pytest   → 730 passed 0 skipped

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. 链路总览(目标)

Client → Gateway(JWT/RBAC) → api/chat → agent_service(LangGraph) → Tools → 存储 → 响应 + audit_log

当前:风控全链路 + Wave 0 共用底座 + 代销平台 v0.1 + AL-09 + 客服 S2 + 前端 P0 主链路(2026-09-09,merger)。测试基线:python -m pytest → 730 passed · web/ 19 Vitest 绿。

下一步(统筹 P1): analytics 问数页 · 接口契约发群 · customer Chat SSE(后端 stream 未接 customer_service)。

本机已就位状态(2026-09-09): .env 含 REDIS_URL=redis://127.0.0.1:6380/0(Docker Redis 7);pytest 730 绿;前端 Chat/平台页已真接。演示/走查后按《演示SOP-风控模块.md》§2 重灌。

本机已知坑: mysql.exe 不在 PATH;reset.ps1 自动化用 MYSQL_PWD;6379 常被 Windows Redis 3.x 占用 → 项目 Docker 映射 6380;Milvus 中文路径需英文 MILVUS_URI;重装环境后 python -c "import jose, redis" 自检。


2. 主链路 · 对话

输入: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. 主链路 · 知识库入库

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