fix: handle empty tools list in OpenAILegacy provider#1352
Open
li-xiu-qi wants to merge 1 commit intoMoonshotAI:mainfrom
Open
fix: handle empty tools list in OpenAILegacy provider#1352li-xiu-qi wants to merge 1 commit intoMoonshotAI:mainfrom
li-xiu-qi wants to merge 1 commit intoMoonshotAI:mainfrom
Conversation
This was referenced Mar 6, 2026
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.
Some OpenAI-compatible APIs (like DashScope/Aliyun) reject requests with empty tools list.
This fix only includes the 'tools' parameter when tools are actually present.
Related Issue
N/A - This is a minor bug fix (15 lines of code) that addresses an API compatibility issue.
Description
Problem
When
kosong.step()is called withEmptyToolset()(e.g., during context compaction), theOpenAILegacyprovider sends an empty tools list to the API. Some OpenAI-compatible APIs (like DashScope/Aliyun) strictly validate the request and reject empty tools lists with error:This prevents context compaction from working when using these APIs.
Solution
Modified
OpenAILegacy.generate()to only include thetoolsparameter in the API request when tools are actually present (non-empty). The fix builds request kwargs dynamically:model,messages,stream, generation kwargstools(only if non-empty),stream_options(only if streaming),reasoning_effort(only if set)Changes
packages/kosong/src/kosong/contrib/chat_provider/openai_legacy.py: Modifiedgenerate()method to conditionally includetoolsparameterTesting
Checklist
make gen-changelogto update the changelog.make gen-docsto update the user documentation.Notes for Reviewers
This is a minimal, backward-compatible fix that only affects request building logic in the OpenAILegacy provider. The change ensures compatibility with stricter OpenAI-compatible APIs while maintaining existing behavior for all other use cases.