fix: include tool_choice in ChatCompletionCache cache key (issue #7968)#7975
Open
truongsontung wants to merge 1 commit into
Open
fix: include tool_choice in ChatCompletionCache cache key (issue #7968)#7975truongsontung wants to merge 1 commit into
truongsontung wants to merge 1 commit into
Conversation
…osoft#7968) The cache key was computed from messages/tools/json_output/extra_create_args but ignored tool_choice. Two requests that differed only in tool_choice ('auto' vs 'required' vs 'none') collided on the same cache key, so a stale cached response was served for the wrong tool_choice. - Pass tool_choice into _check_cache and add it to the serialized cache-key data (normalized: Tool -> schema, else the literal string). - Add regression test test_cache_key_includes_tool_choice. Fixes microsoft#7968
Contributor
|
@truongsontung please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
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.
Summary
Fixes #7968.
ChatCompletionCache._check_cachecomputed the cache key frommessages,tools,json_output, andextra_create_args— but ignoredtool_choice. Two requests that differed only intool_choice("auto"vs"required"vs"none") therefore collided on the same cache key, and a stale cached response was served for the wrongtool_choice.Before
After
tool_choiceis now passed into_check_cacheand included in the serialized cache-key payload (normalized:Tool→.schema, otherwise the literal string).tool_choicevalues are distinct; identical requests still dedupe.Changes
python/packages/autogen-ext/src/autogen_ext/models/cache/_chat_completion_cache.py: threadtool_choicethrough_check_cacheand into the cache-key data dict.tests/models/test_chat_completion_cache.py: addtest_cache_key_includes_tool_choice(verifiesauto/required/noneproduce distinct keys, and that identicaltool_choiceis stable).Test plan
pytest tests/models/test_chat_completion_cache.py→ 26 passed, 1 skippedHappy to adjust the normalization if maintainers prefer a different scheme.