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) ctx(anActionContextinstance) is injected automatically as a keyword argument- Access device via
ctx.driver, shared state viactx.shared_state, credentials viactx.credential_manager - Use
**kwargsfor forward compatibility - Return type should be
str
Using ActionContext
Access the device and state via thectx parameter (an ActionContext instance injected automatically):
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-DroidAgentStatefor 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 actionmemory- Agent memory dictcustom_variables- User-provided variablesvisited_packages- Apps visitedcurrent_package_name- Current app packageplan- Current Manager plan- More in
droidrun/agent/droid/state.py

