|
| 1 | +from typing import Any |
| 2 | + |
| 3 | +from askui.models.shared import ComputerBaseTool |
| 4 | +from askui.models.shared.tool_tags import ToolTags |
| 5 | +from askui.tools.agent_os import AgentOs |
| 6 | +from askui.tools.agent_os_type_error import AgentOsTypeError |
| 7 | +from askui.tools.android.agent_os import AndroidAgentOs |
| 8 | +from askui.tools.askui.askui_controller import AskUiControllerClient |
| 9 | + |
| 10 | + |
| 11 | +class AskUiComputerBaseTool(ComputerBaseTool): |
| 12 | + """ |
| 13 | + Base tool for AskUI computer tools. |
| 14 | + Tools that can only operate with the AskUiControllerClient as agent_os. |
| 15 | + """ |
| 16 | + |
| 17 | + def __init__( |
| 18 | + self, |
| 19 | + agent_os: AgentOs | None = None, |
| 20 | + required_tags: list[str] | None = None, |
| 21 | + **kwargs: Any, |
| 22 | + ) -> None: |
| 23 | + super().__init__( |
| 24 | + required_tags=[ToolTags.COMPUTER.value, ToolTags.ASKUI_CONTROLLER.value] |
| 25 | + + (required_tags or []), |
| 26 | + agent_os=agent_os, |
| 27 | + **kwargs, |
| 28 | + ) |
| 29 | + |
| 30 | + @property |
| 31 | + def agent_os(self) -> AskUiControllerClient: |
| 32 | + """Get the agent OS. |
| 33 | +
|
| 34 | + Returns: |
| 35 | + AgentOs: The agent OS instance. |
| 36 | + """ |
| 37 | + agent_os = super().agent_os |
| 38 | + if not isinstance(agent_os, AskUiControllerClient): |
| 39 | + raise AgentOsTypeError( |
| 40 | + expected_type=AskUiControllerClient, |
| 41 | + actual_type=type(agent_os), |
| 42 | + ) |
| 43 | + return agent_os |
| 44 | + |
| 45 | + @agent_os.setter |
| 46 | + def agent_os(self, agent_os: AgentOs | AndroidAgentOs) -> None: |
| 47 | + """Set the agent OS facade. |
| 48 | +
|
| 49 | + Args: |
| 50 | + agent_os (AgentOs | AndroidAgentOs): The agent OS facade instance to set. |
| 51 | +
|
| 52 | + Raises: |
| 53 | + TypeError: If the agent OS is not an AgentOs instance. |
| 54 | + """ |
| 55 | + if not isinstance(agent_os, AskUiControllerClient): |
| 56 | + raise AgentOsTypeError( |
| 57 | + expected_type=AskUiControllerClient, |
| 58 | + actual_type=type(agent_os), |
| 59 | + ) |
| 60 | + self._agent_os = agent_os |
0 commit comments