-
Notifications
You must be signed in to change notification settings - Fork 7k
feat(provider): add interleaved thinking support for models #5201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Add interleaved_thinking field to ModelsDev Model schema - Add interleavedThinking capability to provider Model interface - Update transform logic to handle interleaved_thinking field mapping - Add test coverage for interleaved thinking transformation This enables support for models with interleaved thinking capabilities in the provider system, allowing better integration with models that support this feature.
- Make interleavedThinking field optional to maintain backward compatibility - Prevent TypeScript errors when models don't have this new capability yet
| capabilities: { | ||
| temperature: model.temperature ?? existingModel?.capabilities.temperature ?? false, | ||
| reasoning: model.reasoning ?? existingModel?.capabilities.reasoning ?? false, | ||
| interleavedThinking: model.interleaved_thinking ?? existingModel?.capabilities.interleavedThinking ?? false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the casing is not consistent across the change set: stick to the one used in the code base.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the naming to interleavedthinking (all lowercase) to align with the existing toolcall convention in the codebase. Pushed the fix.
Address review feedback: rename interleavedThinking to interleavedthinking to match the codebase convention (e.g., toolcall instead of toolCall)
|
I think the correct fix is adding the reasoning_details support to the openai compatible provider. We should track the interleveaned thinking boolean per model tho but that should first be done on models.dev I am going to add interleaved thinking support to our custom ai sdk provider |
I tried using the reasoning_details parameter, but it didn't work for many providers; for example, LiteLLM doesn't work, nor does VertexAI (for API kimi and minimax). Instead, I tried passing the reasoning via content, and GPT OSS magically became more competent—it was like night and day for simple local tasks. MiniMax and Kimi also had the same result; before, in their reasoning, they constantly showed "The user asked me....", whereas now, for subsequent messages, they respond to the tool. |
|
Ah okay that's a good point. Hm okay I'll do some more research and we will talk internally about this problem in a few hrs. I do see why this fix works, it does feel a bit like a hack but very thankful for you bringing this to my attention i will keep u posted |
How did you do this? I am seeing the exact same thing that you are reporting: Eg, each reasoning message starts with "The user asks me..." instead of the model continuing where it left off. |
|
Hi @rekram1-node |
|
there were 2 different interleaved thinking prs, what format does litellm expect? can u not define this in your opencode.json? we can add more mapping options but if all your models are being defined by u you should be able to specify which data to send back |
It seems that nowadays there is no standard that all providers adhere to for interleaved thinking support, so everyone implements whatever version they like, and others don't even implement it at all. That is why, in my opinion, it would be truly useful if OpenCode (and generally any LLM client) offered a certain degree of provider customization. So, in the specific case of models on LiteLLM, it seems you have to pass it using I saw merged PR #5207; could this be useful in any way for creating provider-specific plugins without messing up the configuration? |
|
We can add/expand the interleaved thinking configuration supports, but i don't think we should be converting all reasoning chunks to text parts, if there is a specific provider that requires it then maybe but so far all the providers that'd want it that way (that I've seen) will already send the reasoning chunks back as assistant messages with the ... tags. |
|
@rekram1-node |
|
Sweet |
Summary
interleaved_thinkingfield to ModelsDev Model schema to detect models with interleaved thinking capabilityinterleavedThinkingcapability to provider Model interface for internal representationWhat is Interleaved Thinking?
Interleaved thinking is a reasoning approach where large language models alternate between thinking and action/answering steps, rather than following the traditional "think-then-answer" pattern. Instead of generating a long chain of thought followed by a single response, models using interleaved thinking follow a pattern like:
Reason → Tool Call → Observe → Reason → Tool Call → ...
Key Benefits:
reasoning_detailsstructuresResearch & Sources
This implementation is based on current research and industry developments:
Technical Changes
interleaved_thinkingboolean field to detect model capabilityinterleavedThinkingboolean to Model capabilitiesApplications
This capability transforms traditional function-calling into agent-level tool use, making it particularly valuable for:
Testing
All existing tests pass, and new test coverage has been added for the interleaved thinking transformation logic. The changes maintain full backward compatibility with existing model configurations.