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 Platform features (Platform tasks, cloud mobiles). Can also be set via
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 otherwiseExample
Example with API Key
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] | PlatformTaskRequest[TOutput]
Pre-built TaskRequest or PlatformTaskRequest (alternative to individual parameters)
Returns
str | dict | TOutput | None
Task result:
str: Simple text outputdict: Unstructured dictionaryTOutput: Instance of specified Pydantic modelNone: Task failed or no output
Examples
For platform tasks, the Locked App Package is configured on the platform task itself, not in
PlatformTaskRequest. For local tasks using TaskRequest, use .with_locked_app_package() in the builder.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 serversExample
install_apk
Install an APK on the connected Android device.- For local devices: Uses ADB to install the APK directly
- For cloud mobiles: Installs it on the cloud mobile via the API
Parameters
str | Path
required
Path to the local APK file to install
Raises
FileNotFoundError: If the APK file does not existAgentNotInitializedError: If the agent is not initialized (local mode)AgentError: If the device is not an Android device or ADB client is not initializedCloudMobileServiceUninitializedError: If cloud mobile service is not initialized (cloud mode)AgentTaskRequestError: If cloud mobile ID is not configured (cloud mode)
get_screenshot
Capture a screenshot from the mobile device.- For local devices: Uses ADB (Android) or xcrun (iOS) to capture screenshots directly
- For cloud mobiles: Retrieves screenshots from the cloud mobile via the Platform API
Returns
Image.Image
Screenshot as a PIL Image object
Raises
AgentNotInitializedError: If the agent is not initializedCloudMobileServiceUninitializedError: If using cloud mobile without proper initializationException: If screenshot capture fails
Example
Example with Cloud Mobile
Complete Example
Exception Handling
The Agent may raise the following exceptions:AgentNotInitializedError: Agent methods called before initializationDeviceNotFoundError: No device found or device disconnectedAgentProfileNotFoundError: Specified profile not foundServerStartupError: Failed to start required serversExecutableNotFoundError: Required executable (adb, idb, xcrun) not foundAgentTaskRequestError: Invalid task request configurationPlatformServiceUninitializedError: Platform service not initialized (missing API key)CloudMobileServiceUninitializedError: Cloud mobile service not initialized (missing API key or cloud mobile not configured)AgentInvalidApiKeyError: Invalid Minitap API key
Next Steps
Task Request Builder
Configure tasks with the builder pattern
Agent Config Builder
Configure agent behavior

