Agent class is the primary entry point for the SDK. It coordinates all components required for mobile automation.
Responsibilities
Device Management
Initializes and manages connections to Android/iOS devices
Server Lifecycle
Starts and stops the Device Controller server
Task Execution
Creates and executes automation tasks
Resource Cleanup
Handles proper cleanup and resource release
Basic Usage
Creating an Agent
- Platform (Recommended)
- Local Development
With the platform, simply create an agent - no configuration needed:All profiles and task configurations are managed on platform.mobile-use.ai.
Agent Lifecycle
Configuration Options
The agent can be configured using theAgentConfigBuilder:
Initialization Options
Theinit() method accepts several parameters for robust initialization:
Device Selection
By default, the agent connects to the first available device. You can specify a device explicitly:Server Configuration
The agent manages the Device Controller server which handles all device interactions:Device Controller Server
Device Controller Server
Executes device actions and captures screen state using native platform tools:
- Android: Uses ADB (Android Debug Bridge) with UIAutomator2 for UI automation
- iOS: Uses IDB (iOS Development Bridge) for simulator and device control
- Screenshots and UI hierarchy capture
- Tap, swipe, scroll gestures
- App launching and navigation
- Key press events and text input
Complete Example
- Platform
- Local
Best Practices
Always use try-finally
Always use try-finally
Ensure
agent.clean() is called even if errors occurHandle initialization failures
Handle initialization failures
Check the return value of
init()Use context managers
Use context managers
Consider wrapping in a context manager for automatic cleanup

