Agent class is the primary entry point for the mobile-use SDK, responsible for managing device interaction and executing tasks.
Import
Constructor
Parameters
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
Maximum number of attempts to start servers if they fail
Number of retries for API calls
Seconds to wait between retries
Returns
True if initialization succeeded, False otherwiseExample
Always check the return value of
init() before running tasks.run_task
Execute a mobile automation task asynchronously.Parameters
Natural language description of what to accomplish
Type of output:
- Pydantic model class for structured output
- String description for output format
Agent profile to use (name or instance)
Optional name for the task (for logging/debugging)
Pre-built TaskRequest or PlatformTaskRequest (alternative to individual parameters)
Returns
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
Natural language description of what to accomplish
Returns
TaskRequestBuilder instance for fluent configuration
Example
clean
Clean up resources, stop servers, and reset the agent state.Parameters
Set to
True to clean zombie/pre-existing mobile-use serversExample
Use
force=True if you have zombie servers from previous runs: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, maestro, xcrun) not foundAgentTaskRequestError: Invalid task request configurationPlatformServiceUninitializedError: Platform service not initialized (missing API key)AgentInvalidApiKeyError: Invalid Minitap API key