From 4abda02eb80d0d260c69a4033fcdfb2cee90027e Mon Sep 17 00:00:00 2001 From: Samir mlika <105347215+mlikasam-askui@users.noreply.github.com> Date: Thu, 8 May 2025 11:23:51 +0200 Subject: [PATCH] Fix ToolError --- src/askui/tools/anthropic/base.py | 7 ++++--- src/askui/tools/anthropic/computer.py | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/askui/tools/anthropic/base.py b/src/askui/tools/anthropic/base.py index c6c290cb..d12be51e 100644 --- a/src/askui/tools/anthropic/base.py +++ b/src/askui/tools/anthropic/base.py @@ -1,6 +1,6 @@ from abc import ABCMeta, abstractmethod from dataclasses import dataclass, fields, replace -from typing import Any +from typing import Any, Optional from anthropic.types.beta import BetaToolUnionParam @@ -74,9 +74,10 @@ class ToolError(Exception): Args: message (str): The error message. - result (ToolResult): The ToolResult that caused the error. + result (ToolResult, optional): The ToolResult that caused the error. """ - def __init__(self, message: str, result: ToolResult): + def __init__(self, message: str, result: Optional[ToolResult] = None): self.message = message self.result = result + super().__init__(self.message) diff --git a/src/askui/tools/anthropic/computer.py b/src/askui/tools/anthropic/computer.py index 6b279da7..f1a2a8a0 100644 --- a/src/askui/tools/anthropic/computer.py +++ b/src/askui/tools/anthropic/computer.py @@ -278,7 +278,7 @@ def __call__( if coordinate is not None: raise ToolError(f"coordinate is not accepted for {action}") if not isinstance(text, str): - raise ToolError(output=f"{text} must be a string") + raise ToolError(f"{text} must be a string") if action == "key": if text in KEYSYM_MAP.keys(): @@ -312,7 +312,7 @@ def __call__( return self.screenshot() if action == "cursor_position": # TODO: Implement in the future - return ToolError("cursor_position is not implemented by this agent") + raise ToolError("cursor_position is not implemented by this agent") if action == "left_click": self.controller_client.click("left") return ToolResult()