Mobile Device Automation with LLM Agents: Architecture and On-Device Deployment
This article explains how to control mobile devices with an LLM agent: decoupling planning from execution, mapping device actions to HTTP tools, Android accessibility and screen capture, and a local on-device agent plus bridge service.
As large language models improve, text-only chat is often not enough for complex workflows. Treating the model as a “brain” that can call external tools—an agent—has become a major direction. In mobile automation and device control, a brain-plus-hands design is especially promising. This article covers agent-based mobile control: core design, the call path, and on-device local deployment.
1. Architecture: Decouple Decision from Execution
Traditional automation scripts and RPA rely on brittle rules and coordinates. Small UI changes break the script. An LLM agent changes how the system works.
The idea is: the agent thinks and plans; a separate device-bridge service sees the screen, taps, types, and reports results.
- Brain (agent): The model understands natural language and reasons. Given a user instruction, it infers intent and splits it into atomic tasks.
- Hands (device bridge): A bridge app on the device does not modify the agent core. It plugs in as a plugin or external service. It receives commands, uses OS-level capabilities to read the screen, tap, type, swipe, and screenshot, then returns results or state.
This split improves robustness and generalization. The model does not need pixel coordinates. It only needs to know there is a button labeled Settings, then issue a tap-on-text command; the bridge locates and executes it.
2. Call Path and Tool Mapping
To control a phone, the agent is given a standard tool set. The tools are wrapped HTTP client calls.
Tool definitions
On the Python side, functions are typically prefixed with device actions, for example:
device_tap(x, y)ordevice_tap_text(text): tap a coordinate or a text elementdevice_type(text): type into the focused fielddevice_swipe(start, end): swipedevice_open_app(app_name): open an appdevice_screenshot(): capture the screen
Relay
Those functions send HTTP requests to localhost:8766 by default. A relay receives the request and forwards it to the device. The relay hides network differences between the agent host and the physical device so local and remote setups share the same interface.
Example flow
User: “Open Settings, screenshot the current page, and describe it.”
The agent decomposes the task and calls tools in order:
device_open_app("设置")— the bridge starts Settings.device_screenshot()— the bridge captures the screen and returns image data or a path.- The agent uses multimodal understanding on the screenshot.
- It returns a natural-language summary to the user.
The model decides dynamically; the tools execute faithfully.
3. Device Perception on Mobile
The bridge depends on OS APIs. On Android, perception is mainly structured UI and vision.
Screen reading: AccessibilityService
The core is Android AccessibilityService. With it enabled, the app can listen to and read the current window’s UI tree, including:
- node type (button, text, input, image, and so on)
- text
- bounds
- clickable, scrollable, and similar flags
The bridge turns this into a structured node tree (for example JSON) for the agent. Without a screenshot, the agent can still see interactive elements and act precisely.
Visual capture: recording and screenshots
For nonstandard UI or games, accessibility is often not enough. MediaProjection or accessibility screenshot APIs capture the screen. Images record the run and feed multimodal models on complex pages.
Permissions
At install and init, the bridge typically needs:
- Accessibility: UI tree and simulated taps
- Overlay: status or control panel
- Screen capture/recording: live frames
- Other runtime permissions: storage, network, depending on the scenario
4. On-Device Local Deployment
Besides a cloud agent talking to the phone over the public network, a more demanding, privacy-friendly option is to run the agent on the device itself.
Environment
On a typical Android phone, a practical path is a mobile terminal emulator (for example an open-source terminal app):
- Install the terminal app.
- Set up a Linux-compatible layer and Python.
- Install agent dependencies and core packages.
- Start the agent process.
Local networking
The agent runs in the terminal process; the bridge runs at the Android system layer. They talk over 127.0.0.1 or localhost with no external traffic and lower latency.
Pairing
Connections are usually paired. In the agent chat, the user issues something like “connect to this device, pairing code XXXXXX.” The bridge app shows a dynamic code. The terminal sends the code; after verification, a long-lived connection is established. Compute and control stay on the device.
5. Summary and Outlook
Decoupling brain and hands addresses the fragility of traditional RPA. Combined with HTTP tools, accessibility, screen capture, and on-device deployment, developers can build systems that understand natural-language intent and control phones accurately.
As on-device small models improve, and as cloud containers, logging, and monitoring join in, cloud–edge agent automation can add value in automated testing, accessibility for older users, and intelligent customer support.
