From 1df1138d04d70fb3f4e5b752dc5eef01ee20727b Mon Sep 17 00:00:00 2001 From: zenfun Date: Sat, 21 Feb 2026 01:03:19 +0800 Subject: [PATCH] feat(agent): conditionally register browser tools based on sandbox capabilities _apply_sandbox_tools now checks the booted session's capabilities before registering browser tools (BrowserExecTool, BrowserBatchExecTool, RunBrowserSkillTool). - If no session exists yet (first request), all tools are registered conservatively to avoid breaking the initial interaction - If a session exists without browser capability, browser tools are omitted, preventing CapabilityNotSupportedError from Bay - Skill lifecycle tools remain unconditionally registered --- astrbot/core/astr_main_agent.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/astrbot/core/astr_main_agent.py b/astrbot/core/astr_main_agent.py index d0054b3f6..611bdeec3 100644 --- a/astrbot/core/astr_main_agent.py +++ b/astrbot/core/astr_main_agent.py @@ -845,7 +845,6 @@ def _apply_llm_safety_mode(config: MainAgentBuildConfig, req: ProviderRequest) - def _apply_sandbox_tools( config: MainAgentBuildConfig, req: ProviderRequest, session_id: str ) -> None: - _ = session_id if req.func_tool is None: req.func_tool = ToolSet() booter = config.sandbox_cfg.get("booter", "shipyard_neo") @@ -864,9 +863,24 @@ def _apply_sandbox_tools( req.func_tool.add_tool(FILE_DOWNLOAD_TOOL) if booter == "shipyard_neo": - req.func_tool.add_tool(BROWSER_EXEC_TOOL) - req.func_tool.add_tool(BROWSER_BATCH_EXEC_TOOL) - req.func_tool.add_tool(RUN_BROWSER_SKILL_TOOL) + # Determine sandbox capabilities from an already-booted session. + # If no session exists yet (first request), capabilities is None + # and we register all tools conservatively. + from astrbot.core.computer.computer_client import session_booter + + sandbox_capabilities: list[str] | None = None + existing_booter = session_booter.get(session_id) + if existing_booter is not None: + sandbox_capabilities = getattr(existing_booter, "capabilities", None) + + # Browser tools: only register if profile supports browser + # (or if capabilities are unknown because sandbox hasn't booted yet) + if sandbox_capabilities is None or "browser" in sandbox_capabilities: + req.func_tool.add_tool(BROWSER_EXEC_TOOL) + req.func_tool.add_tool(BROWSER_BATCH_EXEC_TOOL) + req.func_tool.add_tool(RUN_BROWSER_SKILL_TOOL) + + # Neo-specific tools (always available for shipyard_neo) req.func_tool.add_tool(GET_EXECUTION_HISTORY_TOOL) req.func_tool.add_tool(ANNOTATE_EXECUTION_TOOL) req.func_tool.add_tool(CREATE_SKILL_PAYLOAD_TOOL)