Skip to main content
The Agent class is the primary entry point for the mobile-use SDK, responsible for managing device interaction and executing tasks.

Import

Constructor

Parameters

AgentConfig
Custom agent configuration. If not provided, default configuration is used.

Example

Methods

init

Initialize the agent by connecting to a device and starting required servers.

Parameters

str
Minitap API key for supported API-backed integrations. Can also be set via the MINITAP_API_KEY environment variable.
int
default:3
Maximum number of attempts to start servers if they fail
int
default:5
Number of retries for API calls
int
default:5
Seconds to wait between retries

Returns

bool
True if initialization succeeded, False otherwise

Example

Always check the return value of init() before running tasks. Note that init() is now an async method and must be awaited.

run_task

Execute a mobile automation task asynchronously.

Parameters

str
Natural language description of what to accomplish
type[TOutput] | str
Type of output:
  • Pydantic model class for structured output
  • String description for output format
str | AgentProfile
Agent profile to use (name or instance)
str
Optional name for the task (for logging/debugging)
TaskRequest[TOutput]
Pre-built task request (alternative to individual parameters)

Returns

str | dict | TOutput | None
Task result:
  • str: Simple text output
  • dict: Unstructured dictionary
  • TOutput: Instance of specified Pydantic model
  • None: Task failed or no output

Examples


new_task

Create a new task request builder for fluent task configuration.

Parameters

str
required
Natural language description of what to accomplish

Returns

TaskRequestBuilder[None]
TaskRequestBuilder instance for fluent configuration

Example


clean

Clean up resources, stop servers, and reset the agent state.

Parameters

bool
default:false
Set to True to clean zombie/pre-existing mobile-use servers

Example

Use force=True if you have zombie servers from previous runs:
Note that clean() is now an async method and must be awaited.

install_apk

Install an APK on the connected Android device.
This method uses ADB to install the APK on the connected Android device.

Parameters

str | Path
required
Path to the local APK file to install

Raises

  • FileNotFoundError: If the APK file does not exist
  • AgentNotInitializedError: If the agent is not initialized
  • AgentError: If the device is not an Android device or ADB client is not initialized
APK installation is only supported on Android devices. Attempting to install an APK on an iOS device will raise an AgentError.

get_screenshot

Capture a screenshot from the mobile device.
This method uses ADB (Android) or xcrun (iOS) to capture screenshots from the connected device.

Returns

Image.Image
Screenshot as a PIL Image object

Raises

  • AgentNotInitializedError: If the agent is not initialized
  • Exception: If screenshot capture fails

Example

Use get_screenshot() for debugging, monitoring, or extracting visual data from your mobile device during automation workflows.

Complete Example

Exception Handling

The Agent may raise the following exceptions:
  • AgentNotInitializedError: Agent methods called before initialization
  • DeviceNotFoundError: No device found or device disconnected
  • AgentProfileNotFoundError: Specified profile not found
  • ServerStartupError: Failed to start required servers
  • ExecutableNotFoundError: Required executable (adb, idb, xcrun) not found
  • AgentTaskRequestError: Invalid task request configuration
  • AgentInvalidApiKeyError: Invalid Minitap API key
See Exceptions for details.

Next Steps

Task Request Builder

Configure tasks with the builder pattern

Agent Config Builder

Configure agent behavior