fix: stabilize OpenAI tool schema order - #9798
Merged
Soulter merged 1 commit intoAug 25, 2026
Merged
Conversation
Member
|
感谢,我都不知道会有这个情况(tool加载顺序可能会不同) |
Contributor
Author
|
不客气,我是在用promptxray来观察astrbot的时候,发现命中缓存的概率非常低,排查之后发现是工具调用的时候因为没有固定工具顺序,所以每次缓存前缀都没有命中 |
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.
修改说明
ToolSet.tools原有的注册顺序不变。当工具注册顺序在不同运行中发生变化时,稳定的声明顺序可以避免兼容上游的提示词前缀产生不必要变化,也有利于上游的 Prompt Cache 复用。
验证
python -m ruff format --check astrbot/core/agent/tool.py tests/unit/test_tool_google_schema.pypython -m ruff check astrbot/core/agent/tool.py tests/unit/test_tool_google_schema.pypython -m pytest tests/unit/test_tool_google_schema.py -q