Build and run agents you can see, understand and trust.
Python agentchatbotlarge-language-modelsllmllm-agentmcpmulti-agentmulti-modalreact-agentrealtime-agentvoice-agentvoice-assistant
fix(tool): clarify Windows asyncio subprocess error in LocalBackend (#2837)
梁文钰ac6efacb0ebd
diff --git a/src/agentscope/tool/_builtin/_backend.py b/src/agentscope/tool/_builtin/_backend.pyindex 7cfd1bf4a..ecc2a21e7 100644--- a/src/agentscope/tool/_builtin/_backend.py+++ b/src/agentscope/tool/_builtin/_backend.py@@ -802,6 +802,13 @@ class LocalBackend(BackendBase):stderr=asyncio.subprocess.PIPE,**kwargs,)+ except NotImplementedError as exc:+ # Windows SelectorEventLoop doesn't support subprocesses.+ raise RuntimeError(+ "The current event loop doesn't support subprocesses "+ "(e.g. SelectorEventLoop on Windows), use a "+ "ProactorEventLoop instead.",+ ) from excexcept (FileNotFoundError, NotADirectoryError, OSError) as exc:# The executable could not be found or spawned. A shell would# have returned 127 ("command not found"); mirror that sodiff --git a/tests/backend_local_test.py b/tests/backend_local_test.pyindex e9e52305f..c146d1526 100644--- a/tests/backend_local_test.py+++ b/tests/backend_local_test.py@@ -18,6 +18,7 @@ import osimport sysimport tempfileimport unittest+from unittest import mockfrom unittest.async_case import IsolatedAsyncioTestCasefrom agentscope.tool import ExecResult, LocalBackend@@ -143,6 +144,16 @@ class TestLocalBackendExec(IsolatedAsyncioTestCase):self.assertEqual(result.exit_code, -1)self.assertEqual(result.stderr, b"timed out")+ async def test_unsupported_event_loop_raises_runtime_error(self) -> None:+ """Test NotImplementedError from subprocess creation is wrapped."""+ with mock.patch(+ "agentscope.tool._builtin._backend.asyncio.create_subprocess_exec",+ side_effect=NotImplementedError,+ ):+ with self.assertRaises(RuntimeError) as ctx:+ await self.backend.exec_shell([sys.executable, "-c", "pass"])+ self.assertIsInstance(ctx.exception.__cause__, NotImplementedError)+class TestLocalBackendFileIO(IsolatedAsyncioTestCase):"""Test cases for ``read_file`` / ``write_file`` round-trips."""