Skip to content

Conversation

@lgc2333
Copy link

@lgc2333 lgc2333 commented Dec 17, 2025

Modifications / 改动点

  • This is NOT a breaking change. / 这不是一个破坏性变更。
  1. handler_module_path 统一移至 astrbot/core/star/star_manager.py 处理,以解决模块路径差异问题
  2. 通过注册一个假 handler,让使用 Context.add_llm_tools 注册的 Tool 能够展示在网页上

Screenshots or Test Results / 运行截图或测试结果

image image
image image

Checklist / 检查清单

  • 😊 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。/ If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
  • 👀 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。/ My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
  • 🤓 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到了 requirements.txtpyproject.toml 文件相应位置。/ 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.txt and pyproject.toml.
  • 😮 我的更改没有引入恶意代码。/ My changes do not introduce malicious code.

Summary by Sourcery

通过在 star manager 中集中管理 LLM 工具 handler 模块路径的赋值,并在加载时与插件元数据对齐,修复其路径处理问题。

Bug Fixes:

  • 当模块匹配时,基于插件元数据设置 handler_module_path,解决 LLM 工具 handler_module_path 值不一致的问题。

Enhancements:

  • 通过移除内联构造 handler_module_path 的逻辑并改进新增工具的日志记录,简化在上下文中注册 LLM 工具的流程。
Original summary in English

Summary by Sourcery

Fix LLM tool handler module path handling by centralizing its assignment in the star manager and aligning it with plugin metadata during load.

Bug Fixes:

  • Resolve inconsistent handler_module_path values for LLM tools by setting them based on plugin metadata when modules match.

Enhancements:

  • Simplify LLM tool registration in context by removing inline handler_module_path construction and improving logging of added tools.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你好——我已经审阅了你的改动,这里是一些反馈:

  • star_manager.load 中,建议把 elif ft.__module__ == metadata.module_path 改成单独的 if,这样对于既有 handler 属性、又依赖 metadata 派生的模块路径的工具,也能正确设置 handler_module_path
  • 相等判断 ft.__module__ == metadata.module_path 对于定义在子模块中的工具来说可能过于严格;可以考虑使用前缀或层级式检查(例如 startswith),以便把位于 metadata.module_path.* 下的工具也正确关联起来。
给 AI Agent 的提示
请根据这次代码审查中的评论进行修改:

## 总体评论
-`star_manager.load` 中,建议把 `elif ft.__module__ == metadata.module_path` 改成单独的 `if`,这样对于既有 `handler` 属性、又依赖 metadata 派生的模块路径的工具,也能正确设置 `handler_module_path`- 相等判断 `ft.__module__ == metadata.module_path` 对于定义在子模块中的工具来说可能过于严格;可以考虑使用前缀或层级式检查(例如 `startswith`),以便把位于 `metadata.module_path.*` 下的工具也正确关联起来。

Sourcery 对开源项目是免费的——如果你觉得我们的审查有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的审查。
Original comment in English

Hey there - I've reviewed your changes - here's some feedback:

  • In star_manager.load, consider changing the elif ft.__module__ == metadata.module_path to a separate if so that handler_module_path can still be set for tools that have a handler attribute but also rely on the metadata-derived module path.
  • The equality check ft.__module__ == metadata.module_path may be too strict for tools defined in submodules; consider using a prefix or hierarchical check (e.g., startswith) so that tools in metadata.module_path.* are also correctly associated.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `star_manager.load`, consider changing the `elif ft.__module__ == metadata.module_path` to a separate `if` so that `handler_module_path` can still be set for tools that have a `handler` attribute but also rely on the metadata-derived module path.
- The equality check `ft.__module__ == metadata.module_path` may be too strict for tools defined in submodules; consider using a prefix or hierarchical check (e.g., `startswith`) so that tools in `metadata.module_path.*` are also correctly associated.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@lgc2333 lgc2333 changed the title fix #4097 fix #4097 & show tools added by Context.add_llm_tools in web panel Dec 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant