Mobile AI Agent Architecture: Separating Decision from Execution for Automation
This article explains a mobile AI agent architecture that separates LLM-based decision-making from device-side execution. It covers the roles of the reasoning agent and Android bridge, the communication path through a relay service, atomic tool interfaces, screen perception through the accessibility node tree and screenshots, local deployment in an Android terminal environment, and practical scenarios and safeguards for automation.
1. Background: Enabling LLMs to Actually Control a Phone
Large language models are naturally good at understanding natural language, decomposing tasks, and making plans, but they have no perception or execution capabilities of their own. They cannot see which buttons are on the screen, and they cannot extend a “finger” to tap them. To deliver an experience where a user says one sentence and the phone completes the operation automatically, two fundamental problems must be solved:
- Perception: How does the agent know the current screen state, including available text, buttons, input fields, and clickable areas?
- Execution: How does the agent turn a “decision” into real taps, swipes, text input, and other operations?
A widely accepted approach is to separate decision-making from execution. The LLM handles thinking and planning, while a separate “bridge layer” running on the mobile system handles screen perception, operation execution, and result reporting. The two communicate through a clear interface protocol, with each side focusing on what it does best.
2. Core Architecture: Separation of Decision and Execution
2.1 Role Division
The overall architecture consists of two core roles:
- Agent layer: Runs LLM inference, receives user instructions, and performs task decomposition, tool selection, and result analysis. It does not directly access low-level system capabilities.
- Bridge layer: An app or service running on the Android system side. It holds system permissions such as accessibility service and screen capture permissions, and exposes a set of atomic device operation interfaces.
This separation provides three benefits:
- Decoupling: The agent can be deployed on a local device or on a cloud server. The bridge layer does not care who the caller is and only responds to requests according to the protocol.
- Clear security boundary: All sensitive system permissions are concentrated on the bridge side, making auditing and control easier. The agent can operate the device only through restricted tool interfaces.
- Testability: Each tool interface in the bridge layer can be tested independently, and the agent’s planning logic can also be validated with simulated tool calls.
2.2 Communication Path
A typical call path is as follows:
Agent (LLM decision-making)│ HTTP request (tool call)▼Relay service (listens on local port 8766 by default)│ forwards▼Mobile Bridge App (holds system permissions)│ executes operation▼Android system UI
The tools are essentially lightweight HTTP clients. Requests are sent to the local relay service and then forwarded to the phone for execution. When the agent and the phone run on the same device, they communicate directly through the local loopback address, and data does not leave the device. When the agent is deployed remotely, the relay service acts as the bridge across networks.
3. Tool Interface Design: Atomic Operation Set
The bridge layer needs to expose a set of atomic operations with appropriate granularity and clear semantics. A common interface set includes:
| Tool | Function |
|---|---|
| Open app | Launch a specified app by app name |
| Tap coordinates | Simulate a tap at a specified screen position |
| Tap text | Locate text on the screen and tap it |
| Enter text | Inject text into the focused input field |
| Swipe | Simulate a swipe or drag gesture in a direction |
| Screenshot | Capture the current screen and return it |
| Read view hierarchy | Return structured UI node information |
Several design principles are worth noting:
- Atomicity and composability: Each tool performs only one action, and complex tasks are completed by the agent combining multiple tools during reasoning.
- Semantic naming: Interface names should directly reflect the intended behavior, reducing the probability of the model selecting the wrong tool.
- Structured returns: Execution results should be returned as structured data such as JSON, rather than plain-text descriptions, so the model can understand them precisely.
4. Screen Perception: The Agent’s Eyes
4.1 UI Node Tree
Android accessibility services can parse the current interface into a structured node tree. This includes each control’s type (button, text field, list item), text content, coordinate bounds, and whether it is clickable. The bridge layer organizes this tree and returns it to the agent, enabling the agent to “read” the screen layout and know exactly where to tap and where to enter text.
Compared with relying solely on screenshots, the node tree has three major advantages:
- Precision: Coordinates come directly from system measurements without visual estimation, leading to a higher tap hit rate.
- Low cost: Structured text data is much smaller than an image, reducing transmission and inference overhead.
- Verifiability: The node tree can be compared before and after an operation to confirm whether the interface changed as expected, forming a closed operation loop.
4.2 Screen Capture Capability
Screenshots and screen recording rely on screen capture mechanisms provided by Android, such as system-level screen projection authorization (MediaProjection) or accessibility-related screenshot capabilities. After a screenshot is captured, a visual understanding model or multimodal model is usually used to analyze the image and answer questions such as “what is currently displayed on the page.”
In practice, the node tree plus screenshots form a complementary combination. The node tree answers “where the controls are and what they are,” while the screenshot answers “how the overall screen looks and whether there are visual anomalies.” Combining the two can significantly improve the agent’s accuracy in understanding the interface.
4.3 Call Sequence
A complete tool call sequence is as follows:
User: "Open Settings, take a screenshot of the current page, and describe it"↓Agent planning:1. Call the "Open app" tool with the target "Settings"2. Wait for the UI to load, then call the "Screenshot" tool3. Analyze the screenshot content4. Generate a natural-language summary and return it to the user↓Each tool call: Agent → Relay → Bridge App → execute → result returned
This loop of model decision-making and tool execution is the essence of agent automation.
5. Local On-Device Deployment
Because the agent’s core capabilities are provided in command-line form, and an installation path is officially provided for running in an Android terminal environment such as a Termux-like terminal emulator, a self-contained deployment on a single phone is entirely possible. The agent runs in the terminal environment, the bridge app runs in the Android system, and the two communicate through a local network address.
5.1 Basic Deployment Steps
- Install a terminal environment on the phone and update the base packages.
- Install the agent runtime and its dependencies according to the documentation.
- Install and open the bridge app, and grant the necessary permissions such as accessibility and screen capture.
- Start the agent and obtain the pairing code displayed by the bridge app.
- Initiate a connection in the agent conversation, for example by entering a connection command with the pairing code, to complete device binding.
5.2 Value of the Local Deployment
- Data stays on the device: All screen data and operation commands flow through the local loopback network, making privacy-sensitive scenarios such as operating a personal photo album or SMS safer.
- Controllable cost: No additional server is required, and an old phone can be repurposed as an agent execution terminal.
- Always available: It does not depend on external networks or remote services, making it suitable for scenarios such as home automation and device self-maintenance.
6. Typical Scenarios and Cautions
Typical scenarios include assisted operation for elderly users (voice converted into automated taps), app automation testing, batch repetitive operations (replying to messages one by one or organizing settings in batches), and device inspection with status screenshot reporting.
Cautions:
- Least privilege: The bridge app should request only the permissions necessary to complete its functions and avoid excessive authorization.
- Operation confirmation: For high-risk operations such as payments or deletion, it is recommended to insert a human confirmation step into the agent workflow.
- Retry and timeout: UI load timing is uncertain, so tool calls should have reasonable timeouts. After a failure, the node tree should be used to determine whether to retry or adjust the strategy.
- Audit logs: The bridge layer should record the time, target, and result of each operation to help investigate accidental operations later.
7. Conclusion
The key to mobile agent automation is a clear main line: the LLM handles decision-making, tools handle execution, and the bridge layer grounds perception and operation in reality. Through atomic tool interfaces, structured screen perception, and a clear communication protocol, an agent can “see” and “control” a real phone. A local deployment based on a terminal environment further closes the loop of this architecture on a single device, providing a low-barrier and privacy-preserving path for directions such as personal automation assistants and automated device operations. Understanding this “decision-execution” separation architecture also allows readers to transfer it to agent automation practices on other platforms.
