@@ -520,6 +520,13 @@ async def _ensure_persona_and_skills(
520520 "If you need to use these capabilities, ask the user to enable Computer Use in the AstrBot WebUI -> Config."
521521 )
522522 tmgr = plugin_context .get_llm_tool_manager ()
523+ persona_tools_configured = bool (persona and persona .get ("tools" ) is not None )
524+ req ._persona_tools_configured = persona_tools_configured
525+ req ._persona_allowed_tool_names = (
526+ {str (tool_name ) for tool_name in persona .get ("tools" , [])}
527+ if persona_tools_configured
528+ else None
529+ )
523530
524531 # inject toolset in the persona
525532 if (persona and persona .get ("tools" ) is None ) or not persona :
@@ -1068,28 +1075,42 @@ def _apply_sandbox_tools(
10681075 req .func_tool = ToolSet ()
10691076 if req .system_prompt is None :
10701077 req .system_prompt = ""
1078+ allowed_tool_names = getattr (req , "_persona_allowed_tool_names" , None )
1079+ persona_tools_configured = bool (getattr (req , "_persona_tools_configured" , False ))
1080+
10711081 tool_mgr = llm_tools
1072- req .func_tool .add_tool (tool_mgr .get_builtin_tool (ExecuteShellTool ))
1073- req .func_tool .add_tool (tool_mgr .get_builtin_tool (ListSandboxesTool ))
1074- req .func_tool .add_tool (tool_mgr .get_builtin_tool (ListSandboxProvidersTool ))
1075- req .func_tool .add_tool (tool_mgr .get_builtin_tool (GetCurrentSandboxTool ))
1076- req .func_tool .add_tool (tool_mgr .get_builtin_tool (CreateSandboxTool ))
1077- req .func_tool .add_tool (tool_mgr .get_builtin_tool (SwitchSandboxTool ))
1078- req .func_tool .add_tool (tool_mgr .get_builtin_tool (KeepAliveSandboxTool ))
1079- req .func_tool .add_tool (tool_mgr .get_builtin_tool (ReleaseSandboxTool ))
1080- req .func_tool .add_tool (tool_mgr .get_builtin_tool (SetSandboxRetentionPolicyTool ))
1081- req .func_tool .add_tool (tool_mgr .get_builtin_tool (TakeoverSandboxTool ))
1082- req .func_tool .add_tool (tool_mgr .get_builtin_tool (DestroySandboxTool ))
1083- req .func_tool .add_tool (tool_mgr .get_builtin_tool (ScreenshotSandboxTool ))
1084- req .func_tool .add_tool (tool_mgr .get_builtin_tool (CopyFileBetweenSandboxesTool ))
1085- req .func_tool .add_tool (tool_mgr .get_builtin_tool (PythonTool ))
1086- req .func_tool .add_tool (tool_mgr .get_builtin_tool (FileUploadTool ))
1087- req .func_tool .add_tool (tool_mgr .get_builtin_tool (FileDownloadTool ))
1088- req .func_tool .add_tool (tool_mgr .get_builtin_tool (FileReadTool ))
1089- req .func_tool .add_tool (tool_mgr .get_builtin_tool (FileWriteTool ))
1090- req .func_tool .add_tool (tool_mgr .get_builtin_tool (FileEditTool ))
1091- req .func_tool .add_tool (tool_mgr .get_builtin_tool (GrepTool ))
1092- req .system_prompt = f"{ req .system_prompt or '' } \n { SANDBOX_MODE_PROMPT } \n "
1082+ added_tool = False
1083+
1084+ def add_sandbox_tool (tool_cls ) -> None :
1085+ nonlocal added_tool
1086+ tool = tool_mgr .get_builtin_tool (tool_cls )
1087+ if persona_tools_configured and tool .name not in allowed_tool_names :
1088+ return
1089+ req .func_tool .add_tool (tool )
1090+ added_tool = True
1091+
1092+ add_sandbox_tool (ExecuteShellTool )
1093+ add_sandbox_tool (ListSandboxesTool )
1094+ add_sandbox_tool (ListSandboxProvidersTool )
1095+ add_sandbox_tool (GetCurrentSandboxTool )
1096+ add_sandbox_tool (CreateSandboxTool )
1097+ add_sandbox_tool (SwitchSandboxTool )
1098+ add_sandbox_tool (KeepAliveSandboxTool )
1099+ add_sandbox_tool (ReleaseSandboxTool )
1100+ add_sandbox_tool (SetSandboxRetentionPolicyTool )
1101+ add_sandbox_tool (TakeoverSandboxTool )
1102+ add_sandbox_tool (DestroySandboxTool )
1103+ add_sandbox_tool (ScreenshotSandboxTool )
1104+ add_sandbox_tool (CopyFileBetweenSandboxesTool )
1105+ add_sandbox_tool (PythonTool )
1106+ add_sandbox_tool (FileUploadTool )
1107+ add_sandbox_tool (FileDownloadTool )
1108+ add_sandbox_tool (FileReadTool )
1109+ add_sandbox_tool (FileWriteTool )
1110+ add_sandbox_tool (FileEditTool )
1111+ add_sandbox_tool (GrepTool )
1112+ if added_tool :
1113+ req .system_prompt = f"{ req .system_prompt or '' } \n { SANDBOX_MODE_PROMPT } \n "
10931114
10941115
10951116def _proactive_cron_job_tools (req : ProviderRequest , plugin_context : Context ) -> None :
0 commit comments