/Cradle

The Cradle framework is a first attempt at General Computer Control (GCC). Cradle supports agents to ace any computer task by enabling strong reasoning abilities, self-improvment, and skill curation, in a standardized general environment with minimal requirements.

Primary LanguagePythonMIT LicenseMIT

Cradle: Empowering Foundation Agents Towards General Computer Control

[Website] [arXiv] [PDF]

Python Version GitHub license

The Cradle framework empowers nascent foundation models to perform complex computer tasks via the same unified interface humans use, i.e., screenshots as input and keyboard & mouse operations as output.

πŸ“’ Updates

Latest Videos

                 

Click on either of the video thumbnails above to watch them on YouTube.

πŸ’Ύ Installation

Prepare the Environment File

We currently provide access to OpenAI's and Claude's API. Please create a .env file in the root of the repository to store the keys (one of them is enough).

Sample .env file containing private information:

OA_OPENAI_KEY = "abc123abc123abc123abc123abc123ab"
RF_CLAUDE_AK = "abc123abc123abc123abc123abc123ab" # Access Key for Claude
RF_CLAUDE_SK = "123abc123abc123abc123abc123abc12" # Secret Access Key for Claude
AZ_OPENAI_KEY = "123abc123abc123abc123abc123abc12"
AZ_BASE_URL = "https://abc123.openai.azure.com/"
RF_CLAUDE_AK = "abc123abc123abc123abc123abc123ab"
RF_CLAUDE_SK = "123abc123abc123abc123abc123abc12"
IDE_NAME = "Code"

OA_OPENAI_KEY is the OpenAI API key. You can get it from the OpenAI.

AZ_OPENAI_KEY is the Azure OpenAI API key. You can get it from the Azure Portal.

OA_CLAUDE_KEY is the Anthropic Claude API key. You can get it from the Anthropic.

RF_CLAUDE_AK and RF_CLAUDE_SK are AWS Restful API key and secret key for Claude API.

IDE_NAME refers to the IDE environment in which the repository's code runs, such as PyCharm or Code (VSCode). It is primarily used to enable automatic switching between the IDE and the target environment.

Setup

Python Environment

Please setup your python environment and install the required dependencies as:

# Clone the repository
git clone https://github.com/BAAI-Agents/Cradle.git
cd Cradle

# Create a new conda environment
conda create --name cradle-dev python=3.10
conda activate cradle-dev
pip install -r requirements.txt

Install the OCR Tools

1. Option 1
# Download best-matching version of specific model for your spaCy installation
python -m spacy download en_core_web_lg

or

# pip install .tar.gz archive or .whl from path or URL
pip install https://github.com/explosion/spacy-models/releases/download/en_core_web_lg-3.7.1/en_core_web_lg-3.7.1.tar.gz

2. Option 2
# Copy this url https://github.com/explosion/spacy-models/releases/download/en_core_web_lg-3.7.1/en_core_web_lg-3.7.1.tar.gz
# Paste it in the browser and download the file to res/spacy/data
cd res/spacy/data
pip install en_core_web_lg-3.7.1.tar.gz

πŸš€ Get Started

Due to the vast differences between each game and software, we have provided the specific settings for each of them below.

  1. Red Dead Redemption 2
  2. Stardew Valley
  3. Cities: Skylines
  4. Dealer's Life 2
  5. Software

🌲 File Structure

Since some users may want to apply our framework to new games, this section primarily showcases the core directories and organizational structure of Cradle. We will highlight in "⭐⭐⭐" the modules related to migrating to new games, and provide detailed explanations later.

Cradle
β”œβ”€β”€ cache # Cache the GroundingDino model and the bert-base-uncased model
β”œβ”€β”€ conf # ⭐⭐⭐ The configuration files for the environment and the llm model
β”‚   β”œβ”€β”€ env_config_dealers.json
β”‚   β”œβ”€β”€ env_config_rdr2_main_storyline.json
β”‚   β”œβ”€β”€ env_config_rdr2_open_ended_mission.json
β”‚   β”œβ”€β”€ env_config_skylines.json
β”‚   β”œβ”€β”€ env_config_stardew_cultivation.json
β”‚   β”œβ”€β”€ env_config_stardew_farm_clearup.json
β”‚   β”œβ”€β”€ env_config_stardew_shopping.json
β”‚   β”œβ”€β”€ openai_config.json
β”‚   β”œβ”€β”€ claude_config.json
β”‚   β”œβ”€β”€ restful_claude_config.json
β”‚   └── ...
β”œβ”€β”€ deps # The dependencies for the Cradle framework, ignore this folder
β”œβ”€β”€ docs # The documentation for the Cradle framework, ignore this folder
β”œβ”€β”€ res # The resources for the Cradle framework
β”‚   β”œβ”€β”€ models # Ignore this folder
β”‚   β”œβ”€β”€ tool # Subfinder for RDR2
β”‚   β”œβ”€β”€ [game or software] # ⭐⭐⭐ The resources for game, exmpale: rdr2, dealers, skylines, stardew, outlook, chrome, capcut, meitu, feishu
β”‚   β”‚   β”œβ”€β”€ prompts # The prompts for the game
β”‚   β”‚   β”‚   └── templates
β”‚   β”‚   β”‚       β”œβ”€β”€ action_planning.prompt
β”‚   β”‚   β”‚       β”œβ”€β”€ information_gathering.prompt
β”‚   β”‚   β”‚       β”œβ”€β”€ self_reflection.prompt
β”‚   β”‚   β”‚       └── task_inference.prompt
β”‚   β”‚   β”œβ”€β”€ skills # The skills json for the game, it will be generated automatically
β”‚   β”‚   β”œβ”€β”€ icons # The icons difficult for GPT-4 to recognize in the game can be replaced with text for better recognition using an icon replacer
β”‚   β”‚   └── saves # Save files in the game
β”‚   └── ...
β”œβ”€β”€ requirements.txt # The requirements for the Cradle framework
β”œβ”€β”€ runner.py # The main entry for the Cradle framework
β”œβ”€β”€ cradle # Cradle's core modules
β”‚   β”œβ”€β”€ config # The configuration for the Cradle framework
β”‚   β”œβ”€β”€ environment # The environment for the Cradle framework
β”‚   β”‚   β”œβ”€β”€ [game or software] # ⭐⭐⭐ The environment for the game, exmpale: rdr2, dealers, skylines, stardew, outlook, chrome, capcut, meitu, feishu
β”‚   β”‚   β”‚   β”œβ”€β”€ __init__.py # The initialization file for the environment
β”‚   β”‚   β”‚   β”œβ”€β”€ atomic_skills # Atomic skills in the game. Users should customise them to suit the needs of the game or software, e.g. character movement
β”‚   β”‚   β”‚   β”œβ”€β”€ composite_skills # Combination skills for atomic skills in games or software
β”‚   β”‚   β”‚   β”œβ”€β”€ skill_registry.py # The skill registry for the game. Will register all atomic skills and composite skills into the registry.
β”‚   β”‚   β”‚   └── ui_control.py # The UI control for the game. Define functions to pause the game and switch to the game window
β”‚   β”‚   └── ...
β”‚   β”œβ”€β”€ gameio # Interfaces that directly wrap the skill registry and ui control in the environment
β”‚   β”œβ”€β”€ log # The log for the Cradle framework
β”‚   β”œβ”€β”€ memory # The memory for the Cradle framework
β”‚   β”œβ”€β”€ module # Currently there is only the skill execution module. Later will migrate action planning, self-reflection and other modules from planner and provider
β”‚   β”œβ”€β”€ planner # The planner for the Cradle framework. Unified interface for action planning, self-reflection and other modules. This module will be deleted later and will be moved to the module module.
β”‚   β”œβ”€β”€ runner # ⭐⭐⭐ The logical flow of execution for each game and software. All game and software processes will then be unified into a single runner
β”‚   β”œβ”€β”€ utils # Defines some helper functions such as save json and load json
β”‚   └── provider # The provider for the Cradle framework. We have semantically decomposed most of the execution flow in the runner into providers
β”‚       β”œβ”€β”€ augment # Methods for image augmentation
β”‚       β”œβ”€β”€ llm # Call for the LLM model, e.g. OpenAI's GPT-4o, Claude, etc.
β”‚       β”œβ”€β”€ module # ⭐⭐⭐ The module for the Cradle framework. e.g., action planning, self-reflection and other modules. It will be migrated to the cradle/module later.
β”‚       β”œβ”€β”€ object_detect # Methods for object detection
β”‚       β”œβ”€β”€ process # ⭐⭐⭐ Methods for pre-processing and post-processing for action planning, self-reflection and other modules
β”‚       β”œβ”€β”€ video # Methods for video processing
β”‚       β”œβ”€β”€ others # Methods for other operations, e.g., save and load coordinates for skylines
β”‚       β”œβ”€β”€ circle_detector.py # The circle detector for the rdr2
β”‚       β”œβ”€β”€ icon_replacer.py # Methods for replacing icons with text
β”‚       β”œβ”€β”€ sam_provider.py # Segment anything for software
β”‚       └── ...
└── ...

πŸ“š Migrate to New Game

Since each game's settings and the operating systems they are compatible with are different, Cradle cannot simply replace one game name to migrate to a new game. We suggest considering each game specifically. For example, RDR2, an independent AAA game, requires real-time combat, so we need to pause the game to wait for GPT-4o's response and then unpause the game to execute the actions. Stardew has the same issue. Other games like Dealer's Life 2 and Cities: Skylines do not have real-time requirements, so they do not need to pause. If the new game is similar to the latter, we recommend copying Cities: Skylines' implementation and following its implementation path to create the corresponding modules. Although each game may differ significantly, our Cradle framework can still achieve a unified adaptation for a game. Assuming the new game's name is newgame, the specific migration pipeline can be found Migrate to New Game Guide.

Citation

If you find our work useful, please consider citing us!

@article{tan2024cradle,
  title={Cradle: Empowering Foundation Agents towards General Computer Control},
  author={Weihao Tan and Wentao Zhang and Xinrun Xu and Haochong Xia and Ziluo Ding and Boyu Li and Bohan Zhou and Junpeng Yue and Jiechuan Jiang and Yewen Li and Ruyi An and Molei Qin and Chuqiao Zong and Longtao Zheng and Yujie Wu and Xiaoqiang Chai and Yifei Bi and Tianbao Xie and Pengjie Gu and Xiyun Li and Ceyao Zhang and Long Tian and Chaojie Wang and Xinrun Wang and BΓΆrje F. Karlsson and Bo An and Shuicheng Yan and Zongqing Lu},
  journal={arXiv preprint arXiv:2403.03186},
  year={2024}
}