fix(tool): validate return type from _invoke method to ensure ToolInv… (#12079)

Signed-off-by: -LAN- <laipz8200@outlook.com>
This commit is contained in:
-LAN- 2024-12-25 18:36:24 +08:00 committed by GitHub
parent 5d04638091
commit 7ae417b4b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -222,6 +222,12 @@ class Tool(BaseModel, ABC):
if not isinstance(result, list):
result = [result]
if not all(isinstance(message, ToolInvokeMessage) for message in result):
raise ValueError(
f"Invalid return type from {self.__class__.__name__}._invoke method. "
"Expected ToolInvokeMessage or list of ToolInvokeMessage."
)
return result
def _transform_tool_parameters_type(self, tool_parameters: Mapping[str, Any]) -> dict[str, Any]: