OS-Genesis Framework
repository·main·Indexed 41 days ago
https://github.com/os-copilot/os-genesisA framework for automating the construction of GUI agent trajectory data using reverse task synthesis. OS-Genesis provides tools and models, including versions based on InternVL2 and Qwen2-VL, to train agents for interacting with Android and Web interfaces. It includes pipelines for collecting interaction triples via random walks in AndroidWorld and WebArena, a trajectory reward model for scoring, and evaluation tools for the AndroidControl benchmark.
What's inside OS-Genesis
- OS-Genesis is an interaction-driven pipeline designed to synthesize high-quality and diverse GUI agent trajectory data without human supervision or predefined tasks. It utilizes reverse task synthesis and a trajectory reward model to enable effective end-to-end training of GUI agents across Mobile (Android) and Web environments.
Build trajectories in the AndroidWorld Environment
mainTransform instructions into trajectories in AndroidWorld by following these steps:
- Prepare App States: Unzip
params_new.zipinto theandroid_env/android_worlddirectory, replacing existing folders if necessary. - Prepare Instructions: Move your instruction file (e.g.,
aw_instructions.json) into theandroid_env/androidworlddirectory. - Execute Runner: Run
run_gpt_task_runner.pyto generate augmented trajectory information and screenshots.
Outputs:
aw_instructions.json: Contains augmented trajectory information.- A screenshot folder (e.g.,
screenshots_gpt_241103).
Note on Implementation: The trajectory collection uses inference logic adapted from the M3A agent. Specific modifications are documented via comments within
gpt_task_runner.py.# Move instruction file to the environment directory # Then run the task runner python run_gpt_task_runner.py- Prepare App States: Unzip
Evaluate the AndroidControl Benchmark
mainTo evaluate the AndroidControl Benchmark using OS-Genesis, follow these three steps:
- Clone the repository to your local environment.
- Run Inference using the provided shell script, passing the dataset and checkpoint as arguments.
- Run Evaluation using the Python evaluation script.
# 1. Clone the repository git clone https://github.com/OS-Copilot/OS-Genesis.git # 2. Inference cd OS-Genesis/evaluation/android_control bash run_ac_inference.sh $dataset $checkpoint # 3. Evaluation python ac_eval.pyCollect interaction triples via Random Walk in AndroidWorld
mainTo collect
<screen_pre, action, screen_after>triples using a random walk in the AndroidWorld environment, follow these steps:- Setup: Clone the AndroidWorld repository. Place
random_walk_aw.pyandrun_random_walk_aw.pyinside the AndroidWorld directory. - Start Emulator: Launch the Android Virtual Machine using the emulator command. Ensure you use the correct
EMULATOR_NAME(e.g.,AndroidWorldAvd). - Run Collection: Execute the runner script to begin large-scale interaction collection.
Outputs include screenshots in both the original format and an
allytreeannotated format.# 1. Start the emulator EMULATOR_NAME=AndroidWorldAvd ~/Library/Android/sdk/emulator/emulator -avd $EMULATOR_NAME -no-snapshot -grpc 8554 # 2. Run the random walk collection python run_random_walk_aw.py- Setup: Clone the AndroidWorld repository. Place
Collect interaction triples via Random Walk in WebArena
mainTo collect
<screen_pre, action, screen_after>triples in the WebArena environment:- Setup: Configure WebArena and ensure the specified ports are open to access the website.
- Prepare Script: Place
random_walk_web.pyin the WebArena directory. - Run Collection: Execute the script to perform the random walk and collect large-scale interaction triples.
python random_walk_web.pyEvaluate using AndroidWorld
mainTo evaluate a trained model using AndroidWorld, you must align the model's action space with the environment. This is achieved by integrating the Genesis agent files into the original AndroidWorld agent directory and replacing the inference script.
Follow these steps:
- Relocate Genesis files: Move
genesis_agent.pyandgenesis_utils.pyto the directoryandroid_env/android_world/android_world/agents(this is the original path for agents in AndroidWorld). - Replace inference script: Replace the existing
infer.pyinandroid_env/android_world/android_world/agentswith your Genesis inference script. - Run evaluation: Execute the evaluation using the
run.pyscript with theandroid_worldsuite family.
This process follows the standard AndroidWorld framework.
python run.py \ --suite_family=android_world \ --agent_name=genesis_agent \ --perform_emulator_setup- Relocate Genesis files: Move
Extract instructions and trajectories from dataset JSON files
mainThe diversity analysis expects data in specific JSON formats. To prepare data for analysis, you must extract two types of information:
- Instructions: A list of strings extracted from the
instructionkey of each entry. - Trajectories: A list of strings representing the reasoning or actions taken during a task.
- For Mobile data, extract the
reasonfield from each step within thestepslist. - For Web data, extract the
reason_actionfield from each step within thestepslist.
- For Mobile data, extract the
Note: When processing trajectories, it is common practice to limit the number of samples (e.g., using a
MAX_NUMconstant) to maintain computational efficiency during embedding generation.# Extracting instructions instructions = [d['instruction'] for d in data_list] # Extracting Mobile trajectories (using 'reason') mobile_traj = [] for episode in mobile_data: if 'steps' in episode: for step in episode['steps']: mobile_traj.append(step['reason']) # Extracting Web trajectories (using 'reason_action') web_traj = [] for episode in web_data: if 'steps' in episode: for step in episode['steps']: web_traj.append(step['reason_action'])- Instructions: A list of strings extracted from the
Troubleshoot unresponsive Android VM during long runs
mainDuring long data collection runs, the Android Virtual Machine may become unresponsive, likely due to memory issues within the VM.
Workaround: Reset the device directly within Android Studio to release occupied memory and restore normal operation.
Access Raw Collected Triples for Reverse Task Synthesis
mainIf you wish to reproduce the reverse task synthesis process without re-collecting data from emulators, you can use the raw
<s_pre, a, s_post>triples provided. These include screenshots and corresponding text (including SoM info).- Mobile Data: Available via Google Drive Screenshots and Data JSON.
- Web Data: Available via Google Drive Screenshots and Data JSON.
Examine the Trajectory Reward Model implementation
mainAn example implementation of the Reward Model used in OS-Genesis can be found ingenesis_rm.py. This serves as a reference for how trajectories are scored.Available OS-Genesis Models for Mobile and Web
mainOS-Genesis provides pre-trained models for Android (AndroidControl and AndroidWorld) and Web environments. These models are based on either
InternVL2orQwen2-VLarchitectures.AndroidControl Models
- OS-Genesis-4B-AC: Based on
InternVL2-4B. Trained onOS-Genesis-ac-training-data. - OS-Genesis-7B-AC: Based on
Qwen2-VL-7B-Instruct. Trained onOS-Genesis-ac-training-data. - OS-Genesis-8B-AC: Based on
InternVL2-8B. Trained onOS-Genesis-ac-training-data.
AndroidWorld Models
- OS-Genesis-4B-AW: Based on
InternVL2-4B. Trained onOS-Genesis-aw-training-data. - OS-Genesis-7B-AW: Based on
Qwen2-VL-7B-Instruct. Trained onOS-Genesis-aw-training-data. - OS-Genesis-8B-AW: Based on
InternVL2-8B. Trained onOS-Genesis-aw-training-data.
Web Models
- OS-Genesis-4B-WA: Based on
InternVL2-4B. Trained onOS-Genesis-web-training-data. - OS-Genesis-7B-WA: Based on
Qwen2-VL-7B-Instruct. Trained onOS-Genesis-web-training-data. - OS-Genesis-8B-WA: Based on
InternVL2-8B. Trained onOS-Genesis-web-training-data.
- OS-Genesis-4B-AC: Based on
Visualize text embeddings with HDBSCAN clustering
mainTo visually inspect how semantic clusters are distributed in the embedding space, you can project the embeddings and color them by cluster labels generated via HDBSCAN.
Steps:
- Generate embeddings using
SentenceTransformer. - Apply
HDBSCAN(min_cluster_size=2)to the embeddings to identify clusters. - Use a scatter plot to visualize the first two dimensions of the embeddings, coloring points by their cluster ID.
from sentence_transformers import SentenceTransformer from hdbscan import HDBSCAN import matplotlib.pyplot as plt # 1. Get embeddings model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2") embeddings = model.encode(sentences) # 2. Cluster clusterer = HDBSCAN(min_cluster_size=2).fit(embeddings) # 3. Visualize plt.scatter(embeddings[:, 0], embeddings[:, 1], c=clusterer.labels_, cmap="Spectral", s=10) plt.show()- Generate embeddings using