Files
XingHuo/docs/memory/FLOW.md
T

81 lines
2.2 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`
------
## 1. 链路总览
```text
Client → Gateway(JWT/RBAC) → api/chat → agent_service → Tools → 存储 → 响应 + audit_log
```
------
## 2. 主链路 · 对话
```text
输入:Authorization + X-Agent-Type + X-Trace-Id + 用户消息
↓
Gateway:验签、角色准入、注入 AuthContext
↓
api/chat:SessionGuard;创建/续 agent_session
↓
memory_service:Redis 读最近 N 轮;异步写 agent_message
↓
agent_service:LangChain + DeepSeek;按 Agent 类型选 Tool 集
↓
Tool 示例:
- Core RO:持仓/流水(自动注入 customer_id)
- milvus_tool:产品规则 RAG + source_refs
- memory_service:读/写 L1/L2/L3(ProfileGuard)
- 风控 service 账号:R-02 适当性(无会话)
↓
输出:assistant 消息 + has_disclaimer(客户/对外)
↓
落库:agent_message、agent_tool_call、audit_log(同 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 |
| 会话 | session_id | Redis ctx + MySQL session | actor_id 一致 |
| RAG | question + product_id? | chunks + source_doc_id | 必须溯源 |
| 画像读 | customer_id | L1/L2/L3 JSON | RBAC 矩阵 §8 |
| 审计 | 任意判定 | audit_log INSERT | 不可删改 |
------
## 6. 关键数据约定
- MySQL 脚本:`docs/项目框架设计/表设计/01-mysql-共用底座.sql`、`02-mysql-agent专用.sql`
- Redis Key:`docs/项目框架设计/表设计/02-redis-keys.md`
- Milvus:`kb_product_rules`、`kb_business_ops`;向量 **1024** 维
- 禁止:Agent 覆盖 L0 正式 C1~C5