How erickjtorres/app_use works
Project Type and Purpose
• Type: An open-source Python library/tool for AI‐powered UI automation of mobile apps (currently Flutter, with React Native planned).
• Purpose: Expose a simple API so that AI agents (via LLMs) can inspect and interact with a running mobile app’s UI tree over the Flutter Dart VM service (and future frameworks).
File Structure
• app_use/agent/: Core “Agent” abstractions, orchestration of prompts, LLM integration, history, and interaction flows.
• app_use/app/: “App” layer—connects to the mobile app’s VM service (WebSocket), provides low-level commands.
• app_use/controller/: Registry of controllers, command dispatch, high-level API for actions like tap, scroll, find.
• app_use/agent/message_manager/: Handles message formatting, retries, error management, and view rendering of results.
• app_use/nodes/: Builds and traverses UI element trees (WidgetTreeBuilder, ElementTreeBuilder), abstracts UI hierarchy.
• examples/: Quickstart scripts showing integration with ChatOpenAI and the AppUse API.
Extract Key Insights from README
• External Dependencies: LLM (ChatOpenAI), WebSocket VM service (FlutterDriver), Python libraries.
• Core Workflow:
1. To VM service
2. Pull UI tree
3. Agent issues high-level tasks
4. Controller translates to low-level commands
5. App layer executes commands over WebSocket
6. Feedback loop to LLM
• Extensibility: Custom Agents, new frameworks (React Native), widget interaction patterns.
Main Components & Their Relationships
a. Agent Layer
• Contains: task prompt, LLM client (ChatOpenAI), run loop, History object
• Outbound: sends “intents” or “actions” to Message Manager/Controller
• Inbound: receives UI‐state snapshots, command results
b. Message Manager
• Role: formats messages, handles retries, structures prompts/ responses
c. Controller Layer
• Role: Maps high‐level intents to platform commands (e.g., tap(widget_id), scroll)
d. App Layer
• Role: Opens WebSocket to Dart VM service, sends raw JSON RPC commands
e. External Systems
• LLM Provider (OpenAI)
• Flutter App (with driver extension enabled)
• WebSocket VM Service (Dart VM)
f. Nodes / UI Tree
• Role: Construct in‐memory representation of UI hierarchy for the Agent’s decision making
Architectural Patterns & Principles
• Layered Architecture: clear separation—Agent (orchestration), Controller (translation), App (transport), Nodes (model).
• Adapter/Bridge: App layer adapts between Python and the Dart VM service.
• Extensibility Points: Agent subclasses, controller registry, app adapters for new frameworks.
• Context Management: async with patterns for resource safety.