Build and run agents you can see, understand and trust.
Python agentchatbotlarge-language-modelsllmllm-agentmcpmulti-agentmulti-modalreact-agentrealtime-agentvoice-agentvoice-assistant
fix(tool): only validate external result metadata on success (#2623)
DavdGao4c0547b0c82c
diff --git a/src/agentscope/tool/_base.py b/src/agentscope/tool/_base.pyindex f0ced7b64..b0a61517c 100644--- a/src/agentscope/tool/_base.py+++ b/src/agentscope/tool/_base.py@@ -11,6 +11,7 @@ import jsonschemafrom pydantic import BaseModel+from ..message import ToolResultStatefrom ._constants import DEFAULT_DANGEROUS_FILES, DEFAULT_DANGEROUS_DIRECTORIESfrom ..permission import (PermissionContext,@@ -279,7 +280,8 @@ class ToolBase(ABC):its own result has nothing to check. Shape only, against:attr:`metadata_schema`; whether the content is any good is thecaller's judgement, not this tool's, since a user who answers- "no idea" has produced a perfectly valid result.+ "no idea" has produced a perfectly valid result. Only successful+ results are checked, since the schema describes a successful run.Raises:`jsonschema.ValidationError`:@@ -287,7 +289,10 @@ class ToolBase(ABC):caller. The reply stays parked, so the executor can fixwhat it sent and try again."""- if self.metadata_schema is not None:+ if (+ self.metadata_schema is not None+ and result.state == ToolResultState.SUCCESS+ ):jsonschema.validate(result.metadata, self.metadata_schema)async def check_read_only(diff --git a/tests/ask_user_tool_test.py b/tests/ask_user_tool_test.pyindex 89b7b9c86..1e860c619 100644--- a/tests/ask_user_tool_test.py+++ b/tests/ask_user_tool_test.py@@ -87,6 +87,16 @@ class AskUserTest(IsolatedAsyncioTestCase):).model_dump()await self.tool.check_external_result(result)+ async def test_a_failed_result_owes_no_metadata(self) -> None:+ """The schema describes a successful run, not an error."""+ result = ToolResultBlock(+ id="call-1",+ name="AskUser",+ output="Invalid AskUser input",+ state=ToolResultState.ERROR,+ )+ await self.tool.check_external_result(result)+async def test_the_schema_reaches_the_model_whole(self) -> None:"""Nested models mean $defs, which the model layers inline."""schema = self.tool.input_schema