Skip to content

Commit 7886049

Browse files
refactor(tools): simplify tool names and add unique instance identifiers
1 parent 9d79373 commit 7886049

27 files changed

Lines changed: 96 additions & 72 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: 26 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,9 @@ 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(populate_by_name=True)
167+
168+
base_name: str = Field(alias="name", description="Name of the tool")
165169
description: str = Field(description="Description of what the tool does")
166170
input_schema: InputSchema = Field(
167171
default_factory=_default_input_schema,
@@ -171,12 +175,32 @@ class Tool(BaseModel, ABC):
171175
description="Tags required for the tool", default=[]
172176
)
173177

178+
_unique_id: str = PrivateAttr(default_factory=lambda: str(uuid.uuid4()))
179+
174180
@abstractmethod
175181
def __call__(self, *args: Any, **kwargs: Any) -> ToolCallResult:
176182
"""Executes the tool with the given arguments."""
177183
error_msg = "Tool subclasses must implement __call__ method"
178184
raise NotImplementedError(error_msg)
179185

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

src/askui/tools/computer/connect_tool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class ComputerConnectTool(ComputerBaseTool):
77

88
def __init__(self, agent_os: AgentOs | None = None) -> None:
99
super().__init__(
10-
name="computer_connect",
10+
name="connect",
1111
description=(
1212
"Connect to the agent OS controller to enable computer control. "
1313
"Useful for establishing an initial connection or reconnecting "

src/askui/tools/computer/disconnect_tool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class ComputerDisconnectTool(ComputerBaseTool):
77

88
def __init__(self, agent_os: AgentOs | None = None) -> None:
99
super().__init__(
10-
name="computer_disconnect",
10+
name="disconnect",
1111
description=(
1212
"Disconnect from the agent OS controller. "
1313
"Needs to be used once you are done with the task and want to stop"

src/askui/tools/computer/get_mouse_position_tool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class ComputerGetMousePositionTool(ComputerBaseTool):
77

88
def __init__(self, agent_os: ComputerAgentOsFacade | None = None) -> None:
99
super().__init__(
10-
name="computer_get_mouse_position",
10+
name="get_mouse_position",
1111
description="Get the current mouse position.",
1212
agent_os=agent_os,
1313
required_tags=[ToolTags.SCALED_AGENT_OS.value],

src/askui/tools/computer/get_system_info_tool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ComputerGetSystemInfoTool(ComputerBaseTool):
1515

1616
def __init__(self, agent_os: AgentOs | None = None) -> None:
1717
super().__init__(
18-
name="computer_get_system_info_tool",
18+
name="get_system_info_tool",
1919
description="""
2020
Get the system information.
2121
This tool returns the system information as a JSON object.

src/askui/tools/computer/keyboard_pressed_tool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class ComputerKeyboardPressedTool(ComputerBaseTool):
99

1010
def __init__(self, agent_os: AgentOs | None = None) -> None:
1111
super().__init__(
12-
name="computer_keyboard_pressed",
12+
name="keyboard_pressed",
1313
description="Press and hold a keyboard key.",
1414
input_schema={
1515
"type": "object",

src/askui/tools/computer/keyboard_release_tool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class ComputerKeyboardReleaseTool(ComputerBaseTool):
99

1010
def __init__(self, agent_os: AgentOs | None = None) -> None:
1111
super().__init__(
12-
name="computer_keyboard_release",
12+
name="keyboard_release",
1313
description="Release a keyboard key.",
1414
input_schema={
1515
"type": "object",

src/askui/tools/computer/keyboard_tap_tool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class ComputerKeyboardTapTool(ComputerBaseTool):
99

1010
def __init__(self, agent_os: AgentOs | None = None) -> None:
1111
super().__init__(
12-
name="computer_keyboard_tap",
12+
name="keyboard_tap",
1313
description="Tap (press and release) a keyboard key.",
1414
input_schema={
1515
"type": "object",

0 commit comments

Comments
 (0)