Skip to content

[BUG] 插件开启后 Astrbot 内置注册的工具丢失 #20

@crt106

Description

@crt106

问题描述

开启 astrbot_plugin_group_chat_plus 插件之前 Agent运行时挂载的工具列表:

Image

开启插件之后的工具列表:

Image

可以看到 只包含了第三方注册的工具

主要原因: astrbot_plugin_group_chat_plus/main.py 7177 行左右

        req.prompt = plugin_prompt
        req.image_urls = plugin_image_urls

        # 🔧 修复:用插件自身保存的工具集替换框架注入的工具
        # 新版 AstrBot (>=4.14) 的 build_main_agent 会自动注入 shell/python/cron/send_message 等工具,
        # 这些工具会导致 LLM 进入工具调用循环从而卡死。
        # 旧版 AstrBot (<=4.13) 中 func_tool_manager 参数直接生效,不存在此问题。
        # 这里统一恢复为插件保存的 ToolSet(由 reply_handler 中 get_full_tool_set() 获取),
        # 确保两个版本行为一致:只保留插件注册的工具,移除框架自动注入的工具。
        plugin_tool_set = event.get_extra(PLUGIN_FUNC_TOOL)
        req.func_tool = plugin_tool_set  # 可能是 ToolSet 或 None(获取失败时)

plugin_tool_set 来自:

  func_tools_mgr = context.get_llm_tool_manager()   # → provider_manager.llm_tools
  plugin_tool_set = func_tools_mgr.get_full_tool_set()  # → ToolSet(func_list.copy())

llm_tools 是一个全局的 FunctionToolManager,它的 func_list 里存的是所有插件通过 @llm_tool 装饰器注册的工具。
create_future_task 等 cron 工具是 AstrBot 框架在 build_main_agent 里手动 add_tool 注入的,走的是另一套路径,不经过 FunctionToolManagerfunc_list,所以 get_full_tool_set() 拿不到它们,被插件的覆盖逻辑顺带剔除了

AstrBot 内置工具注册位置

所有内置工具均在 astrbot/core/astr_main_agent.pybuild_main_agent 函数中注册。也就是这些tool都可能被移除掉

注册入口(第 1141–1170 行)

_apply_kb()                                        # L1141
_apply_sandbox_tools() / _apply_local_env_tools()  # L1153–1156
_proactive_cron_job_tools()                        # L1164–1165
req.func_tool.add_tool(SEND_MESSAGE_TO_USER_TOOL)  # L1167–1170

各工具组详情

工具组 工具名 注册位置 开启条件 默认值
知识库 knowledge_base_query _apply_kb() L214–216 kb_agentic_mode = true false
Cron 定时任务 create_future_task
delete_future_task
list_future_tasks
_proactive_cron_job_tools() L924–926 provider_settings.proactive_capability.add_cron_tools = true true
主动发消息 send_message_to_user build_main_agent L1167–1170 platform_meta.support_proactive_message == true(平台层,非配置项) 多数平台为 true
本地环境 astrbot_execute_shell
astrbot_execute_python
_apply_local_env_tools() L281–282 provider_settings.computer_use_runtime = "local" "none"
沙箱基础 execute_shell
execute_python
file_upload
file_download
_apply_sandbox_tools() L862–865 provider_settings.computer_use_runtime = "sandbox" "none"
沙箱浏览器 browser_exec
browser_batch_exec
run_browser_skill
_apply_sandbox_tools() L901–903 同上,且沙箱 session capabilities 包含 "browser"
沙箱 Skill 管理 get_execution_history
annotate_execution
create/get_skill_payload
create/list/evaluate/promote_skill_candidate
list/rollback/sync_skill_release
_apply_sandbox_tools() L906–916 同上,且 sandbox.booter = "shipyard_neo"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions