Skip to content

Commit

Permalink
fix(tool): validate return type from _invoke method to ensure ToolInv…
Browse files Browse the repository at this point in the history
…okeMessage

Signed-off-by: -LAN- <[email protected]>
  • Loading branch information
laipz8200 committed Dec 25, 2024
1 parent 39ace9b commit cd53434
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions api/core/tools/tool/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@ def invoke(self, user_id: str, tool_parameters: Mapping[str, Any]) -> list[ToolI
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]:
Expand Down

0 comments on commit cd53434

Please sign in to comment.