fix: re-apply llm tool inactivation state after plugin initialize() - #9461
Open
Foolllll-J wants to merge 1 commit into
Open
fix: re-apply llm tool inactivation state after plugin initialize()#9461Foolllll-J wants to merge 1 commit into
Foolllll-J wants to merge 1 commit into
Conversation
…o prevent tools registered via add_llm_tools() from being auto-enabled on reload (AstrBotDevs#9440)
📄 Knowledge reviewDosu skipped reviewing this PR because your organization has used its |
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The inactivation check uses only
ft.namefor matching, which could incorrectly disable tools across different plugins if they share names; consider scoping the persistence key or check to include plugin identity (e.g., module path) rather than just the tool name. - You now re-apply inactivation both before and after
initialize(), but with slightly different logic; extracting this into a shared helper that takes the current plugin metadata would reduce duplication and make the behavior easier to reason about. - Iterating over
llm_tools.func_listfor every plugin load may become inefficient as the number of tools grows; consider tracking tools per plugin (e.g., via a registry keyed bymodule_path) so you only iterate the subset relevant to the current plugin.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The inactivation check uses only `ft.name` for matching, which could incorrectly disable tools across different plugins if they share names; consider scoping the persistence key or check to include plugin identity (e.g., module path) rather than just the tool name.
- You now re-apply inactivation both before and after `initialize()`, but with slightly different logic; extracting this into a shared helper that takes the current plugin metadata would reduce duplication and make the behavior easier to reason about.
- Iterating over `llm_tools.func_list` for every plugin load may become inefficient as the number of tools grows; consider tracking tools per plugin (e.g., via a registry keyed by `module_path`) so you only iterate the subset relevant to the current plugin.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
fix: re-apply llm tool inactivation state after plugin initialize() to prevent tools registered via add_llm_tools() from being auto-enabled on reload
Background
When a plugin registers its LLM function-calling tools via
context.add_llm_tools()inside itsinitialize()method (e.g.,FunctionToolsubclass pattern), and a user disables one of those tools through the management panel, the tool's name is recorded in theinactivated_llm_toolslist in persistent storage. However, upon reloading that specific plugin (single-plugin reload), the framework's existing inactivation logic — which runs beforeinitialize()— fails to catch these tools because they haven't been added tollm_tools.func_listyet. Consequently, the newly registered tools start withactive=Trueand become re-enabled automatically, ignoring the user's previous choice.Modifications / 改动点
A new post-initialize inactivation re-application is added immediately after the
initialize()call, inside the per-plugin loading loop. It iteratesllm_tools.func_list, checks whether each tool belongs to the current plugin (_is_plugin_llm_tool), and setsft.active = Falseif the tool's name is ininactivated_llm_tools. This runs for every plugin regardless of reload type (single or full), closing the gap.astrbot/core/star/star_manager.py(+8 lines)await metadata.star_cls.initialize()(line ~1418), before theOnPluginLoadedEventtriggerScreenshots or Test Results / 运行截图或测试结果
Checklist / 检查清单
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。
🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。
Summary by Sourcery
Bug Fixes: