Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 32 additions & 32 deletions src/askui/chat/migrations/shared/assistants/seeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@
</IMPORTANT>"""
),
tools=[
"computer_disconnect",
"computer_connect",
"computer_mouse_click",
"computer_get_mouse_position",
"computer_keyboard_pressed",
"computer_keyboard_release",
"computer_keyboard_tap",
"computer_list_displays",
"computer_mouse_hold_down",
"computer_mouse_release",
"computer_mouse_scroll",
"computer_move_mouse",
"computer_retrieve_active_display",
"computer_screenshot",
"computer_set_active_display",
"computer_type",
"disconnect",
"connect",
"mouse_click",
"get_mouse_position",
"keyboard_pressed",
"keyboard_release",
"keyboard_tap",
"list_displays",
"mouse_hold_down",
"mouse_release",
"mouse_scroll",
"move_mouse",
"retrieve_active_display",
"screenshot",
"set_active_display",
"type",
],
)

Expand Down Expand Up @@ -124,22 +124,22 @@
"""
),
tools=[
"android_screenshot_tool",
"android_tap_tool",
"android_type_tool",
"android_drag_and_drop_tool",
"android_key_event_tool",
"android_swipe_tool",
"android_key_combination_tool",
"android_shell_tool",
"android_connect_tool",
"android_get_connected_devices_serial_numbers_tool",
"android_get_connected_displays_infos_tool",
"android_get_current_connected_device_infos_tool",
"android_get_connected_device_display_infos_tool",
"android_select_device_by_serial_number_tool",
"android_select_display_by_unique_id_tool",
"android_setup_helper",
"screenshot_tool",
"tap_tool",
"type_tool",
"drag_and_drop_tool",
"key_event_tool",
"swipe_tool",
"key_combination_tool",
"shell_tool",
"connect_tool",
"get_connected_devices_serial_numbers_tool",
"get_connected_displays_infos_tool",
"get_current_connected_device_infos_tool",
"get_connected_device_display_infos_tool",
"select_device_by_serial_number_tool",
"select_display_by_unique_id_tool",
"setup_helper",
],
)

Expand Down
30 changes: 28 additions & 2 deletions src/askui/models/shared/tools.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import logging
import re
import types
import uuid
from abc import ABC, abstractmethod
from datetime import timedelta
from functools import wraps
Expand All @@ -19,7 +21,7 @@
from fastmcp.utilities.types import Image as FastMcpImage
from mcp import Tool as McpTool
from PIL import Image
from pydantic import BaseModel, Field
from pydantic import BaseModel, ConfigDict, Field, PrivateAttr
from typing_extensions import Self

from askui.models.shared.agent_message_param import (
Expand Down Expand Up @@ -161,7 +163,11 @@ def _create_tool_result_block_param_for_playwright_error(


class Tool(BaseModel, ABC):
name: str = Field(description="Name of the tool")
model_config = ConfigDict(
validate_by_alias=True,
)

base_name: str = Field(alias="name", description="Name of the tool")
description: str = Field(description="Description of what the tool does")
input_schema: InputSchema = Field(
default_factory=_default_input_schema,
Expand All @@ -171,12 +177,32 @@ class Tool(BaseModel, ABC):
description="Tags required for the tool", default=[]
)

_unique_id: str = PrivateAttr(default_factory=lambda: str(uuid.uuid4()))

@abstractmethod
def __call__(self, *args: Any, **kwargs: Any) -> ToolCallResult:
"""Executes the tool with the given arguments."""
error_msg = "Tool subclasses must implement __call__ method"
raise NotImplementedError(error_msg)

@property
def name(self) -> str:
"""Returns the unique name for this tool instance."""
name_parts = [self.base_name]
if len(self.required_tags) > 0:
name_parts.append(f"tags_{'_'.join(self.required_tags)}")
name_parts.append(self._unique_id)
name = "_".join(name_parts)
# Ensure name matches pattern ^[a-zA-Z0-9_-]$
name = re.sub(r"[^a-zA-Z0-9_-]", "_", name)
# Ensure name is not longer than 64 characters
return name[:64]

@name.setter
def name(self, value: str) -> None:
"""Sets the base name of the tool."""
self.base_name = value

def to_params(
self,
) -> BetaToolUnionParam:
Expand Down
28 changes: 14 additions & 14 deletions src/askui/tools/android/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AndroidScreenshotTool(AndroidBaseTool):

def __init__(self, agent_os: AndroidAgentOsFacade | None = None) -> None:
super().__init__(
name="android_screenshot_tool",
name="screenshot_tool",
description=(
"""
Takes a screenshot of the currently active window.
Expand Down Expand Up @@ -45,7 +45,7 @@ class AndroidTapTool(AndroidBaseTool):

def __init__(self, agent_os: AndroidAgentOsFacade | None = None) -> None:
super().__init__(
name="android_tap_tool",
name="tap_tool",
description=(
"""
Performs a tap (touch) gesture at the given (x, y) coordinates on the
Expand Down Expand Up @@ -111,7 +111,7 @@ class AndroidTypeTool(AndroidBaseTool):

def __init__(self, agent_os: AndroidAgentOsFacade | None = None) -> None:
super().__init__(
name="android_type_tool",
name="type_tool",
description=(
"""
Types the given text on the Android device screen.
Expand Down Expand Up @@ -148,7 +148,7 @@ class AndroidDragAndDropTool(AndroidBaseTool):

def __init__(self, agent_os: AndroidAgentOsFacade | None = None) -> None:
super().__init__(
name="android_drag_and_drop_tool",
name="drag_and_drop_tool",
description=(
"""
Performs a drag and drop gesture on the Android device screen.
Expand Down Expand Up @@ -201,7 +201,7 @@ def __call__(self, x1: int, y1: int, x2: int, y2: int, duration: int = 1000) ->
class AndroidKeyTapEventTool(AndroidBaseTool):
def __init__(self, agent_os: AndroidAgentOsFacade | None = None) -> None:
super().__init__(
name="android_key_event_tool",
name="key_event_tool",
description=(
"""
Performs a key press on the android device.
Expand Down Expand Up @@ -238,7 +238,7 @@ class AndroidSwipeTool(AndroidBaseTool):

def __init__(self, agent_os: AndroidAgentOsFacade | None = None) -> None:
super().__init__(
name="android_swipe_tool",
name="swipe_tool",
description=(
"""
Performs a swipe gesture on the Android device screen, similar to
Expand Down Expand Up @@ -312,7 +312,7 @@ class AndroidKeyCombinationTool(AndroidBaseTool):

def __init__(self, agent_os: AndroidAgentOsFacade | None = None) -> None:
super().__init__(
name="android_key_combination_tool",
name="key_combination_tool",
description=(
"""
Performs a combination of key presses on the Android device, similar to
Expand Down Expand Up @@ -368,7 +368,7 @@ class AndroidShellTool(AndroidBaseTool):

def __init__(self, agent_os: AndroidAgentOsFacade | None = None) -> None:
super().__init__(
name="android_shell_tool",
name="shell_tool",
description=(
"""
Executes a shell command directly on the Android device through ADB.
Expand Down Expand Up @@ -411,7 +411,7 @@ class AndroidGetConnectedDevicesSerialNumbersTool(AndroidBaseTool):

def __init__(self, agent_os: AndroidAgentOsFacade | None = None):
super().__init__(
name="android_get_connected_devices_serial_numbers_tool",
name="get_connected_devices_serial_numbers_tool",
description="Can be used to get all connected devices serial numbers.",
agent_os=agent_os,
)
Expand All @@ -429,7 +429,7 @@ class AndroidGetConnectedDisplaysInfosTool(AndroidBaseTool):

def __init__(self, agent_os: AndroidAgentOsFacade | None = None):
super().__init__(
name="android_get_connected_device_display_infos_tool",
name="get_connected_device_display_infos_tool",
description="Can be used to get all connected displays infos for the "
"current selected device.",
agent_os=agent_os,
Expand All @@ -449,7 +449,7 @@ class AndroidGetCurrentConnectedDeviceInfosTool(AndroidBaseTool):

def __init__(self, agent_os: AndroidAgentOsFacade | None = None):
super().__init__(
name="android_get_current_connected_device_infos_tool",
name="get_current_connected_device_infos_tool",
description="""
Can be used to get the current selected device and selected display infos.
""",
Expand All @@ -474,7 +474,7 @@ class AndroidSelectDeviceBySerialNumberTool(AndroidBaseTool):

def __init__(self, agent_os: AndroidAgentOsFacade | None = None):
super().__init__(
name="android_select_device_by_serial_number_tool",
name="select_device_by_serial_number_tool",
description="Can be used to select a device by its serial number.",
input_schema={
"type": "object",
Expand Down Expand Up @@ -502,7 +502,7 @@ class AndroidSelectDisplayByUniqueIDTool(AndroidBaseTool):

def __init__(self, agent_os: AndroidAgentOsFacade | None = None):
super().__init__(
name="android_select_display_by_unique_id_tool",
name="select_display_by_unique_id_tool",
description="Can be used to select a display by its unique ID.",
input_schema={
"type": "object",
Expand Down Expand Up @@ -530,7 +530,7 @@ class AndroidConnectTool(AndroidBaseTool):

def __init__(self, agent_os: AndroidAgentOsFacade | None = None):
super().__init__(
name="android_connect_tool",
name="connect_tool",
description="""Can be used to connect the adb client to the server.
Needs to select a device after connecting the adb client.
""",
Expand Down
Loading