Skip to content

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

fix(tool): run a no-argument tool call on an empty argument payload (#3095)

XuRuuuy3046c88da7e7
diff --git a/src/agentscope/_utils/_common.py b/src/agentscope/_utils/_common.py
index 11e47424c..8b2b4456b 100644
--- a/src/agentscope/_utils/_common.py
+++ b/src/agentscope/_utils/_common.py
@@ -121,6 +121,10 @@ def _json_loads_with_repair(
`ToolJSONDecodeError`:
If the JSON string cannot be loaded into a dict.
"""
+ # Some providers stream no arguments at all for a no-argument tool call
+ if not json_str.strip():
+ return {}
+
parsed = None
error_message = "Error: Failed to parse your tool arguments."
try:
diff --git a/tests/tool_argument_repair_test.py b/tests/tool_argument_repair_test.py
index a5fea8cd0..14826e74a 100644
--- a/tests/tool_argument_repair_test.py
+++ b/tests/tool_argument_repair_test.py
@@ -114,6 +114,12 @@ class JsonLoadsWithRepairTest(unittest.TestCase):
{"count": "42", "verbse": True},
)
+ def test_empty_arguments_are_an_empty_object(self) -> None:
+ """Test that an empty argument payload is parsed as no arguments."""
+ for json_str in ["", " "]:
+ with self.subTest(json_str=json_str):
+ self.assertDictEqual(_json_loads_with_repair(json_str), {})
+
def test_reject_invalid_arguments(self) -> None:
"""Test the arguments that cannot be loaded into a valid dict."""
for json_str in ['"hello"', "[1, 2]"]: