返回 DeepSeek-Reasonix
reasoning_replay.go
根目录 / internal / provider / responses / reasoning_replay.go
1 package responses
2
3 import (
4 "reasonix/internal/provider"
5 "slices"
6 "strings"
7 )
8
9 // RequiresToolCallReasoning tells the agent to preserve stateless vendors'
10 // reasoning on assistant tool-call turns so the follow-up can replay it.
11 // DeepSeek and MiMo document this requirement for multi-turn tool calls.
12 func (c *client) RequiresToolCallReasoning() bool {
13 return c != nil && c.caps.toolCallReasoning && !responsesReasoningDisabled(c.effort)
14 }
15
16 // AllowsEmptyReasoningFallback reports that a Responses tool turn remains
17 // replayable when the provider emitted no reasoning item. DeepSeek and MiMo
18 // both accept the function_call/function_call_output pair without fabricating
19 // a reasoning item; any reasoning that was emitted is still preserved above.
20 func (c *client) AllowsEmptyReasoningFallback() bool {
21 return c.RequiresToolCallReasoning()
22 }
23
24 func (c *client) MissingToolCallReasoningWarningIdentity() string {
25 if c == nil {
26 return ""
27 }
28 return strings.Join([]string{
29 "responses", strings.TrimSpace(c.name), strings.TrimSpace(c.requestURL),
30 strings.TrimSpace(c.model), strings.TrimSpace(c.vendor), strings.TrimSpace(c.mode), strings.TrimSpace(c.effort),
31 }, "\x00")
32 }
33
34 // WarnOnMissingToolCallReasoning reports a tool_calls turn that arrived
35 // without reasoning only for vendors whose endpoint reliably emits it.
36 // DeepSeek's official API emits tool-call reasoning for its pro-tier models,
37 // so a missing chain-of-thought there is a real degradation worth one warning.
38 // MiMo documents reasoning alongside tool calls but does not guarantee it on
39 // every round (observed: mimo-v2.5-pro tool-call turn with empty reasoning),
40 // so a missing chain-of-thought is endpoint-conditional, not a degradation
41 // signal — silence the warning. Capability-driven (review #7234):
42 // toolCallReasoning=false vendors (DashScope) never warn — no round-trip
43 // contract; singleSegmentReasoning=true vendors (MiMo) never warn — their
44 // tool-call thinking is a single optional segment. Only multi-segment
45 // thinking vendors that require replay (DeepSeek) warn, scoped to non-flash.
46 func (c *client) WarnOnMissingToolCallReasoning() bool {
47 if !c.RequiresToolCallReasoning() || c.caps.singleSegmentReasoning {
48 return false
49 }
50 model := strings.ToLower(strings.TrimSpace(c.model))
51 // Flash-tier DeepSeek models do not emit tool-call reasoning (same carve
52 // as openai.go expectsDeepSeekToolCallReasoning).
53 return !strings.Contains(model, "flash")
54 }
55
56 func (c *client) RequiresAssistantReasoningReplay(m provider.Message) bool {
57 if slices.ContainsFunc(m.ResponsesItems, provider.IsReplayableResponsesReasoning) {
58 return true
59 }
60
61 return c.RequiresToolCallReasoning() && (len(m.ToolCalls) > 0 || m.ReasoningContent != "")
62 }
63
63 lines GO