01 Context & Constraints
Cloud-based agents controlling mobile devices fail in the real world for three fundamental reasons: network jitter on cellular connections destroys tactile feedback loops, transmitting real-time screen captures off-device violates basic personal privacy, and commercial API latency (typically 800ms–2400ms per step) makes typing and scrolling feel broken.
In this project, we built a fully autonomous, zero-cloud agent loop executing entirely on-device. An open-weight quantized model running via llama.cpp in Termux translates user intent directly into low-level Android kernel input events via an ADB Unix domain socket.
02 Agent Architecture
The system is organized into a four-stage cyclic pipeline designed to eliminate IPC overhead between perception and execution:
03 ADB Touch Transport
Standard adb shell input tap x y launches a new zygote JVM process for every invocation, taking 320ms–540ms per touch event. To achieve interactive speeds, the daemon communicates directly with the kernel via native binary events:
04 Local Inference Benchmarks
Testing on a Snapdragon 8+ Gen 1 platform using llama-bench with OpenCL shader backend:
05 Execution Logs & Perception
Real-time execution log from the agent control loop executing a multi-step navigation flow:
06 Device Benchmark Matrix
Measured performance across physical test devices under thermal equilibrium:
| Hardware Platform | Kernel / OS | Prompt Proc | Generation | Peak Memory | Status |
|---|---|---|---|---|---|
| Snapdragon 8+ Gen 1 (Nothing Phone 2) | Linux 5.10 / Android 14 | 17.4 tok/s | 6.8 tok/s | 1,840 MB | PASS |
| Tensor G3 (Pixel 8) | Linux 5.15 / Android 14 | 14.1 tok/s | 5.2 tok/s | 1,910 MB | PASS |
| Dimensity 9200+ | Linux 5.15 / Android 14 | 16.8 tok/s | 6.1 tok/s | 1,870 MB | PASS |
| Snapdragon 865 (Legacy Pixel 4 XL) | Linux 4.19 / Android 13 | 8.2 tok/s | 3.1 tok/s | 1,820 MB | OOM RISK |
07 Failure Modes & Race Conditions
Through 300 automated execution trials, we identified two severe failure modes:
- Soft Keyboard Occlusion: When an input field gains focus, the soft keyboard animates upward over 250ms. If the agent emits an immediate subsequent tap on a target coordinate calculated prior to the animation, the tap hits the keyboard rather than the intended submit button.
- Accessibility Node Cache Staleness: Android's
uiautomatorfrequently returns cached accessibility node bounds for dynamically populated RecyclerView items, causing the agent to attempt taps on off-screen views.
The Android window manager does not broadcast an atomic completion event for soft keyboard transitions to unprivileged shell sessions. The agent must verify window metrics after any input event before issuing coordinates.
08 Lessons & Architecture Decisions
To eliminate these race conditions without adding artificial sleep delays:
- We implemented a heuristic bounding-box validator that clips all proposed target coordinates against the active display minus the current IME (Input Method Editor) frame height.
- We replaced full UI hierarchy XML dumps with an incremental binary diffing algorithm running in C, reducing perception extraction time from 420ms down to 38ms.
09 Source Code & Reproduction
The entire daemon and quantized models are available in the repository below. Ensure you enable Developer Options and grant USB debugging (Security settings) for simulated input permission.
Inspect Repository axe01010/android-ai-agent ↗