Agent-Driven Mobile Automation Architecture: Separating LLM Decision-Making from Device Execution
Mobile UI automation faces a structural mismatch: large language models excel at understanding goals, planning steps, and revising plans from feedback, but cannot directly touch system interfaces; operating systems can read widget trees, inject taps, and capture screens, but lack cross-step task reasoning. This article presents a two-layer architecture—“the agent decides, the bridge layer perceives and executes”—covering the problem it solves, the overall design, the call chain, screen reading via accessibility services, tap/input/capture handling, timing and state management, deployment topologies, and security boundaries. It is implementation-agnostic and offers practical guidance for building stable, auditable, and permission-minimized mobile automation.
Mobile automation has long suffered from a structural contradiction: large language models are good at understanding goals, breaking them into steps, and revising plans based on feedback—but they cannot directly interact with system interfaces. Operating systems can read widget trees, inject taps, and capture the screen, but they have no cross-step task reasoning. Connecting the two through a clean boundary—rather than embedding a model inside system services or hard-coding tap logic into scripts—is currently the most reliable engineering approach. This article abstracts that solution as “the agent handles decision-making; the bridge layer handles perception and execution,” and discusses its principles, deployment, and governance, independent of any specific product.
1. The Problem to Solve
Typical tasks are rarely a single tap. They look more like “open an app, find the entry point, fill in content, verify the result, roll back on failure.” Pure scripts that rely on coordinates or fixed widget identifiers break the moment the UI changes; pure conversational models can only output text suggestions and cannot verify whether the screen actually changed. A workable architecture must satisfy four requirements:
- Decision and execution are separated; the model holds no system permissions directly.
- Perception results are structured: the model sees widget trees, text, and necessary screenshots—not unbounded raw byte streams.
- Every action is traceable, including call parameters, return status, and latency.
- Permissions are minimized: screen reading, screen capture, overlay layers, and network communication can each be disabled independently.
We therefore recommend two layers: a planning layer running in a controlled compute environment that emits intents only through tool interfaces, and a bridge layer running on the device that translates intents into system-permitted UI actions and returns the results.
2. Overall Architecture
2.1 Responsibility Split
The planning layer maintains the conversation, task state, and tool selection. Based on the user’s goal, it generates the next action—open an app, tap a piece of text, input content, scroll a list, or request a screenshot. It does not compute tap coordinates, nor does it cache sensitive UI data long-term.
The bridge layer is a controlled executor on the device. It relies on system-provided accessibility capabilities to read the node tree of the current window, on screen-capture capabilities to obtain the display, and—only with explicit user authorization—performs taps, text input, and swipes. The bridge layer should reject requests from unpaired sources and enforce per-session timeouts.
The two communicate through a relay over a local or restricted network. The relay only does authentication, forwarding, and logging; it carries no business logic. This means the planning layer can run in a terminal environment on the phone itself or on a compute node within the same network, while the device side remains the only component that can touch the UI.
2.2 Why Not Modify the Model Runtime
Exposing device capabilities as pluggable tools—rather than modifying the model core—has three benefits. First, model upgrades are decoupled from the system permission model, shrinking the kernel attack surface. Second, the same planning layer can attach to emulators, physical devices, or remote devices with a stable tool contract. Third, audit points concentrate at the tool boundary: every screen read and every tap is logged, making it easy to review misoperations.
3. The Call Chain
One complete loop can be summarized as: the user’s goal enters the planning layer, which selects a tool; the tool client sends the request to the local relay; the relay validates pairing state and forwards to the device-side service; the service invokes system capabilities and returns a structured result; the planning layer then decides to continue, retry, or finish.
The illustrative tool contract need not bind to any concrete implementation—only the semantics need to be stable:
observe() -> node summary of the current window, plus an optional screenshot referenceopen_app(name) -> attempt to bring the target app to the foregroundtap(target) -> tap by text, resource identifier, or regioninput_text(value) -> write text into the focused input fieldswipe(direction) -> scroll within a scrollable areacapture() -> return the screen for supplementary visual understanding
These names describe responsibilities only; they are not the formal interface of any product. Implementations should use whitelisted parameters, length limits, and timeouts, and must never pass arbitrary shell commands or arbitrary intents through to the system.
The key principle for the planning layer is not “plan every step at once” but short-horizon planning: submit one verifiable action per step and update state from observations. For example, for “open system settings and summarize the current page,” a sound decomposition is: switch to the target app, read the node tree, optionally capture a screenshot, then summarize with text. If opening fails, return a clear error code—do not let the model guess coordinates and tap blindly.
4. Screen Reading: From UI to a Reasonable Structure
Android’s accessibility service, once explicitly enabled by the user, can retrieve node information for the current window, typically including text, content description, class name, clickability, editability, bounding rectangle, and parent-child relationships. The bridge layer should not push the entire raw tree to the model; it should prune it:
- Remove invisible, out-of-bounds, and duplicate nodes.
- Generate stable short identifiers for actionable nodes so the model does not depend on volatile coordinates.
- Cap the number of nodes and text length returned per call.
- Mask or withhold text from password fields, payment pages, and verification-code areas by default.
Node trees suit precise operations; screenshots suit understanding image-based buttons, custom drawing, and information missing from the tree. The two should complement, not replace, each other. By default, prefer structured nodes for taps and input; request the screen only when the tree is insufficient, and keep the image for as short a time as possible.
5. Taps, Input, and Screen Capture
Tapping should locate targets first by visible text or content description, then by node identifier, and only then by region. Coordinate-based taps are a last resort, and the target must be re-verified as still on screen before execution, to avoid mis-taps after a list scrolls.
Input must distinguish “focus an existing input field” from “clear and rewrite.” For verification codes, passwords, and payment credentials, require human confirmation—never make auto-fill the default path. Swipes need a maximum step count to prevent the model from scrolling forever in an empty list.
Screen capture typically depends on user-authorized screen projection or the system’s accessibility screenshot capability. Authorization must be revocable; captured results stay in session memory by default and are deleted when the task ends. If an overlay layer is used to display an “automation in progress” status, keep it visible—users should always know when their device is being operated.
Documentation and implementations should explicitly list required permissions: accessibility, overlay windows, screen capture, and the necessary runtime permissions. If any one is missing, the bridge layer should return an understandable failure reason, not a silent empty result.
6. Timing and the State Machine
Reliable timing is not “assume success once the tap is sent”; it is a three-phase request–execute–observe cycle.
- The planning layer issues an action request with an idempotency identifier.
- Before execution, the device side verifies that the foreground app and target node still match.
- After execution, wait for the UI to stabilize, then return the new node summary or a diff.
- On timeout, node disappearance, or a permission dialog, return a failure type; the planning layer decides to retry, change course, or hand back to a human.
Pairing should use short-lived verification codes with rate-limited attempts. On the same device, the terminal environment and the bridge app can communicate over the loopback address so traffic never leaves the device; across devices, an authenticated channel is mandatory, binding device identity to the session. The relay must never accept tap requests from arbitrary unpaired sources.
7. Deployment Topologies
7.1 On-Device
The planning layer runs in a terminal environment on the device itself; the bridge app runs at the system level; the two communicate via a local address. The advantages are that data never leaves the device and latency is low—well suited to personal debugging and offline tasks. Note that the terminal process and the bridge process have different lifecycles: screen locks, power-saving policies, and background restrictions can all interrupt the service. Use a foreground service or an explicit keep-alive prompt, never covert persistence.
7.2 Split Compute Node and Device
The planning layer runs on an intranet compute node while the device keeps only the bridge and relay. This suits scenarios requiring larger context or unified scheduling across multiple test devices. In this setup you must isolate the network, log sources, restrict the list of actionable apps, and never leave production-account sessions attached to automation devices long-term.
In either topology, treat pairing codes, session tokens, and screenshots as sensitive data: encrypt in transit, encrypt at rest or avoid persisting to disk entirely, and rotate regularly.
8. Stability and Security Boundaries
UI automation is inherently fragile, so governance should focus on recoverability:
- Define a success condition for each action, such as target text appearing or the foreground package name changing.
- Set a global step limit and per-step timeout to prevent infinite loops.
- Model system permission dialogs separately—never let the model blindly tap “Allow” on an unknown dialog.
- Log tool traces for review, but redact accounts, verification codes, and message content from logs.
- Provide a one-tap stop that immediately disconnects the relay and revokes the current screen capture.
These capabilities are legitimate for efficiency automation on your own devices or controlled testing. Using them on unauthorized devices, for covert monitoring, or to bypass others’ informed consent falls outside the bounds of legitimate engineering. Design defaults should be explicit notification, always-disableable, and least privilege.
9. Practical Advice for Getting Started
Start with read-only observation and confirm that node summaries are sufficient to support decisions before enabling taps and input. Start with short, single-app tasks before extending to cross-app flows. Collect failure samples as “UI state → action → result” records and use them to improve prompts and tool parameters rather than endlessly increasing model freedom. If you later add cloud-based task orchestration, logging, and monitoring, keep them at the level of generic capabilities: the task queue delivers tasks, the log service preserves the audit trail, and the alerting service notifies a human on repeated failures or permission interruptions. An agent can accelerate operations—but permissions, the stop switch, and auditing must stay on the human side.
