This guide will help you set up and run the Android Agent-S2 system for automated Android UI interaction tasks with comprehensive episode scoring and logging.
This project builds upon two key frameworks:
- Android World: A dynamic benchmarking environment for Android UI automation tasks
- Agent-S: A hierarchical agent architecture for complex task execution
For more information about the underlying frameworks, please refer to their respective repositories and documentation.
- Operating System: Windows, macOS, or Linux
- RAM: At least 8GB (16GB recommended)
- Storage: At least 10GB free space
- Python: 3.11+ (required for android_world compatibility)
- Android Studio: Latest version
- Conda: For Python environment management
- Git: For cloning repositories
# Clone the Agent-S repository
git clone
cd Agent-S
# Initialize and update submodules
git submodule update --init --recursive- Download Android Studio from https://developer.android.com/studio
- Install Android Studio following the installation wizard
- Open Android Studio and complete the initial setup
- Open Android Studio
- Go to Tools β AVD Manager
- Click Create Virtual Device
- Select Pixel 6 for hardware
- Choose Tiramisu, API Level 33 for System Image
- Name the AVD: AndroidWorldAvd
- Click Finish
Note: Watch the setup video for detailed visual instructions.
Important: Launch the emulator from command line, NOT from Android Studio UI.
# Find your Android SDK path (usually in Android Studio settings)
# Common paths:
# Windows: C:\Users\username\AppData\Local\Android\Sdk
# macOS: ~/Library/Android/sdk
# Linux: ~/Android/Sdk
# Set ANDROID_HOME environment variable
export ANDROID_HOME=/path/to/your/Android/Sdk
# Launch the emulator with required flags
$ANDROID_HOME/emulator/emulator -avd AndroidWorldAvd -grpc 8554Critical: The
-grpc 8554flag is required for communication with the accessibility forwarding app.
# Create conda environment with current Python version
conda create -n android_world python=3.11
# Activate the environment
conda activate android_world
# Verify Python version
python --version # Should show Python 3.11.x# Navigate to the Agent-S directory
cd Agent-S
# Install base requirements
pip install -r requirements.txt# Navigate to android_world directory
cd android_world
# Install android_world dependencies
pip install -e .# Install additional packages needed for Android Agent-S2
pip install absl-py
pip install pillow
pip install opencv-python
pip install requests
pip install tiktoken# Make sure you're in the android_world conda environment
conda activate android_world
# Install all requirements (including Android Agent-S2 dependencies)
pip install -r requirements.txt# Set OpenAI API key (required for LLM operations)
export OPENAI_API_KEY="your-openai-api-key-here"
# Set Android SDK path
export ANDROID_HOME="/path/to/your/Android/Sdk"
# Add platform-tools to PATH
export PATH=$PATH:$ANDROID_HOME/platform-toolsBefore running, ensure:
- β
Android emulator is running with
-grpc 8554flag - β
Conda environment
android_worldis activated - β OpenAI API key is set
- β All dependencies are installed
The system provides several run scripts for different use cases:
# Navigate to the s2android directory
cd Agent-S/gui_agents/s2android
# Run with default settings (ContactsAddContact task)
python run_task.py
# Run with specific model
python run_task.py --model=gpt-4o-mini
# Run with specific task
python run_task.py --task=ContactsAddContact
# Run with custom API key
python run_task.py --api_key=your-api-key# Run with comprehensive episode scoring and metrics
python run_task_with_scorer.py
# Run with specific task and model
python run_task_with_scorer.py --task=ContactsAddContact --model=gpt-4o-mini
# Run with custom parameters
python run_task_with_scorer.py --task=SystemWifiTurnOn --model=gpt-4o-mini --console_port=5554# Run all available tasks with scoring
python run_all_tasks_with_scorer.py
# Run with specific model and max steps
python run_all_tasks_with_scorer.py --model=gpt-4o-mini --max_steps=20
# Start from a specific task (useful for resuming)
python run_all_tasks_with_scorer.py --start_from_task=ContactsAddContact
# Exclude specific tasks
python run_all_tasks_with_scorer.py --exclude_tasks=ContactsDeleteContact,SystemWifiTurnOn# Test screenshot capture and processing
python run_simple_screenshot_test.py
# Test with specific parameters
python run_simple_screenshot_test.py --model=gpt-4o-mini# Compare screenshots between different runs
python run_screenshot_comparison.py
# Compare with specific parameters
python run_screenshot_comparison.py --model=gpt-4o-mini# Run with custom ADB path
python run_task_with_scorer.py --adb_path=/path/to/adb
# Run with different console port
python run_task_with_scorer.py --console_port=5556
# Run with emulator setup (only needed once)
python run_task_with_scorer.py --perform_emulator_setup=True
# Run with specific task and model
python run_task_with_scorer.py --task=ContactsAddContact --model=gpt-4o-miniThe Android Agent-S2 includes a comprehensive episode scoring system that evaluates agent performance across multiple dimensions:
The episode scorer computes a 0-100 score based on:
- Goal Completion: +50 points (primary success metric)
- Subtask Coverage: Up to +20 points (planning effectiveness)
- Step Efficiency: Up to +10 points (minimal steps)
- Action Validity: Up to +5 points (correct actions)
- Verifier Alignment: Up to +5 points (verification success)
- Replan Penalty: Up to -10 points (excessive replanning)
- Stall Penalty: Up to -10 points (lack of progress)
- Cost Penalty: Up to -5 points (token usage)
- Latency Penalty: Up to -5 points (response time)
- Steps taken: Number of execution steps
- Actions performed: Total actions and state-changing actions
- Token usage: Input/output tokens for planner, executor, and DAG
- Latency: Response times for each component
- Verification: Success rate of action verification
- Planning: Number of planning attempts and subtask completion
All logs are stored in gui_agents/s2android/logs/ with timestamped filenames:
logs/
βββ qa_logs_YYYYMMDD_HHMMSS.json # Question-Answer logs
βββ metrics_YYYYMMDD_HHMMSS.jsonl # Episode metrics
βββ qa_logs_TaskName_YYYYMMDD_HHMMSS.json # Task-specific QA logs
βββ metrics_TaskName_YYYYMMDD_HHMMSS.jsonl # Task-specific metrics
Contains detailed question-answer interactions between the agent and verifier:
- Task goal: The original task objective
- Task success: Whether the task was completed successfully
- QA pairs: All question-answer interactions during execution
- Verification results: Success/failure of each action verification
- Reasoning: Detailed reasoning for each decision
Contains comprehensive episode metrics in JSONL format:
- Final score: Overall episode score (0-100)
- Success status: Whether the goal was achieved
- Component scores: Breakdown of scoring components
- Performance metrics: Steps, actions, tokens, latency
- Planning metrics: Subtasks planned and completed
# View recent QA logs
ls -la gui_agents/s2android/logs/qa_logs_*.json | tail -5
# View recent metrics
ls -la gui_agents/s2android/logs/metrics_*.jsonl | tail -5
# Analyze specific task logs
grep "ContactsAddContact" gui_agents/s2android/logs/metrics_*.jsonl
# View log contents
cat gui_agents/s2android/logs/qa_logs_20250811_143108.jsonThe logs can be analyzed to:
- Track performance trends across multiple runs
- Identify failure patterns and improvement opportunities
- Compare different models and configurations
- Debug agent behavior and decision-making
- Generate performance reports and visualizations
# Error: adb not found in common Android SDK paths
# Solution: Set correct ANDROID_HOME and PATH
export ANDROID_HOME="/path/to/your/Android/Sdk"
export PATH=$PATH:$ANDROID_HOME/platform-tools# Check if emulator is running
adb devices
# If no devices listed, restart emulator with correct flags
$ANDROID_HOME/emulator/emulator -avd AndroidWorldAvd -grpc 8554# If you get android_world import errors
cd Agent-S/android_world
pip install -e .# Ensure you're using Python 3.11+
python --version
# If not, recreate conda environment
conda deactivate
conda remove -n android_world --all
conda create -n android_world python=3.11
conda activate android_world# Run with verbose logging
python run_task_with_scorer.py --verbosity=1
# Check emulator status
adb devices
adb shell getprop ro.build.version.releaseWhen running successfully, you should see:
π Starting Android Agent-S2 Contact Task
π± Using device on port: 5554
π€ Using model: gpt-4o-mini
π§ Setting up Android environment...
β
Successfully imported android_world components
π Loading task registry...
π― Using default task: ContactsAddContact
π― Task Goal: Add a new contact with name 'John Doe' and phone number '555-1234'
π€ Creating Android Agent-S2...
π Starting task execution...
==================================================
π― Goal: Add a new contact with name 'John Doe' and phone number '555-1234'
==================================================
π Step 1/20
------------------------------
Worker β Add contact name: Enter the contact's first and last name
π§ WORKER EXECUTION (Step 1):
Subtask: Add contact name: Enter the contact's first and last name
Plan: I need to add a contact name. Let me first open the contacts app...
β
Screen changed detected
π Action: {"action_type": "open_app", "app_name": "Contacts"}
π Task Results
==================================================
π― Goal: Add a new contact with name 'John Doe' and phone number '555-1234'
π Success Score: 1.0/1.0
β
Agent Completed: Yes
π Result: SUCCESS β
π
Episode Score: 85.2 / 100
π― Goal: β
SUCCESS
π Components:
Goal: +50.0
Coverage: +18.5
Efficiency: +8.2
Validity: +4.8
Verifier: +4.7
Penalties: -1.0 (replans), -0.0 (stalls), -0.0 (cost), -0.0 (latency)
π Stats: 12 steps, 1 replans, 15 actions, 8 state changes
The system supports various Android tasks:
- ContactsAddContact: Add a new contact with name and phone number
- ContactsEditContact: Edit an existing contact
- ContactsDeleteContact: Delete a contact
- ContactsNewContactDraft: Create a contact draft
- SystemWifiTurnOn: Turn on WiFi
- SystemWifiTurnOff: Turn off WiFi
- SystemBluetoothTurnOn: Turn on Bluetooth
- SystemBluetoothTurnOff: Turn off Bluetooth
- FilesMoveFile: Move a file to a different location
- FilesDeleteFile: Delete a file
- FilesCreateFolder: Create a new folder
- MarkorAddNoteHeader: Add a header to a note
- MarkorChangeNoteContent: Modify note content
- MarkorCreateFolder: Create a new folder in Markor
- ExpenseAddSingle: Add a single expense
- ExpenseAddMultiple: Add multiple expenses
- ExpenseDeleteSingle: Delete a single expense
- ExpenseDeleteMultiple: Delete multiple expenses
- ExpenseDeleteDuplicates: Remove duplicate expenses
# List connected devices
adb devices
# Check emulator properties
adb shell getprop
# Check running processes
adb shell ps# View system logs
adb logcat
# View specific app logs
adb logcat | grep "com.android.contacts"# Run with detailed logging
python run_task_with_scorer.py --verbosity=2
# Check episode data collection
# Look for episode_images_* directories after runningAgent-S/
βββ gui_agents/
β βββ s2android/
β βββ agents/ # Agent implementations
β β βββ agent_s.py # Main Android Agent-S2
β β βββ worker.py # Worker agent
β β βββ manager.py # Manager agent
β β βββ verifier_agent.py # Verification agent
β β βββ grounding.py # Grounding utilities
β βββ core/ # Core modules
β βββ memory/ # Procedural memory
β βββ utils/ # Utilities
β β βββ episode_scorer.py # Episode scoring system
β βββ logs/ # Generated logs
β βββ run_task.py # Basic task execution
β βββ run_task_with_scorer.py # Task with scoring β
β βββ run_all_tasks_with_scorer.py # Batch execution
β βββ run_simple_screenshot_test.py # Screenshot testing
β βββ run_screenshot_comparison.py # Screenshot comparison
βββ android_world/ # Android World framework
βββ requirements.txt # All dependencies (including Android Agent-S2)
βββ README.md # This file
If you encounter issues:
- Check the troubleshooting section above
- Verify all prerequisites are met
- Check emulator is running with correct flags
- Ensure conda environment is activated
- Verify API key is set correctly
- Review logs in
gui_agents/s2android/logs/for detailed error information
For additional support, please check the main project README or create an issue in the repository.
- The emulator must be launched with
-grpc 8554flag for proper communication - Python 3.11+ is required for android_world compatibility
- The system saves comprehensive logs for analysis in
gui_agents/s2android/logs/ - Episode scoring provides detailed performance metrics (0-100 scale)
- All runs generate both QA logs and metrics logs for complete analysis
- The verifier agent provides detailed analysis of agent performance
- Field identification has been enhanced with hint_text analysis
- Android World GitHub: Official repository with setup instructions, task definitions, and API documentation
- Agent-S GitHub: Official repository with agent architecture details and implementation guides
- Android World: "Android World: A Dynamic Benchmarking Environment for Android UI Automation Tasks" - Provides detailed methodology and task definitions
- Agent-S: "Agent-S: A Hierarchical Agent Architecture for Complex Task Execution" - Describes the hierarchical planning and execution framework
- Android World Issues: GitHub Issues - For bug reports and feature requests
- Agent-S Discussions: GitHub Discussions - For questions and community support