Multi-Model and Accessibility Interaction Architecture for Mobile AI Agents
This article explores a robust architecture for mobile AI agents, focusing on the integration of multi-model capabilities and accessibility services. It details how to decouple model "thinking" from device "execution" by establishing a unified model client abstraction, routing strategies, and structured node tree processing. Additionally, it covers step-by-step task execution loops, strict security and permission governance, and observability design to help developers build stable, maintainable, and auditable mobile AI agent systems.
1. Technical Background and Overall Goals
The core objective of a mobile AI agent is to enable AI models not only to understand natural language but also to perform operations in real device environments, such as page recognition, control location, clicking, swiping, inputting, returning, and capturing screenshots. Compared to traditional chat applications, these systems must simultaneously address three issues:
- How the model understands tasks and generates action plans;
- How the application converts model outputs into device-executable operations;
- How the system maintains stable operation under permissions, security, and exception environments.
Therefore, a complete mobile AI agent is typically not a single model or interface, but a combination of a model access layer, a task orchestration layer, a device interaction layer, a state observation layer, and a security governance layer. Multi-model support and accessibility service control are the two most critical foundational capabilities.
From an engineering perspective, the system should decouple “thinking” and “execution.” The model is responsible for understanding the goal, analyzing the current state, and proposing the next action; the device interaction module is responsible for validating the action, locating the target node, and executing the operation; the state observation module feeds the execution result back to the model, forming a closed loop of “observe – decide – execute – re-observe.”
2. Multi-Model Access Layer Design
2.1 Why Multiple Models Are Needed
Different models vary in context length, reasoning capability, response speed, cost, and output stability. The tasks faced by mobile AI agents also differ:
- Simple information extraction is suitable for models with faster response speeds;
- Multi-step page operations require stronger planning and reasoning capabilities;
- Long-process tasks need larger context capacities;
- Data-sensitive scenarios may require models in local or controlled environments;
- High-concurrency business requires dynamic scheduling based on quotas, load, and availability.
If an application directly binds a specific model service in its business code, changing the model later often requires modifying a large amount of call logic, leading to code coupling. Therefore, a more reasonable approach is to establish a unified model client abstraction.
2.2 Unified Client Abstraction
A model calling interface independent of specific services can be defined to shield the differences in request formats, authentication methods, streaming responses, and error codes across different backends. For example:
interface ModelClient {suspend fun complete(request: ModelRequest): ModelResponsefun stream(request: ModelRequest): Flow<ModelChunk>}
Where ModelRequest can contain the following common fields:
- System instructions;
- User task;
- Historical context;
- Current page summary;
- Available tools list;
- Maximum output length;
- Whether to enable streaming return.
The model response should be uniformly represented as text, structured action, or error information. For an AI agent, returning only natural language is not ideal; it is more recommended to require the model to output constrained structured results, for example:
{"type": "click","target": {"text": "Confirm"},"reason": "Current page requires form submission"}
In actual projects, the model output should also undergo format validation, and unverified text should not be directly handed over to the device control module.
2.3 Backend Factory and Routing Strategy
To achieve pluggable integration, a client factory or registry can be used to manage different model backends. The business layer only needs to provide a logical model identifier and a calling strategy, and the underlying layer creates the corresponding client based on the configuration.
Routing strategies can include:
- Selecting models by task type;
- Selecting models by response latency;
- Switching to a fallback model based on failure retry counts;
- Selecting an adapted model by context length;
- Restricting available backends by data security level;
- Configuring default models by user or tenant.
It should be noted that switching models cannot just change the name; it should also synchronously handle the context format, tool description format, and output constraints. For continuous tasks, necessary task states must be preserved when switching models to avoid repeated or erroneous operations caused by context loss.
3. Accessibility Interaction Layer Responsibilities
3.1 Reading Structured Information from the Interface
Actionable information in mobile applications is usually contained within the interface node tree. The accessibility service can read the node structure of the current window, including text, content descriptions, clickable states, editable states, selected states, boundary regions, and parent-child hierarchical relationships.
The system should not send the entire node tree to the model without processing, as this will cause context redundancy, privacy leaks, and increased inference costs. A more reasonable approach is to perform node normalization first:
Node Type: ButtonVisible Text: ConfirmClickable: YesLocation: Bottom right of the screenState: Enabled
Subsequently, filtering is performed based on task relevance, retaining only interactive nodes, key text nodes, and necessary hierarchical relationships.
3.2 Device Operation Capabilities
The interaction layer typically needs to provide the following basic capabilities:
- Clicking a specified node;
- Long-pressing a specified node;
- Swiping or dragging;
- Focusing on an input box;
- Injecting text;
- Returning or switching pages;
- Obtaining current window information;
- Capturing screen images;
- Traversing and filtering the node tree.
These capabilities should be encapsulated into a finite set of tools rather than exposing arbitrary underlying interfaces to the model. For example, you can define:
click(target)inputText(target, text)swipe(start, end, duration)pressBack()captureScreen()readCurrentPage()
Each tool requires parameter validation. For instance, a click operation must confirm that the target node exists and is visible; an input operation must confirm that the target is an editable control; a swipe operation needs to limit the start/end coordinate range and duration.
3.3 Node Location Strategy
Relying solely on text for location is vulnerable to language, dynamic content, and page redesigns. The actual system should adopt a multi-strategy combination:
- Prioritize stable control identifiers;
- Next, use text and content descriptions;
- Then combine control type, hierarchical relationship, and screen region;
- Finally, use image or coordinate-assisted location when necessary.
Location results should include a confidence level. If multiple candidate nodes exist, the system should not randomly select one but should feed the candidates back to the model or ask the user for confirmation. For high-risk operations, such as submission, deletion, payment, or sending content, a secondary confirmation mechanism must be added.
4. Task Execution Loop
A reliable AI agent should not adopt an approach where the “model generates all operations at once.” A more stable solution is step-by-step execution:
Step 1: Understand the Task
The system receives the user’s goal, converts it into a clear task description, and identifies the constraints in the task. For example, the user may request only to read information without modifying content, or may require confirmation before execution.
Step 2: Observe the Page
Obtain the current state through the accessibility node tree and necessary screenshots to form a structured page summary. The page summary should try to include controls, text, and states relevant to the task.
Step 3: Generate the Next Action
The model generates one or a set of candidate actions based on the goal and current state. For complex tasks, it is recommended to execute only one high-confidence action at a time so that page changes can be detected promptly.
Step 4: Execute and Validate
After the device interaction layer executes the action, it should wait for the page to stabilize and re-read the state. Success cannot be judged solely by a successful API call, because a successful click response does not mean the page has completed the transition.
Step 5: Exception Handling
If the target node disappears, the page changes, permissions are insufficient, or the operation times out, the system should record the reason and adopt a recovery strategy, such as re-reading the page, returning to the previous level, refreshing the task context, or requesting user intervention.
5. Security and Permission Governance
Accessibility services possess strong device control capabilities, so strict security boundaries must be established.
First, the principle of least privilege should be adopted, enabling relevant capabilities only after explicit user authorization, and clearly explaining the types of operations the service can perform. Second, sensitive data should be desensitized; for example, account information, verification codes, communication content, and identity information should not be sent to the model by default.
Additionally, an action risk grading system should be established:
- Low-risk actions: reading pages, expanding menus, regular swiping;
- Medium-risk actions: filling out forms, sending regular messages, modifying non-critical settings;
- High-risk actions: deleting data, submitting transactions, modifying security configurations, sending sensitive content.
High-risk actions should require user confirmation, utilizing system-level prompts or manual review when necessary. The model can only make suggestions; the final execution authority should be jointly decided by the policy engine and the permission control module.
6. Reliability and Observability Design
To facilitate troubleshooting, the system needs to record a complete but desensitized execution chain, including:
- Task identifier;
- Current page summary;
- Model request and response time;
- Action type;
- Node location result;
- Execution result;
- Retry count;
- Exception reason;
- Final task status.
Logs should not unconditionally save full screenshots and raw text; retention policies should be set based on privacy levels. For production systems, metrics such as model call success rate, action failure rate, page recognition failure rate, average task duration, and manual takeover ratio can also be added.
For exception recovery, it is recommended to set timeout, retry, and circuit breaker mechanisms. When a single action fails, limited retries can be performed, but after consecutive failures, automatic operations should stop to prevent the agent from getting stuck in repeated clicking or page loops.
7. Engineering Implementation Suggestions
In actual development, the system can be divided into the following modules:
Task Entry Layer└── Task parsing and user confirmationModel Orchestration Layer└── Model routing, context management, output validationState Observation Layer└── Node tree reading, screenshot, page summaryAction Execution Layer└── Click, input, swipe, backPolicy and Security Layer└── Permissions, risk levels, secondary confirmationObservability Layer└── Logging, metrics, exception tracking
Modules should communicate through stable data structures, avoiding direct dependencies on specific models or specific pages. For testing, virtual node trees and simulated page states can be constructed to verify whether model outputs are correctly converted into safe actions. At the same time, exception scenarios such as permissions being turned off, slow page loading, duplicate nodes, app switching, and network unavailability should also be covered.
8. Conclusion
Multi-model capability addresses “how to obtain more suitable intelligent decisions,” while accessibility interaction capability addresses “how to implement decisions on the device.” Only by combining the two can a truly executable mobile AI agent be formed.
However, the key to the system is not just connecting more models or adding more operational interfaces, but establishing clear abstraction boundaries: the model is responsible for understanding and planning, the interaction layer for execution, the policy layer for limiting risks, and the observation layer for validating results. Only on the foundation of unified interfaces, structured output, step-by-step execution, permission control, and comprehensive monitoring can mobile AI agents gradually evolve from demo features to stable, maintainable, and auditable engineering systems.
