fix: preserve reasoning_content for assistant thinking history in OpenAI-compatible requests#1401
Open
QaqNaN wants to merge 1 commit into
Open
fix: preserve reasoning_content for assistant thinking history in OpenAI-compatible requests#1401QaqNaN wants to merge 1 commit into
QaqNaN wants to merge 1 commit into
Conversation
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.
#1400
Summary
This PR fixes a reasoning-history compatibility issue for OpenAI-compatible providers such as Kimi.
CCR already preserves Claude/Anthropic thinking blocks internally as
thinking, but in multi-turn tool-call flows that reasoning history was not always carried back intoreasoning_contenton assistant messages before sending the final upstream request.Some providers are strict about this. For example, Kimi may reject the request with an error like:
thinking is enabled but reasoning_content is missing in assistant tool call message
What changed
Extend unified message structure
Added reasoning_content?: string to the unified message type so reasoning history can be preserved explicitly in the internal message model.
Preserve reasoning content during Anthropic -> unified conversion
When converting Anthropic/Claude assistant messages that contain thinking blocks, the extracted thinking content is now also stored in reasoning_content.
Add request-side fallback in the reasoning transformer
Before sending a request upstream, the reasoning transformer now checks assistant history messages and fills reasoning_content from thinking.content when it is missing.
This makes the behavior more robust even if earlier stages only preserved thinking.
Why this is needed
CCR already handles:
enabling/disabling reasoning mode on requests
converting provider reasoning_content back into CCR thinking on responses
But assistant reasoning history was not reliably restored into the OpenAI-compatible request format.
This becomes visible in providers that validate reasoning history for assistant tool-call messages.
Scope
This is not a Kimi-specific code path.
The fix is implemented in the shared message conversion / reasoning flow so that any OpenAI-compatible provider expecting reasoning_content can benefit.
Files changed
packages/core/src/types/llm.ts
packages/core/src/transformer/anthropic.transformer.ts
packages/core/src/transformer/reasoning.transformer.ts
Testing
Tested locally with Kimi reasoning mode in a tool-call flow.
Before this change:
follow-up requests could fail with missing reasoning_content on assistant tool-call history
After this change:
the same flow completes successfully
Notes
This change may slightly increase request payload size because preserved reasoning history can now exist in both thinking and reasoning_content forms internally / during request transformation.
However, this is intentional and improves compatibility with strict reasoning-capable providers.