aps-agent/docs/architecture/dialog.md

45 lines
2.6 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.

# 对话智能:多轮澄清 + 引导式排产向导
> M-F 落地:听不懂就追问,缺数据就引导,小白也能排产。
> 代码:`server/agent_core/dialog.py`;接线在 `gateway/app.py` 的 chat 流(`pre_route` / `post_route`)。
## 管线位置
```
用户输入 → dialog.pre_route(session, text) # 若有挂起澄清/向导态,优先按上下文解析
→ intent.recognize(...) # 快路正则 + LLM
→ dialog.post_route(session, result) # 低置信/unknown → 澄清卡;wizard 意图 → 向导
→ workflow.handle_intent(...) # 正常执行
```
会话态存内存 `_SESSIONS[session_id]`:`clarify`(挂起澄清)与 `wizard`(向导状态机)。
## 多轮澄清(clarify)
- 触发:意图 `unknown` 或置信 0.5–0.85,且 `guess_domain` 能猜出领域(排产/订单/主数据/知识/技能/系统)。
- 出「clarify」UI 块:top 候选意图按钮 + 文案「你是想…?」;下一句优先按澄清上下文解析——
序号(「第一个」)、关键词、原文重述均可回填。
- 若追问后仍无新领域线索,复用上一轮候选再问一次;**两轮未解 → 放弃回兜底帮助**。
- 高置信(≥0.85)意图完全不走澄清,零额外延迟。
## 引导式排产向导(`schedule.wizard`,P0)
口令:「我要排产 / 帮我排产 / 怎么排产」。状态机每步 = 对话 + 表单卡(UI 块 type=`wizard`):
1. **readiness 检查**([M-B](./database.md),`aps_domain/readiness.py`)→ 全绿直接给「试排」按钮;
2. **缺工艺路线** → 按产品名在 `routing_templates` + RAG 推荐模板(「看起来是车削类零件,推荐:
粗车→精车→钻孔→去毛刺」)→ 用户选定 → `routing.template.apply` **P2 确认卡**写入路线;
3. **缺工时** → 逐工序追问「X 工序单件几分钟」→ `flex.time.update` P2;或「跳过用默认」标「推断」;
4. **缺日历** → 提供默认单班日历一键写入;
5. 齐备 → 自动试排(`flex.schedule` P1)+ 结果讲解。全程可「取消/跳过」。
## 权力边界
向导本身 P0(只读引导),所有写入动作复用既有 P2 通道(确认卡 → `/api/actions/confirm`),
无绕行——见 [harness.md](./harness.md) 的 `schedule.wizard / routing.template.apply / flex.time.update`。
## 测试
`tests/golden/test_dialog_clarify.py`(低置信→澄清→序号/关键词回填→两轮放弃)、
`test_schedule_wizard.py`(全绿直排 / 缺路线推荐模板 / 缺工时追问 / 缺日历默认 / 取消)。