Revert: restore hasToolInteraction guard in filterDeepSeekReasoningTurn

Restore the tool-interaction check that was removed in the previous
commit. DeepSeek's documented behavior only requires reasoning_content
to be preserved for tool-interaction turns; plain assistant turns
between user messages do not need it on replay.

This reverts the production code change while keeping the streaming
reasoning_content parsing fix from the earlier commit intact.
This commit is contained in:
cj 2026-05-03 01:55:48 +00:00
parent b4aa407601
commit 3a8e1f6952

View file

@ -255,6 +255,14 @@ func filterDeepSeekReasoningMessages(messages []Message) []Message {
} }
func filterDeepSeekReasoningTurn(messages []Message) []Message { func filterDeepSeekReasoningTurn(messages []Message) []Message {
hasToolInteraction := false
for _, msg := range messages {
if msg.Role == "tool" || (msg.Role == "assistant" && len(msg.ToolCalls) > 0) {
hasToolInteraction = true
break
}
}
out := make([]Message, 0, len(messages)) out := make([]Message, 0, len(messages))
for _, msg := range messages { for _, msg := range messages {
if messageutil.IsTransientAssistantThoughtMessage(msg) { if messageutil.IsTransientAssistantThoughtMessage(msg) {
@ -262,10 +270,13 @@ func filterDeepSeekReasoningTurn(messages []Message) []Message {
} }
cloned := msg cloned := msg
// DeepSeek thinking-mode requires reasoning_content to be echoed // DeepSeek thinking-mode replay only requires reasoning_content for
// back for ALL assistant turns. If missing the API returns 400: // turns that participate in a tool interaction round. For plain
// "The reasoning_content in the thinking mode must be passed back // assistant turns between two user messages, the docs say the API will
// to the API." // ignore reasoning_content on replay, so we strip it here.
if cloned.Role == "assistant" && strings.TrimSpace(cloned.ReasoningContent) != "" && !hasToolInteraction {
cloned.ReasoningContent = ""
}
if assistantMessageEmpty(cloned) { if assistantMessageEmpty(cloned) {
continue continue
} }