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 otherwiseExample
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 outputdict: Unstructured dictionaryTOutput: Instance of specified Pydantic modelNone: 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 serversExample
install_apk
Install an 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 existAgentNotInitializedError: If the agent is not initializedAgentError: If the device is not an Android device or ADB client is not initialized
get_screenshot
Capture a screenshot from the mobile device.Returns
Image.Image
Screenshot as a PIL Image object
Raises
AgentNotInitializedError: If the agent is not initializedException: If screenshot capture fails
Example
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 configurationAgentInvalidApiKeyError: Invalid Minitap API key
Next Steps
Task Request Builder
Configure tasks with the builder pattern
Agent Config Builder
Configure agent behavior

