Overview
Custom tools are Python functions that extend agent capabilities beyond built-in atomic actions (click, type, swipe). Use cases:- External API calls (webhooks, REST services)
- Data processing and calculations
- Database operations
- Domain-specific logic
Quick Start
Basic Example
Simple custom tool without device access:Tool Structure
All custom tools follow this format:- List only user parameters in
"parameters"(notctx) - Mobilerun passes
ctxautomatically - Access device via
ctx.driver, shared state viactx.shared_state, credentials viactx.credential_manager - Return type should be
str
Using ActionContext
Usectx to access the device and current run:
ctx:
ctx.driver-DeviceDriverfor raw device I/O (screenshot, tap, swipe, etc.)ctx.state_provider-StateProviderto fetch/parse UI statectx.ui- CurrentUIState(refreshed each step)ctx.shared_state-MobileAgentStatefor agent coordinationctx.credential_manager-CredentialManagerfor secrets
Accessing Shared State
Access agent state viactx.shared_state:
step_number- Current execution stepaction_history- List of executed actionsaction_outcomes- Success/failure per actionagent_memory- Information saved by the Manager or FastAgent during the runcustom_variables- User-provided variablesvisited_packages- Apps visitedcurrent_package_name- Current app packageplan- Current Manager plan- More in
mobilerun/agent/droid/state.py