mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-15 17:30:13 +08:00
refactor: remove unused plugin_context parameter from _apply_sandbox_tools
This commit is contained in:
@@ -36,6 +36,7 @@ from astrbot.core.persona_error_reply import (
|
||||
from astrbot.core.platform.astr_message_event import AstrMessageEvent
|
||||
from astrbot.core.provider import Provider
|
||||
from astrbot.core.provider.entities import ProviderRequest
|
||||
from astrbot.core.provider.register import llm_tools
|
||||
from astrbot.core.skills.skill_manager import SkillManager, build_skills_prompt
|
||||
from astrbot.core.star.context import Context
|
||||
from astrbot.core.star.star_handler import star_map
|
||||
@@ -999,7 +1000,6 @@ def _apply_sandbox_tools(
|
||||
config: MainAgentBuildConfig,
|
||||
req: ProviderRequest,
|
||||
session_id: str,
|
||||
plugin_context: Context,
|
||||
) -> None:
|
||||
if req.func_tool is None:
|
||||
req.func_tool = ToolSet()
|
||||
@@ -1015,7 +1015,7 @@ def _apply_sandbox_tools(
|
||||
os.environ["SHIPYARD_ENDPOINT"] = ep
|
||||
os.environ["SHIPYARD_ACCESS_TOKEN"] = at
|
||||
|
||||
tool_mgr = plugin_context.get_llm_tool_manager()
|
||||
tool_mgr = llm_tools
|
||||
req.func_tool.add_tool(tool_mgr.get_builtin_tool(ExecuteShellTool))
|
||||
req.func_tool.add_tool(tool_mgr.get_builtin_tool(PythonTool))
|
||||
req.func_tool.add_tool(tool_mgr.get_builtin_tool(FileUploadTool))
|
||||
@@ -1364,7 +1364,7 @@ async def build_main_agent(
|
||||
_apply_llm_safety_mode(config, req)
|
||||
|
||||
if config.computer_use_runtime == "sandbox":
|
||||
_apply_sandbox_tools(config, req, req.session_id, plugin_context)
|
||||
_apply_sandbox_tools(config, req, req.session_id)
|
||||
elif config.computer_use_runtime == "local":
|
||||
_apply_local_env_tools(req, plugin_context)
|
||||
|
||||
|
||||
@@ -1501,7 +1501,7 @@ class TestApplySandboxTools:
|
||||
)
|
||||
req = ProviderRequest(prompt="Test", func_tool=None)
|
||||
|
||||
module._apply_sandbox_tools(config, req, "session-123", mock_context)
|
||||
module._apply_sandbox_tools(config, req, "session-123")
|
||||
|
||||
assert req.func_tool is not None
|
||||
assert isinstance(req.func_tool, ToolSet)
|
||||
@@ -1516,7 +1516,7 @@ class TestApplySandboxTools:
|
||||
)
|
||||
req = ProviderRequest(prompt="Test", func_tool=None)
|
||||
|
||||
module._apply_sandbox_tools(config, req, "session-123", mock_context)
|
||||
module._apply_sandbox_tools(config, req, "session-123")
|
||||
|
||||
tool_names = req.func_tool.names()
|
||||
assert "astrbot_execute_shell" in tool_names
|
||||
@@ -1534,7 +1534,7 @@ class TestApplySandboxTools:
|
||||
)
|
||||
req = ProviderRequest(prompt="Test", system_prompt="Original prompt")
|
||||
|
||||
module._apply_sandbox_tools(config, req, "session-123", mock_context)
|
||||
module._apply_sandbox_tools(config, req, "session-123")
|
||||
|
||||
assert "sandboxed environment" in req.system_prompt
|
||||
|
||||
@@ -1555,7 +1555,7 @@ class TestApplySandboxTools:
|
||||
monkeypatch.delenv("SHIPYARD_ENDPOINT", raising=False)
|
||||
monkeypatch.delenv("SHIPYARD_ACCESS_TOKEN", raising=False)
|
||||
|
||||
module._apply_sandbox_tools(config, req, "session-123", mock_context)
|
||||
module._apply_sandbox_tools(config, req, "session-123")
|
||||
|
||||
assert os.environ.get("SHIPYARD_ENDPOINT") == "https://shipyard.example.com"
|
||||
assert os.environ.get("SHIPYARD_ACCESS_TOKEN") == "test-token"
|
||||
@@ -1575,7 +1575,7 @@ class TestApplySandboxTools:
|
||||
req = ProviderRequest(prompt="Test", func_tool=None)
|
||||
|
||||
with patch("astrbot.core.astr_main_agent.logger") as mock_logger:
|
||||
module._apply_sandbox_tools(config, req, "session-123", mock_context)
|
||||
module._apply_sandbox_tools(config, req, "session-123")
|
||||
|
||||
mock_logger.error.assert_called_once()
|
||||
assert (
|
||||
@@ -1598,7 +1598,7 @@ class TestApplySandboxTools:
|
||||
req = ProviderRequest(prompt="Test", func_tool=None)
|
||||
|
||||
with patch("astrbot.core.astr_main_agent.logger") as mock_logger:
|
||||
module._apply_sandbox_tools(config, req, "session-123", mock_context)
|
||||
module._apply_sandbox_tools(config, req, "session-123")
|
||||
|
||||
mock_logger.error.assert_called_once()
|
||||
|
||||
@@ -1616,7 +1616,7 @@ class TestApplySandboxTools:
|
||||
existing_toolset.add_tool(existing_tool)
|
||||
req = ProviderRequest(prompt="Test", func_tool=existing_toolset)
|
||||
|
||||
module._apply_sandbox_tools(config, req, "session-123", mock_context)
|
||||
module._apply_sandbox_tools(config, req, "session-123")
|
||||
|
||||
assert "existing_tool" in req.func_tool.names()
|
||||
assert "astrbot_execute_shell" in req.func_tool.names()
|
||||
@@ -1631,7 +1631,7 @@ class TestApplySandboxTools:
|
||||
)
|
||||
req = ProviderRequest(prompt="Test", system_prompt="Base prompt")
|
||||
|
||||
module._apply_sandbox_tools(config, req, "session-123", mock_context)
|
||||
module._apply_sandbox_tools(config, req, "session-123")
|
||||
|
||||
assert req.system_prompt.startswith("Base prompt")
|
||||
assert "sandboxed environment" in req.system_prompt
|
||||
@@ -1646,7 +1646,7 @@ class TestApplySandboxTools:
|
||||
)
|
||||
req = ProviderRequest(prompt="Test", system_prompt=None)
|
||||
|
||||
module._apply_sandbox_tools(config, req, "session-123", mock_context)
|
||||
module._apply_sandbox_tools(config, req, "session-123")
|
||||
|
||||
assert isinstance(req.system_prompt, str)
|
||||
assert "sandboxed environment" in req.system_prompt
|
||||
|
||||
Reference in New Issue
Block a user