Build and run agents you can see, understand and trust.
Python agentchatbotlarge-language-modelsllmllm-agentmcpmulti-agentmulti-modalreact-agentrealtime-agentvoice-agentvoice-assistant
fix(tool): hide bash subprocess windows on Windows (#1717)
Yufeng He0e0050537eab
diff --git a/src/agentscope/tool/_builtin/_bash.py b/src/agentscope/tool/_builtin/_bash.pyindex 0c129d28e..fc058a20f 100644--- a/src/agentscope/tool/_builtin/_bash.py+++ b/src/agentscope/tool/_builtin/_bash.py@@ -22,6 +22,22 @@ from ...message import TextBlockfrom .._response import ToolChunk+def _subprocess_creation_kwargs() -> dict[str, Any]:+ """Return platform-specific subprocess creation options."""+ if os.name != "nt":+ return {}++ import subprocess++ return {+ "creationflags": getattr(+ subprocess,+ "CREATE_NO_WINDOW",+ 0x08000000,+ ),+ }++class Bash(ToolBase):"""The bash tool."""@@ -604,6 +620,7 @@ easier to review tool calls and give permission.command,stdout=asyncio.subprocess.PIPE,stderr=asyncio.subprocess.PIPE,+ **_subprocess_creation_kwargs(),)# Wait for completion with timeoutdiff --git a/tests/builtin_bash_test.py b/tests/builtin_bash_test.pyindex 4091252c5..fd8b2110d 100644--- a/tests/builtin_bash_test.py+++ b/tests/builtin_bash_test.py@@ -3,8 +3,10 @@import sysimport unittestfrom unittest.async_case import IsolatedAsyncioTestCase+from unittest.mock import patchfrom agentscope.tool import ToolChunk, Bash+from agentscope.tool._builtin._bash import _subprocess_creation_kwargsfrom agentscope.permission import (PermissionContext,PermissionBehavior,@@ -13,6 +15,23 @@ from agentscope.permission import (from agentscope.message import TextBlock+class BashSubprocessKwargsTest(unittest.TestCase):+ """Test platform-specific subprocess kwargs."""++ def test_non_windows_subprocess_kwargs_are_empty(self) -> None:+ """On non-Windows the helper returns no extra subprocess kwargs."""+ with patch("agentscope.tool._builtin._bash.os.name", "posix"):+ self.assertEqual(_subprocess_creation_kwargs(), {})++ def test_windows_subprocess_kwargs_hide_console(self) -> None:+ """On Windows the helper sets ``creationflags`` to hide the console."""+ with patch("agentscope.tool._builtin._bash.os.name", "nt"):+ self.assertEqual(+ _subprocess_creation_kwargs(),+ {"creationflags": 0x08000000},+ )++@unittest.skipIf(sys.platform == "win32","Bash tool is not supported on Windows",