实现 Provider reasoning 协议解析
解析 Chat 与 Responses 的 reasoning 字段和流式事件 保持正文、工具调用与 GameAgent 默认行为不变 补充 reasoning 分流、终态快照与兼容开关测试
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
# 【实施计划】Provider reasoning 协议解析
|
||||
|
||||
| 字段 | 值 |
|
||||
| --- | --- |
|
||||
| Milestone | `docs/project-memory/plans/【里程碑】Provider推理与正文分离及策划Agent展示-2026-09-14.md` |
|
||||
| Status | awaiting-review |
|
||||
| Owner | Codex |
|
||||
|
||||
## 修改边界
|
||||
|
||||
本轮只修改 `server-rs/crates/platform-llm/src/lib.rs` 的共享 Provider 解析、流式累计和相关单元测试;不接入策划 Runtime、Tauri 事件、前端 UI,也不修改 GameAgent、HTTP、OpenAPI、SpacetimeDB 或持久化 schema。
|
||||
|
||||
## 实现顺序
|
||||
|
||||
1. 扩展 Chat 与 Responses 的内部响应 DTO/事件提取器,识别 reasoning 文本并继续过滤出正文。
|
||||
2. 将 reasoning 作为独立事件字段进入流式累计;仅在 `capture_reasoning=true` 时写入累计值和回调,默认关闭保持空值。
|
||||
3. 在非流式 Responses/Chat 终态响应中填充 `LlmRunResponse.reasoning`,解析异常降级为空且不影响正文和工具调用。
|
||||
4. 增加协议级测试,覆盖增量顺序、终态快照、content parts、无 reasoning、工具调用共存和默认关闭兼容。
|
||||
|
||||
## 验收标准
|
||||
|
||||
- `reasoning_delta` 与 `delta_text` 分离,`accumulated_text` 永不包含 reasoning。
|
||||
- `capture_reasoning=false` 时 `LlmStreamDelta` 与 `LlmRunResponse` 的 reasoning 字段为空。
|
||||
- `capture_reasoning=true` 时 Chat 的 `reasoning`/`reasoning_content`/reasoning parts、Responses 的 reasoning summary 增量和终态 output 均可累计。
|
||||
- reasoning 缺失或形状未知时不影响正文、工具调用、finish reason 和 Responses 原生 output。
|
||||
- 相关 Rust 测试、格式、编码和 diff 检查通过。
|
||||
|
||||
## 本轮验收证据
|
||||
|
||||
| 证据 | 结果 |
|
||||
| --- | --- |
|
||||
| `cargo test --manifest-path server-rs/Cargo.toml -p platform-llm` | PASS,151 个单元测试通过;真实 Provider 测试按仓库约定保持 ignored |
|
||||
| `cargo fmt --manifest-path server-rs/Cargo.toml --all -- --check` | PASS |
|
||||
| `npm run check:encoding` | PASS,4560 个文件 |
|
||||
| `npm run check:doc-index` | PASS |
|
||||
| `git diff --check` | PASS |
|
||||
|
||||
未验证项:未连接真实 Provider;策划 Runtime、Tauri 事件和前端 UI 属于后续里程碑,本轮未接入。
|
||||
|
||||
## 验证命令
|
||||
|
||||
```text
|
||||
cargo test --manifest-path server-rs/Cargo.toml -p platform-llm
|
||||
cargo fmt --manifest-path server-rs/Cargo.toml --all -- --check
|
||||
npm run check:encoding
|
||||
git diff --check
|
||||
```
|
||||
|
||||
## 风险与回滚点
|
||||
|
||||
- Provider 兼容网关可能把 reasoning 放在未建模字段;提取器采用可选 JSON 读取,失败只丢弃 reasoning。
|
||||
- 终态 summary 可能重复增量;累计逻辑按快照与已有前缀去重。
|
||||
- 若发现正文或工具调用回归,回退本轮解析提交即可,第一轮共享契约仍可独立保留。
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user