Skip to main content
A vision-based agent that can interact with Android devices through computer vision and AI. This agent can perform various UI interactions on Android devices like tapping, typing, swiping, and more. It uses computer vision models to locate UI elements and execute actions on them. Arguments:
  • reporters list[Reporter] | None, optional - List of reporter instances for logging and reporting. If None, an empty list is used.
  • 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 tap(), 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 AndroidVisionAgent so that they can be selected using the model parameter of AndroidVisionAgent or the model parameter of its tap(), get(), act() etc. methods. Entries in the registry override entries in the default model registry.
  • model_provider str | None, optional - The model provider to use for vision tasks.
Example:

tap

Taps on the specified target. Arguments:
  • target str | Locator | Point - The target to tap on. Can be a locator, a point, or a string.
  • model ModelComposition | str | None, optional - The composition or name of the model(s) to be used for tapping on the target.
Example:

type

Types the specified text as if it were entered on a keyboard. Arguments:
  • text str - The text to be typed. Must be at least 1 character long. Only ASCII printable characters are supported. other characters will raise an error.
Example:

key_tap

Taps the specified key on the Android device. Arguments:
  • key ANDROID_KEY - The key to tap.
Example:

key_combination

Taps the specified keys on the Android device. Arguments:
  • keys list[ANDROID_KEY] - The keys to tap.
  • duration_in_ms int, optional - The duration in milliseconds to hold the key combination. Default is 100ms.
Example:

shell

Executes a shell command on the Android device. Arguments:
  • command str - The shell command to execute.
Example:

drag_and_drop

Drags and drops the specified target. Arguments:
  • x1 int - The x-coordinate of the starting point.
  • y1 int - The y-coordinate of the starting point.
  • x2 int - The x-coordinate of the ending point.
  • y2 int - The y-coordinate of the ending point.
  • duration_in_ms int, optional - The duration in milliseconds to hold the drag and drop. Default is 1000ms.
Example:

swipe

Swipes the specified target. Arguments:
  • x1 int - The x-coordinate of the starting point.
  • y1 int - The y-coordinate of the starting point.
  • x2 int - The x-coordinate of the ending point.
  • y2 int - The y-coordinate of the ending point.
  • duration_in_ms int, optional - The duration in milliseconds to hold the swipe. Default is 1000ms.
Example:

set_device_by_serial_number

Sets the active device for screen interactions by name. Arguments:
  • device_sn str - The serial number of the device to set as active.
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 AndroidVisionAgent:
    Example Using AndroidVisionAgent:
    Example Using AndroidVisionAgent 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: