llms: preserve reasoning_content in MessageContent for tool calling round-trip#1479
Open
llms: preserve reasoning_content in MessageContent for tool calling round-trip#1479
Conversation
ee0e8f3 to
fe77f3a
Compare
fe77f3a to
df72e5b
Compare
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.
fix: preserve
reasoning_contentin tool calling round-trip for deepseek-reasonerCloses #1478
Summary
reasoning_contentbeing lost during conversation round-trip when usingdeepseek-reasonerwith tool callingreasoning_content-- without it, the API returns HTTP 400:Missing reasoning_content field in the assistant messageProblem
The
reasoning_contentfield was correctly parsed from API responses (PR #1121) but could not be sent back in subsequent requests because:MessageContentstruct had noReasoningContentfield -- users couldn't attach reasoning content to assistant messages in conversation historyMessageContent->ChatMessageconversion in the OpenAI provider didn't transfer reasoning contentChanges
llms/generatecontent.goReasoningContent stringfield toMessageContentstructllms/openai/openaillm.gomc.ReasoningContenttomsg.ReasoningContentwhen converting AI messagesllms/marshaling.goMarshalJSON/UnmarshalJSONto includereasoning_content(with omitempty)llms/marshaling_test.gollms/openai/internal/openaiclient/chat_test.goUsage
After this fix, users can preserve
reasoning_contentin the tool calling round-trip:Test plan
ChatMessagemarshal/unmarshal withReasoningContent+ToolCallsMessageContentmarshal/unmarshal withreasoning_contentMessageContentwithreasoning_content+ tool calls (JSON and YAML)go test ./llms/...)Notes
ReasoningContentdefaults to empty string and is omitted from JSON when emptyOpenAIFunctionsAgentalso doesn't propagatereasoning_contentthrough its scratchpad (agents/openai_functions_agent.go). This is a separate issue that can be addressed in a follow-up PR