Repository navigation
fix: a thinking model is handed its earlier reasoning on tool-calling requests - #512
Merged
Merged
Conversation
… requests DeepSeek's thinking mode needs every earlier turn's reasoning_content back on a request carrying tools, and answers 400 without it. The OpenAI-wire client read reasoning from the stream but never wrote it back. The field is named per model by models.dev's interleaved.field, and Ollama (local and Cloud), which reads it as 'reasoning' and drops the other name, declares it on its class. OpenAI is sent none.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
OpenAiClientreadreasoning_content/reasoningoff the stream but wrote an assistant message back ascontent+tool_callsonly. DeepSeek's thinking-mode guide says that on a request carryingtools, thereasoning_contentof all previous turns must be passed back. The official API answers 400 without it. Withouttoolsit is ignored.Through Ollama Cloud nothing errored. Ollama's compat layer reads earlier thinking from
reasoningand drops unknown fields, so DeepSeek V4 Pro ran each of ~1,300 tool-calling steps without the reasoning of the steps before.What
OpenAiClient.reasoningFieldOf(model, tools:)names the field an assistant message'sreasoninggoes back in. It is told whether the request carries tools, and null sends nothing. The tools-only rule is DeepSeek's, so the provider answers it rather than the encoder.ModelInfo.interleavedFieldkeeps models.dev'sinterleaved.field(and the catalog cache writes it back).OpenAiCompatibleProvider.replayedReasoningFieldreads it: DeepSeek →reasoning_content. Z.ai and other described hosts get it the same way. OpenRouter's structuredreasoning_detailsis excluded.OllamaProviderandOllamaCloudProvidershare one mixin,OllamaCompat, which answersreasoningbeside tools. models.dev has nointerleavedon Ollama Cloud'sdeepseek-v4-pro, andreasoning_contentwould be dropped there anyway.OpenAiPlatformClienttakes none.reasoningfor every reply, live and reloaded. A test now pins that an earlier turn's reasoning survives the rebuild.lib/data/builtin/llm/AGENTS.mdsays all of this.Tests
openai_client_test: replayed in the named field beside tools; not sent for an unnamed model, without tools, or by a client with no field (OpenAI's included).providers_test: the catalog gate, the cache round trip, thereasoning_detailsexclusion, Ollama's field, and none for OpenAI.projection_test: an earlier turn's thinking is rebuilt.