fix: encode thinking content parts as reasoning_content for OpenAI-compatible providers#647
Merged
mikehostetler merged 2 commits intoagentjido:mainfrom Apr 26, 2026
Conversation
…mpatible providers When assistant messages contain ContentPart.thinking(...) parts (e.g. from Moonshot reasoning models), the OpenAI encoder was stripping them via encode_openai_content_part returning nil for :thinking parts. This caused multi-turn conversations with Moonshot to fail with: > thinking is enabled but reasoning_content is missing in assistant tool call message Changes: - Add extract_reasoning_content/1 to pull thinking parts out of message content - In encode_openai_message, extract reasoning_content before encoding content, then add it as a top-level reasoning_content field on the encoded message - Remove thinking parts from the content list so they don't get encoded as nil This matches the OpenAI/Moonshot API contract where reasoning_content lives at the message level, not inside the content array.
Contributor
|
Thanks for the focused fix here. I marked this |
spfoos
pushed a commit
to spfoos/req_llm
that referenced
this pull request
Apr 25, 2026
- Only emit reasoning_content for :assistant messages to avoid sending it on user/system/tool roles where it is not expected. - Update stale comment about thinking parts in Defaults encoder. - Add regression tests: - thinking parts become top-level reasoning_content - multiple thinking parts are joined - non-assistant roles do not get reasoning_content - tool_calls preserved alongside reasoning_content Addresses review feedback on PR agentjido#647.
- Only emit reasoning_content for :assistant messages to avoid sending it on user/system/tool roles where it is not expected. - Update stale comment about thinking parts in Defaults encoder. - Add regression tests: - thinking parts become top-level reasoning_content - multiple thinking parts are joined - non-assistant roles do not get reasoning_content - tool_calls preserved alongside reasoning_content Addresses review feedback on PR agentjido#647.
35e8f6f to
c66403e
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.
When assistant messages contain ContentPart.thinking(...) parts (e.g. from Moonshot reasoning models), the OpenAI encoder was stripping them via encode_openai_content_part returning nil for :thinking parts.
This caused multi-turn conversations with Moonshot to fail with:
Changes:
This matches the OpenAI/Moonshot API contract where reasoning_content lives at the message level, not inside the content array.