Capture OpenAI-compatible reasoning and replay it in assistant history #41

Merged
weichen merged 1 commits from feature/quality-p2-i2 into main 2026-10-09 16:07:23 +00:00
Owner

摘要

质量 P2-I2 的内核侧两处小改:

  1. 思考捕获:SSE 的 reasoning_content 累计进终末消息的 Message.Thinking(正文不污染),随会话转录持久化。
  2. 思考回放:OpenAI 兼容序列化(toProviderMessages)把 assistant 捕获到的思考以 块前缀回放。无思考块的消息零改动(非思考模型上下文不受影响);Anthropic 原生路径不变。

背景:转录成为产品直连路径的权威上下文(Dev 任务卡 feature/agent-quality-phase02)后,MiniMax/DeepSeek R1 等交错思考模型要求的历史思考回传必须由内核承载(此前由产品在请求侧重建时注入,P2-I1)。

Evidence

  • SELF:TestReasoningCaptureAndReplay(捕获:reasoning_content→Thinking 且 content 干净;回放: 前缀、无思考消息原样);go vet + go test ./... 全绿
  • 消费方:Backend 分支 feature/agent-quality-phase02(嵌套 pin 指向本头)

Impact

无接口变更;Message.Thinking 语义注释更新。转录文件新增 thinking 字段(omitempty,旧文件兼容)。

## 摘要 质量 P2-I2 的内核侧两处小改: 1. **思考捕获**:SSE 的 reasoning_content 累计进终末消息的 Message.Thinking(正文不污染),随会话转录持久化。 2. **思考回放**:OpenAI 兼容序列化(toProviderMessages)把 assistant 捕获到的思考以 <think> 块前缀回放。无思考块的消息零改动(非思考模型上下文不受影响);Anthropic 原生路径不变。 背景:转录成为产品直连路径的权威上下文(Dev 任务卡 feature/agent-quality-phase02)后,MiniMax/DeepSeek R1 等交错思考模型要求的历史思考回传必须由内核承载(此前由产品在请求侧重建时注入,P2-I1)。 ## Evidence - SELF:TestReasoningCaptureAndReplay(捕获:reasoning_content→Thinking 且 content 干净;回放:<think> 前缀、无思考消息原样);go vet + go test ./... 全绿 - 消费方:Backend 分支 feature/agent-quality-phase02(嵌套 pin 指向本头) ## Impact 无接口变更;Message.Thinking 语义注释更新。转录文件新增 thinking 字段(omitempty,旧文件兼容)。
weichen added 1 commit 2026-10-09 15:38:55 +00:00
Capture OpenAI-compatible reasoning and replay it in assistant history
ci / vet-and-test (pull_request) Successful in 51s
ci / docker-checkout-hostgateway (pull_request) Successful in 1s
3b92cb63b4
Why: Interleaved-thinking models (MiniMax, DeepSeek R1) require the
assistant's thinking to be passed back verbatim in message history; dropping
it degrades later turns. The product's P2-I1 replayed thinking only into the
request-side rebuild; with the session transcript becoming the authoritative
context (quality P2-I2), capture must live in the kernel so thinking persists
in the transcript and replays on every request.

Evidence: SELF - TestReasoningCaptureAndReplay covers capture (SSE
reasoning_content into Message.Thinking, content unpolluted) and replay
(<think> prefix on thinking assistants, untouched non-thinking messages);
go vet + go test ./... pass.

Impact: sse.go accumulates reasoning deltas into the terminal message's
Thinking; client.go toProviderMessages renders captured thinking as a
<think> block prefix for assistant messages. Anthropic path unchanged;
messages without thinking serialize exactly as before.
weichen merged commit 76b6171de5 into main 2026-10-09 16:07:23 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: weichen/Agent-Native#41