Files
crm-ai/docs/plan-a.md
T

80 lines
3.9 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.
# 方案 A:bridge 接管 AI 编排(Live chat 优先)
## 决策
- 使用新 bridge 重写 AI 编排(不复用旧 bridge 代码)
- 先接 Live chat
- 保留 LibreDesk 的 widget JWT + OTP
## 架构
```
LibreDesk(渠道/工作台)
├─ 关闭该 inbox 的自带 AI 自动分配
├─ webhook message.created → bridge /libredesk/webhook
└─ bridge 通过 Agent API Key 回写消息
Bridge(AI 编排)
├─ LLM 调用 + 工具循环
├─ RAG / 上下文 / 情绪 / 质量闭环(后续)
└─ 业务工具(商品/订单/库存/商机/槽位)
```
## Phase 0(已完成)
- [x] 生成 LibreDesk Agent API Key(System 用户)
- [x] 创建 webhook:`message.created` → `http://bridge:4100/libredesk/webhook`
- [x] bridge webhook 端点:HMAC 验签、去重、防循环、inbox 过滤
- [x] bridge 通过 API Key 回写 agent 消息
- [x] Live chat 测试:LibreDesk 收到消息 → bridge 占位回复 → 工作台可见
- [x] 测试后恢复 LibreDesk 原有 AI 自动分配
### Phase 0 环境变量
```
LIBREDESK_API_KEY=...
LIBREDESK_API_SECRET=...
LIBREDESK_WEBHOOK_SECRET=...
LIBREDESK_WEBHOOK_INBOX_IDS=1
LIBREDESK_WEBHOOK_ID=1
```
## Phase 1 核心(已完成)
- [x] LLM 客户端(复用旧 DashScope qwen-plus-latest)
- [x] 系统提示词 + 历史消息上下文
- [x] 工具调用循环(5 个工具)
- [x] 工具调用审计日志
- [x] Live chat 实测:LLM 调 search_products,返回真实价格/库存/链接
- [x] 匿名 OTP 模块(SMTP 163 + Redis,发送/校验实测通过)
- [x] 旧 bridge pgvector RAG(vector-only;旧库无 text_tsv/parent_id)
- [x] AI 已实测:search_kb 回答最低起订量 €30 + 引用 URL
- [x] 匿名 OTP 端到端(AI 问邮箱 → 发码 → 客户回码 → verified → 查订单)
- [x] 切流:inbox 1 关闭 LibreDesk AI automation,启用 bridge webhook
- [ ] Email / WhatsApp 切 bridge(目前仍由 LibreDesk AI 处理)
- [x] 质量闭环第一步:逐会话指标 + URL/工具审计(bridge_ai_metrics)
- [x] LLM 语义缓存(政策 FAQ,pgvector 余弦 >0.85)
- [x] 上下文摘要/压缩(>24 条,保留最近 16 条)
- [x] Prompt 注入防护(消息检测 + 工具结果信任边界)
- [x] 全量商品页站点地图(www 32,691 / us 22,625,商品页 32,051/22,305)
- [x] Hybrid RAG:text_tsv/parent_id/chunk_type,523 parent + 71 child,向量+全文+RRF+父块扩展
- [x] 购买意向 post-LLM 追问兜底(产品+数量触发,缺公司/联系方式时多语言硬追问)
- [x] 商机补齐:内容指纹去重、跨渠道复用/同步、阶段推进、CRM 故障 fail-closed
- [x] 在线 FAQ/KB 同步(不依赖旧 bridge,`sync-kb-online.js`)
- [x] Citation Checker / 幻觉标记 / 飞轮样本
- [x] RAG reranker / 三级升级 / 语言硬约束 / 完整会话 Note
- [x] KB 版本列表/回滚、sitemap 类目 KB、A/B 实验、Prometheus /metrics
- [x] `search_email_history`:已验证客户邮件历史,强制按 verified email scope
- [x] 发送前输出护栏:句子级自动重写 + URL 白名单 + 价格/库存数字必须有工具证据
- [x] Email/WhatsApp 人工接管:Wholesale Support 团队 + assign_team 规则(AI 不再分配)
- [x] 指标告警(错误率/工具错误/未验证 URL/延迟 + 邮件)
- [x] 离线评测(18 条确定性黄金集 + 4 条真实模型 smoke)
- [ ] 质量闭环后续:告警、离线评测、飞轮
> 目前为避免 LibreDesk AI 与 bridge AI 双回复,bridge webhook 已临时停用;等 OTP/RAG 完成后切流(关闭 LibreDesk AI automation + 启用 webhook)。
## Phase 2(待做)
- RAG:混合检索 / rerank / 翻译回退
- 情绪检测 / 升级策略
- 质量闭环:引用审计、指标、评测、飞轮
- Email / WhatsApp 接入
## 开放问题
1. LLM 是否复用旧 DashScope `qwen-plus-latest` 配置?
2. Phase 1 先只处理已登录 JWT 用户,匿名 OTP 用户后置?
3. RAG 用旧 bridge 的 pgvector 还是 LibreDesk 帮助中心?