Skip to content

Commit c59b3c3

Browse files
Merge pull request #228 from askui/refactor-tool-store
refactor(tools): simplify tool names, add unique identifiers, and improve file tool capabilities
2 parents 9d79373 + bffb7d6 commit c59b3c3

37 files changed

Lines changed: 337 additions & 255 deletions

src/askui/chat/migrations/shared/assistants/seeds.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,22 @@
2424
</IMPORTANT>"""
2525
),
2626
tools=[
27-
"computer_disconnect",
28-
"computer_connect",
29-
"computer_mouse_click",
30-
"computer_get_mouse_position",
31-
"computer_keyboard_pressed",
32-
"computer_keyboard_release",
33-
"computer_keyboard_tap",
34-
"computer_list_displays",
35-
"computer_mouse_hold_down",
36-
"computer_mouse_release",
37-
"computer_mouse_scroll",
38-
"computer_move_mouse",
39-
"computer_retrieve_active_display",
40-
"computer_screenshot",
41-
"computer_set_active_display",
42-
"computer_type",
27+
"disconnect",
28+
"connect",
29+
"mouse_click",
30+
"get_mouse_position",
31+
"keyboard_pressed",
32+
"keyboard_release",
33+
"keyboard_tap",
34+
"list_displays",
35+
"mouse_hold_down",
36+
"mouse_release",
37+
"mouse_scroll",
38+
"move_mouse",
39+
"retrieve_active_display",
40+
"screenshot",
41+
"set_active_display",
42+
"type",
4343
],
4444
)
4545

@@ -124,22 +124,22 @@
124124
"""
125125
),
126126
tools=[
127-
"android_screenshot_tool",
128-
"android_tap_tool",
129-
"android_type_tool",
130-
"android_drag_and_drop_tool",
131-
"android_key_event_tool",
132-
"android_swipe_tool",
133-
"android_key_combination_tool",
134-
"android_shell_tool",
135-
"android_connect_tool",
136-
"android_get_connected_devices_serial_numbers_tool",
137-
"android_get_connected_displays_infos_tool",
138-
"android_get_current_connected_device_infos_tool",
139-
"android_get_connected_device_display_infos_tool",
140-
"android_select_device_by_serial_number_tool",
141-
"android_select_display_by_unique_id_tool",
142-
"android_setup_helper",
127+
"screenshot_tool",
128+
"tap_tool",
129+
"type_tool",
130+
"drag_and_drop_tool",
131+
"key_event_tool",
132+
"swipe_tool",
133+
"key_combination_tool",
134+
"shell_tool",
135+
"connect_tool",
136+
"get_connected_devices_serial_numbers_tool",
137+
"get_connected_displays_infos_tool",
138+
"get_current_connected_device_infos_tool",
139+
"get_connected_device_display_infos_tool",
140+
"select_device_by_serial_number_tool",
141+
"select_display_by_unique_id_tool",
142+
"setup_helper",
143143
],
144144
)
145145

src/askui/models/shared/tools.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import logging
2+
import re
23
import types
4+
import uuid
35
from abc import ABC, abstractmethod
46
from datetime import timedelta
57
from functools import wraps
@@ -19,7 +21,7 @@
1921
from fastmcp.utilities.types import Image as FastMcpImage
2022
from mcp import Tool as McpTool
2123
from PIL import Image
22-
from pydantic import BaseModel, Field
24+
from pydantic import BaseModel, ConfigDict, Field, PrivateAttr
2325
from typing_extensions import Self
2426

2527
from askui.models.shared.agent_message_param import (
@@ -161,7 +163,11 @@ def _create_tool_result_block_param_for_playwright_error(
161163

162164

163165
class Tool(BaseModel, ABC):
164-
name: str = Field(description="Name of the tool")
166+
model_config = ConfigDict(
167+
validate_by_alias=True,
168+
)
169+
170+
base_name: str = Field(alias="name", description="Name of the tool")
165171
description: str = Field(description="Description of what the tool does")
166172
input_schema: InputSchema = Field(
167173
default_factory=_default_input_schema,
@@ -171,12 +177,32 @@ class Tool(BaseModel, ABC):
171177
description="Tags required for the tool", default=[]
172178
)
173179

180+
_unique_id: str = PrivateAttr(default_factory=lambda: str(uuid.uuid4()))
181+
174182
@abstractmethod
175183
def __call__(self, *args: Any, **kwargs: Any) -> ToolCallResult:
176184
"""Executes the tool with the given arguments."""
177185
error_msg = "Tool subclasses must implement __call__ method"
178186
raise NotImplementedError(error_msg)
179187

188+
@property
189+
def name(self) -> str:
190+
"""Returns the unique name for this tool instance."""
191+
name_parts = [self.base_name]
192+
if len(self.required_tags) > 0:
193+
name_parts.append(f"tags_{'_'.join(self.required_tags)}")
194+
name_parts.append(self._unique_id)
195+
name = "_".join(name_parts)
196+
# Ensure name matches pattern ^[a-zA-Z0-9_-]$
197+
name = re.sub(r"[^a-zA-Z0-9_-]", "_", name)
198+
# Ensure name is not longer than 64 characters
199+
return name[:64]
200+
201+
@name.setter
202+
def name(self, value: str) -> None:
203+
"""Sets the base name of the tool."""
204+
self.base_name = value
205+
180206
def to_params(
181207
self,
182208
) -> BetaToolUnionParam:

src/askui/tools/android/tools.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class AndroidScreenshotTool(AndroidBaseTool):
1616

1717
def __init__(self, agent_os: AndroidAgentOsFacade | None = None) -> None:
1818
super().__init__(
19-
name="android_screenshot_tool",
19+
name="screenshot_tool",
2020
description=(
2121
"""
2222
Takes a screenshot of the currently active window.
@@ -45,7 +45,7 @@ class AndroidTapTool(AndroidBaseTool):
4545

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

112112
def __init__(self, agent_os: AndroidAgentOsFacade | None = None) -> None:
113113
super().__init__(
114-
name="android_type_tool",
114+
name="type_tool",
115115
description=(
116116
"""
117117
Types the given text on the Android device screen.
@@ -148,7 +148,7 @@ class AndroidDragAndDropTool(AndroidBaseTool):
148148

149149
def __init__(self, agent_os: AndroidAgentOsFacade | None = None) -> None:
150150
super().__init__(
151-
name="android_drag_and_drop_tool",
151+
name="drag_and_drop_tool",
152152
description=(
153153
"""
154154
Performs a drag and drop gesture on the Android device screen.
@@ -201,7 +201,7 @@ def __call__(self, x1: int, y1: int, x2: int, y2: int, duration: int = 1000) ->
201201
class AndroidKeyTapEventTool(AndroidBaseTool):
202202
def __init__(self, agent_os: AndroidAgentOsFacade | None = None) -> None:
203203
super().__init__(
204-
name="android_key_event_tool",
204+
name="key_event_tool",
205205
description=(
206206
"""
207207
Performs a key press on the android device.
@@ -238,7 +238,7 @@ class AndroidSwipeTool(AndroidBaseTool):
238238

239239
def __init__(self, agent_os: AndroidAgentOsFacade | None = None) -> None:
240240
super().__init__(
241-
name="android_swipe_tool",
241+
name="swipe_tool",
242242
description=(
243243
"""
244244
Performs a swipe gesture on the Android device screen, similar to
@@ -312,7 +312,7 @@ class AndroidKeyCombinationTool(AndroidBaseTool):
312312

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

369369
def __init__(self, agent_os: AndroidAgentOsFacade | None = None) -> None:
370370
super().__init__(
371-
name="android_shell_tool",
371+
name="shell_tool",
372372
description=(
373373
"""
374374
Executes a shell command directly on the Android device through ADB.
@@ -411,7 +411,7 @@ class AndroidGetConnectedDevicesSerialNumbersTool(AndroidBaseTool):
411411

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

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

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

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

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

531531
def __init__(self, agent_os: AndroidAgentOsFacade | None = None):
532532
super().__init__(
533-
name="android_connect_tool",
533+
name="connect_tool",
534534
description="""Can be used to connect the adb client to the server.
535535
Needs to select a device after connecting the adb client.
536536
""",

0 commit comments

Comments
 (0)