Skip to main content
A vision-based agent that can interact with user interfaces through computer vision and AI. This agent can perform various UI interactions like clicking, typing, scrolling, and more. It uses computer vision models to locate UI elements and execute actions on them. Arguments:
  • display int, optional - The display number to use for screen interactions. Defaults to 1.
  • reporters list[Reporter] | None, optional - List of reporter instances for logging and reporting. If None, an empty list is used.
  • tools AgentToolbox | None, optional - Custom toolbox instance. If None, a default one will be created with AskUiControllerClient.
  • model ModelChoice | ModelComposition | str | None, optional - The default choice or name of the model(s) to be used for vision tasks. Can be overridden by the model parameter in the click(), get(), act() etc. methods.
  • retry Retry, optional - The retry instance to use for retrying failed actions. Defaults to ConfigurableRetry with exponential backoff. Currently only supported for locate() method.
  • models ModelRegistry | None, optional - A registry of models to make available to the VisionAgent so that they can be selected using the model parameter of VisionAgent or the model parameter of its click(), get(), act() etc. methods. Entries in the registry override entries in the default model registry.
Example:

click

Simulates a mouse click on the user interface element identified by the provided locator. Arguments:
  • locator str | Locator | Point | None, optional - UI element description, structured locator, or absolute coordinates (x, y). If None, clicks at current position.
  • button ‘left’ | ‘middle’ | ‘right’, optional - Specifies which mouse button to click. Defaults to 'left'.
  • repeat int, optional - The number of times to click. Must be greater than 0. Defaults to 1.
  • offset Point | None, optional - Pixel offset (x, y) from the target location. Positive x=right, negative x=left, positive y=down, negative y=up.
  • model ModelComposition | str | None, optional - The composition or name of the model(s) to be used for locating the element to click on using the locator.
Example:

mouse_move

Moves the mouse cursor to the UI element identified by the provided locator. Arguments:
  • locator str | Locator | Point - UI element description, structured locator, or absolute coordinates (x, y).
  • offset Point | None, optional - Pixel offset (x, y) from the target location. Positive x=right, negative x=left, positive y=down, negative y=up.
  • model ModelComposition | str | None, optional - The composition or name of the model(s) to be used for locating the element to move the mouse to using the locator.
Example:

mouse_scroll

Simulates scrolling the mouse wheel by the specified horizontal and vertical amounts. Arguments:
  • x int - The horizontal scroll amount. Positive values typically scroll right, negative values scroll left.
  • y int - The vertical scroll amount. Positive values typically scroll down, negative values scroll up.
Notes: The actual scroll direction depends on the operating system’s configuration. Some systems may have “natural scrolling” enabled, which reverses the traditional direction. The meaning of scroll units varies across operating systems and applications. A scroll value of 10 might result in different distances depending on the application and system settings. Example:

type

Types the specified text as if it were entered on a keyboard. If locator is provided, it will first click on the element to give it focus before typing. If clear is True (default), it will triple click on the element to select the current text (in multi-line inputs like textareas the current line or paragraph) before typing. IMPORTANT: clear only works if a locator is provided. Arguments:
  • text str - The text to be typed. Must be at least 1 character long.
  • locator str | Locator | Point | None, optional - UI element description, structured locator, or absolute coordinates (x, y). If None, types at current focus.
  • offset Point | None, optional - Pixel offset (x, y) from the target location. Positive x=right, negative x=left, positive y=down, negative y=up.
  • model ModelComposition | str | None, optional - The composition or name of the model(s) to be used for locating the element, i.e., input field, to type into using the locator.
  • clear bool, optional - Whether to triple click on the element to give it focus and select the current text before typing. Defaults to True.
Example:

key_up

Simulates the release of a key. Arguments:
  • key PcKey | ModifierKey - The key to be released.
Example:

key_down

Simulates the pressing of a key. Arguments:
  • key PcKey | ModifierKey - The key to be pressed.
Example:

mouse_up

Simulates the release of a mouse button. Arguments:
  • button ‘left’ | ‘middle’ | ‘right’, optional - The mouse button to be released. Defaults to 'left'.
Example:

mouse_down

Simulates the pressing of a mouse button. Arguments:
  • button ‘left’ | ‘middle’ | ‘right’, optional - The mouse button to be pressed. Defaults to 'left'.
Example:

keyboard

Simulates pressing (and releasing) a key or key combination on the keyboard. Arguments:
  • key PcKey | ModifierKey - The main key to press. This can be a letter, number, special character, or function key.
  • modifier_keys list[ModifierKey] | None, optional - List of modifier keys to press along with the main key. Common modifier keys include 'ctrl', 'alt', 'shift'.
  • repeat int, optional - The number of times to press (and release) the key. Must be greater than 0. Defaults to 1.
Example:

cli

Executes a command on the command line interface. This method allows running shell commands directly from the agent. The command is split on spaces and executed as a subprocess. Arguments:
  • command str - The command to execute on the command line.
Example:

act

Instructs the agent to achieve a specified goal through autonomous actions. The agent will analyze the screen, determine necessary steps, and perform actions to accomplish the goal. This may include clicking, typing, scrolling, and other interface interactions. Arguments:
  • goal str | list[MessageParam] - A description of what the agent should achieve.
  • model str | None, optional - The composition or name of the model(s) to be used for achieving the goal.
  • on_message OnMessageCb | None, optional - Callback for new messages. If it returns None, stops and does not add the message.
  • tools list[Tool] | ToolCollection | None, optional - The tools for the agent. Defaults to default tools depending on the selected model.
  • settings AgentSettings | None, optional - The settings for the agent. Defaults to a default settings depending on the selected model.
Returns: None Raises:
  • MaxTokensExceededError - If the model reaches the maximum token limit defined in the agent settings.
  • ModelRefusalError - If the model refuses to process the request.
Example:

get

Retrieves information from an image or PDF based on the provided query. If no source is provided, a screenshot of the current screen is taken. Arguments:
  • query str - The query describing what information to retrieve.
  • source InputSource | None, optional - The source to extract information from. Can be a path to an image, PDF, or office document file, a PIL Image object or a data URL. Defaults to a screenshot of the current screen.
  • response_schema Type[ResponseSchema] | None, optional - A Pydantic model class that defines the response schema. If not provided, returns a string.
  • model str | None, optional - The composition or name of the model(s) to be used for retrieving information from the screen or image using the query. Note: response_schema is not supported by all models. PDF processing is only supported for Gemini models hosted on AskUI.
Returns: ResponseSchema | str: The extracted information, str if no response_schema is provided. Raises:
  • NotImplementedError - If PDF processing is not supported for the selected model.
  • ValueError - If the source is not a valid PDF or image.
Example:

locate

Locates the first matching UI element identified by the provided locator. Arguments:
  • locator str | Locator - The identifier or description of the element to locate.
  • screenshot InputSource | None, optional - The screenshot to use for locating the element. Can be a path to an image file, a PIL Image object or a data URL. If None, takes a screenshot of the currently selected display.
  • model ModelComposition | str | None, optional - The composition or name of the model(s) to be used for locating the element using the locator.
Returns:
  • Point - The coordinates of the element as a tuple (x, y).
Example:

locate_all

Locates all matching UI elements identified by the provided locator. Note: Some LocateModels can only locate a single element. In this case, the returned list will have a length of 1. Arguments:
  • locator str | Locator - The identifier or description of the element to locate.
  • screenshot InputSource | None, optional - The screenshot to use for locating the element. Can be a path to an image file, a PIL Image object or a data URL. If None, takes a screenshot of the currently selected display.
  • model ModelComposition | str | None, optional - The composition or name of the model(s) to be used for locating the element using the locator.
Returns:
  • PointList - The coordinates of the elements as a list of tuples (x, y).
Example:

locate_all_elements

Locate all elements in the current screen using AskUI Models. Arguments:
  • screenshot InputSource | None, optional - The screenshot to use for locating the elements. Can be a path to an image file, a PIL Image object or a data URL. If None, takes a screenshot of the currently selected display.
  • model ModelComposition | None, optional - The model composition to be used for locating the elements.
Returns:
  • list[DetectedElement] - A list of detected elements
Example:

annotate

Annotate the screenshot with the detected elements. Creates an interactive HTML file with the detected elements and saves it to the annotation directory. The HTML file can be opened in a browser to see the annotated image. The user can hover over the elements to see their names and text value and click on the box to copy the text value to the clipboard. Arguments:
  • screenshot ImageSource | None, optional - The screenshot to annotate. If None, takes a screenshot of the currently selected display.
  • annotation_dir str - The directory to save the annotated image. Defaults to “annotations”.
  • model ModelComposition | None, optional - The composition of the model(s) to be used for annotating the image. If None, uses the default model. Example Using VisionAgent:
    Example Using AndroidVisionAgent:
    Example Using VisionAgent with custom screenshot and annotation directory:

wait

Pauses execution or waits until a UI element appears or disappears. Arguments:
  • until float | str | Locator - If a float, pauses execution for the specified number of seconds (must be greater than 0.0). If a string or Locator, waits until the specified UI element appears or disappears on screen.
  • retry_count int | None - Number of retries when waiting for a UI element. Defaults to 3 if None.
  • delay int | None - Sleep duration in seconds between retries when waiting for a UI element. Defaults to 1 second if None.
  • until_condition Literal[“appear”, “disappear”] - The condition to wait until the element satisfies. Defaults to “appear”.
  • model ModelComposition | str | None, optional - The composition or name of the model(s) to be used for locating the element using the until locator.
Raises:
  • WaitUntilError - If the UI element is not found after all retries.
Example: