Skip to content

Build and run agents you can see, understand and trust.

fix(tool): preserve option-like glob argument values (#3004)

little-spoon776b6e9d177288
diff --git a/src/agentscope/tool/_builtin/_glob.py b/src/agentscope/tool/_builtin/_glob.py
index f58f17c5e..88cfc7c24 100644
--- a/src/agentscope/tool/_builtin/_glob.py
+++ b/src/agentscope/tool/_builtin/_glob.py
@@ -300,10 +300,8 @@ Use head_limit to cap the number of results returned.""" # ignore: E501
command = [
python,
self._glob_helper_path,
- "--pattern",
- pattern,
- "--base-dir",
- base_dir,
+ f"--pattern={pattern}",
+ f"--base-dir={base_dir}",
]
result = await self._backend.exec_shell(command, timeout=30.0)
diff --git a/tests/builtin_glob_test.py b/tests/builtin_glob_test.py
index 771d76514..656fa7294 100644
--- a/tests/builtin_glob_test.py
+++ b/tests/builtin_glob_test.py
@@ -88,6 +88,24 @@ class GlobToolTest(IsolatedAsyncioTestCase):
self.assertIn("test2.py", content)
self.assertNotIn("test.txt", content)
+ async def test_dash_prefixed_patterns(self) -> None:
+ """The helper must receive option-like patterns as literal values."""
+ for name, pattern in (
+ ("-report.txt", "-report*.txt"),
+ ("--help", "--help"),
+ ("-report=one.txt", "-report=*.txt"),
+ ):
+ with self.subTest(pattern=pattern):
+ target = os.path.join(self.temp_dir, name)
+ with open(target, "w", encoding="utf-8"):
+ pass
+ chunk = await self.glob_tool(
+ pattern=pattern,
+ path=self.temp_dir,
+ )
+ self.assertEqual(chunk.state, "running")
+ self.assertEqual(chunk.content[0].text, target)
+
async def test_recursive_pattern(self) -> None:
"""Test recursive glob pattern."""
chunk = await self.glob_tool(