Agent S Framework

repository·main·Indexed 11 days ago

https://github.com/simular-ai/agent-s

An open-source framework for autonomous computer interaction that enables intelligent GUI agents to perform complex tasks via an Agent-Computer Interface (ACI). It supports Linux, macOS, and Windows, utilizing the gui-agents SDK and grounding models like UI-TARS-1.5-7B for visual element detection. The framework allows for programmatic control via the GraphSearchAgent and AgentS3 classes, CLI interaction, and integration with OpenClaw for GUI automation.

Tokens
12.3K
Snippets
34
Records
49
Agent score
95%

What's inside Agent S

  1. Manage VM Snapshots in DesktopEnv

    main

    OSWorld scripts use DesktopEnv to create VMs from specific snapshots.

    • Using specific snapshots: When instantiating DesktopEnv, use the snapshot_name parameter to specify which snapshot to boot from.
    • Custom snapshots: If you create a new snapshot of your VM for your own experiments, ensure you pass that specific snapshot name to the DesktopEnv constructor.
    • File system errors: If the VM encounters a "The root file system on <path> requires a manual fsck" error, reset the VM to its previous snapshot.
  2. Supported Models and Grounding Requirements

    main

    Agent S supports various inference providers including Azure OpenAI, Anthropic, Gemini, Open Router, and vLLM. Detailed model information can be found in models.md.

    Required Grounding Model: For optimal performance, it is highly recommended to use UI-TARS-1.5-7B (hosted on Hugging Face Inference Endpoints or another provider) as the grounding model.

  3. Use Agent-S for GUI automation tasks

    main

    Agent-S can be used to automate desktop applications through natural language commands. Common use cases include basic navigation, form filling, multi-step workflows, and application interaction.

    Parameters:

    • task (required): Natural language description of the GUI task.
    • max_steps (optional): Maximum steps the agent can take (default: 15).
    • enable_reflection (optional): Enables self-reflection for improved performance (default: true).
    # Basic navigation
    agent_s_task(task="Open Finder and create a new folder called 'Reports'")
    
    # Form filling
    agent_s_task(task="Open TextEdit, create a new document, and type 'Hello World'")
    
    # Multi-step workflows
    agent_s_task(task="Open Chrome, search for 'Python tutorials', and bookmark the first result")
    
    # Application interaction
    agent_s_task(task="Open System Preferences and check the current display resolution")
  4. Configure Python for Agent S2.5 `set_cell_values` functionality

    main

    Agent S2.5 uses a grounding function set_cell_values that requires the soffice CLI and the unotools library. Because the WAA VM defaults to a GIMP Python 2.x environment, you must configure the system to use LibreOffice's Python (3.10+) instead.

    Step 1: Capture existing dependencies

    1. Connect to the VM.
    2. Open a terminal and navigate to the Desktop directory.
    3. Run pip freeze > requirements.txt to save current libraries.

    Step 2: Configure System Path

    1. Find the LibreOffice Python path using where python inside the VM.
    2. Open Environment Variables in the Windows Search bar.
    3. Edit the Path variable under System variables.
    4. Add the LibreOffice Python path and ensure it is above the GIMP Python path.
    5. Verify by running soffice and checking if import uno works in a Python shell.

    Step 3: Install dependencies for LibreOffice Python

    1. Since LibreOffice Python lacks pip, download get-pip.py from https://bootstrap.pypa.io/get-pip.py.
    2. Run python get-pip.py (ensuring you are using the LibreOffice Python).
    3. Install the captured requirements: pip install -r requirements.txt.

    Step 4: Update WAA Source Code

    In the WAA repository, locate the Python controller and update the command list to use the absolute path of the LibreOffice Python to ensure the Flask server uses the correct version:

    Change: command_list = ["python", "-c", self.pkgs_prefix.format(command=command)] To: command_list = ["/absolute/path/to/libreoffice/python", "-c", self.pkgs_prefix.format(command=command)]

    # Inside VM Desktop directory
    pip freeze > requirements.txt
    
    # After installing pip for LibreOffice Python
    pip install -r requirements.txt
  5. Configure LibreOffice Python for `set_cell_values`

    main

    Agent S2 uses the set_cell_values grounding function, which requires soffice CLI and the unotools library. Because the default VM Python is a GIMP Python (2.x), you must configure the environment to use LibreOffice's Python (3.10+).

    Step 1: Prepare Requirements

    1. Connect to the VM.
    2. Open a terminal and run pip freeze > requirements.txt from the Desktop directory to capture current dependencies.

    Step 2: Configure System Path

    1. Find the LibreOffice python.exe path (use where python inside the VM).
    2. Open Environment Variables in the Windows search bar.
    3. Edit the Path under System variables.
    4. Add the LibreOffice Python path to the list, ensuring it is above the GIMP Python path.
    5. Verify by running soffice and checking if import uno works in a Python script.

    Step 3: Install Dependencies for LibreOffice Python

    1. Download get-pip.py from https://bootstrap.pypa.io/get-pip.py.
    2. Run python get-pip.py using the LibreOffice Python executable.
    3. Install the captured requirements: pip install -r requirements.txt.

    Step 4: Update WAA Code

    In the WAA repository, locate the file src/win-arena-container/client/desktop_env/controllers/python.py and update the command_list assignment to use the absolute path to the LibreOffice Python executable:

    # Change this:
    command_list = ["python", "-c", self.pkgs_prefix.format(command=command)]
    
    # To this:
    command_list = ["absolute/path/to/libreoffice/python", "-c", self.pkgs_prefix.format(command=command)]
  6. Install the Agent-S OpenClaw Integration

    main

    To integrate Agent-S with OpenClaw for autonomous GUI automation, follow these steps:

    1. Install Required Software:
      • Install the gui-agents package: pip install gui-agents
      • Install tesseract for OCR:
        • macOS: brew install tesseract
        • Linux: sudo apt install tesseract-ocr
    2. Deploy to OpenClaw Skills Folder: Copy the integration directory to your OpenClaw workspace:
      cp -r integrations/openclaw ~/.openclaw/workspace/skills/agent-s
    3. Set Permissions: Make the entry point scripts executable:
      chmod +x ~/.openclaw/workspace/skills/agent-s/agent_s_task
      chmod +x ~/.openclaw/workspace/skills/agent-s/agent_s_wrapper.py
    4. Verify Installation: Ensure the agent_s executable is in your PATH:
      which agent_s
    cp -r integrations/openclaw ~/.openclaw/workspace/skills/agent-s
    chmod +x ~/.openclaw/workspace/skills/agent-s/agent_s_task
    chmod +x ~/.openclaw/workspace/skills/agent-s/agent_s_wrapper.py
  7. Use the `gui_agents` SDK

    main

    To integrate Agent S3 into your own Python applications, use the gui_agents SDK. The workflow involves defining engine parameters for both the main model and the grounding model, initializing an OSWorldACI grounding agent, and then creating an AgentS3 instance.

    Core Components

    • AgentS3: The main agent class.
    • OSWorldACI: The grounding agent that translates actions into executable Python code.
    • LocalEnv: (Optional) Enables the local coding environment.

    Implementation Steps

    1. Define engine_params for the main model (provider, model, base_url, api_key, temperature).
    2. Define engine_params_for_grounding for the grounding model (engine_type, model, base_url, api_key, grounding_width, grounding_height).
    3. Initialize OSWorldACI with the engine parameters and platform.
    4. Initialize AgentS3 with the grounding agent and platform.
    5. Call agent.predict(instruction, observation) where observation is a dictionary containing a screenshot (as bytes).
    import pyautogui
    import io
    from gui_agents.s3.agents.agent_s import AgentS3
    from gui_agents.s3.agents.grounding import OSWorldACI
    from gui_agents.s3.utils.local_env import LocalEnv
    from dotenv import load_dotenv
    
    load_dotenv()
    
    # 1. Setup Parameters
    current_platform = "linux"  # "darwin", "windows"
    
    engine_params = {
      "engine_type": "openai",
      "model": "gpt-5-2025-08-07",
      "api_key": "YOUR_API_KEY"
    }
    
    engine_params_for_grounding = {
      "engine_type": "huggingface",
      "model": "ui-tars-1.5-7b",
      "base_url": "http://localhost:8080",
      "grounding_width": 1920,
      "grounding_height": 1080,
    }
    
    # 2. Initialize Agents
    enable_local_env = False
    local_env = LocalEnv() if enable_local_env else None
    
    grounding_agent = OSWorldACI(
        env=local_env,
        platform=current_platform,
        engine_params_for_generation=engine_params,
        engine_params_for_grounding=engine_params_for_grounding,
        width=1920,
        height=1080
    )
    
    agent = AgentS3(
        engine_params,
        grounding_agent,
        platform=current_platform,
        max_trajectory_length=8,
        enable_reflection=True
    )
    
    # 3. Run Inference
    screenshot = pyautogui.screenshot()
    buffered = io.BytesIO()
    screenshot.save(buffered, format="PNG")
    screenshot_bytes = buffered.getvalue()
    
    obs = {
      "screenshot": screenshot_bytes,
    }
    
    instruction = "Close VS Code"
    info, action = agent.predict(instruction=instruction, observation=obs)
    
    # Execute the returned action
    exec(action[0])
  8. Configure LLM API Keys

    main

    Agent S requires LLM API keys (e.g., OpenAI, Anthropic, Azure OpenAI, or vLLM). You can set these as environment variables in your shell configuration (.bashrc or .zshrc) or directly within your Python script.

    Shell configuration (Linux/macOS):

    export OPENAI_API_KEY=<YOUR_API_KEY>

    Python configuration:

    import os
    os.environ["OPENAI_API_KEY"] = "<YOUR_API_KEY>"
  9. Manually Install Office Apps in WAA VM

    main

    The WAA initial setup often fails to install Office applications because the links in tools_config.json may be broken. To fix this, manually install LibreOffice inside the VM:

    1. Start the VM using run-local.sh.
    2. Access the VM via https://localhost:8006.
    3. (Optional) To prevent the agent from interfering while you work, temporarily override the execution in run.py with import time; time.sleep(10000).
    4. Inside the VM, download the latest LibreOffice from the official download page.
    5. Run the setup wizard and complete the installation.
    6. Crucial: Delete the downloaded *.msi file from the VM after installation.
    7. Verify by opening LibreOffice Writer and Calc.
    # Temporary override in run.py to prevent agent interference
    import time
    time.sleep(10000)
  10. Setup Perplexica for Web Retrieval

    main

    To enable web-knowledge retrieval, you must set up Perplexica using Docker.

    1. Navigate to the Perplexica directory and initialize submodules:
      cd Perplexica
      git submodule update --init
    2. Rename sample.config.toml to config.toml and configure your API keys (OPENAI, OLLAMA, GROQ, or ANTHROPIC).
    3. Start the service:
      docker compose up -d
    4. Export the PERPLEXICA_URL environment variable using the port specified in your config.toml:
      export PERPLEXICA_URL=http://localhost:{port}/api/search
    export PERPLEXICA_URL=http://localhost:{port}/api/search