Xingyao Wang 343cc8710f [remote runtime] poll runtime info to wait until alive instead of using long timeout (#4334) 1 年之前
..
browser 178dbfaf4a Run pre-commit (#4163) 1 年之前
builder 5097c4fe71 [Runtime] Audit HTTP Retry timeouts (#4282) 1 年之前
client 4c5e2a339f Feat: Async Goodies for OpenHands (#4347) 1 年之前
e2b c32cec7f89 (enh) send status messages to UI during startup (#3771) 1 年之前
plugins e81c5597d6 feat(runtime): use micromamba instead of mamba and fix build issue (#4154) 1 年之前
remote 343cc8710f [remote runtime] poll runtime info to wait until alive instead of using long timeout (#4334) 1 年之前
utils 5097c4fe71 [Runtime] Audit HTTP Retry timeouts (#4282) 1 年之前
README.md dc418e7b71 Update README.md for runtime (#4015) 1 年之前
__init__.py 8b1f207d39 feat: support remote runtime (#3406) 1 年之前
runtime.py 4c5e2a339f Feat: Async Goodies for OpenHands (#4347) 1 年之前

README.md

OpenHands Runtime

Introduction

The OpenHands Runtime folder contains the core components responsible for executing actions and managing the runtime environment for the OpenHands project. This README provides an overview of the main components and their interactions. You can learn more about how the runtime works in the EventStream Runtime documentation.

Main Components

1. runtime.py

The runtime.py file defines the Runtime class, which serves as the primary interface for agent interactions with the external environment. It handles various operations including:

  • Bash sandbox execution
  • Browser interactions
  • Filesystem operations
  • Environment variable management
  • Plugin management

Key features of the Runtime class:

  • Initialization with configuration and event stream
  • Asynchronous initialization (ainit) for setting up environment variables
  • Action execution methods for different types of actions (run, read, write, browse, etc.)
  • Abstract methods for file operations (to be implemented by subclasses)

2. client/client.py

The client.py file contains the RuntimeClient class, which is responsible for executing actions received from the OpenHands backend and producing observations. This client runs inside a Docker sandbox.

Key features of the RuntimeClient class:

  • Initialization of user environment and bash shell
  • Plugin management and initialization
  • Execution of various action types (bash commands, IPython cells, file operations, browsing)
  • Integration with BrowserEnv for web interactions

Workflow Description

  1. Initialization:

    • The Runtime is initialized with configuration and event stream.
    • Environment variables are set up using ainit method.
    • Plugins are loaded and initialized.
  2. Action Handling:

    • The Runtime receives actions through the event stream.
    • Actions are validated and routed to appropriate execution methods.
  3. Action Execution:

    • Different types of actions are executed:
      • Bash commands using run method
      • IPython cells using run_ipython method
      • File operations (read/write) using read and write methods
      • Web browsing using browse and browse_interactive methods
  4. Observation Generation:

    • After action execution, corresponding observations are generated.
    • Observations are added to the event stream.
  5. Plugin Integration:

    • Plugins like Jupyter and AgentSkills are initialized and integrated into the runtime.
  6. Sandbox Environment:

    • The RuntimeClient sets up a sandboxed environment inside a Docker container.
    • User environment and bash shell are initialized.
    • Actions received from the OpenHands backend are executed in this sandboxed environment.
  7. Browser Interactions:

    • Web browsing actions are handled using the BrowserEnv class.

Important Notes

  • The runtime uses asynchronous programming (asyncio) for efficient execution.
  • Environment variables can be added dynamically to both IPython and Bash environments.
  • File operations and command executions are abstracted, allowing for different implementations in subclasses.
  • The system uses a plugin architecture for extensibility.
  • All interactions with the external environment are managed through the Runtime, ensuring a controlled and secure execution environment.

Runtime Types

EventStream Runtime

The EventStream Runtime is designed for local execution using Docker containers:

  • Creates and manages a Docker container for each session
  • Executes actions within the container
  • Supports direct file system access and local resource management
  • Ideal for development, testing, and scenarios requiring full control over the execution environment

Key features:

  • Real-time logging and debugging capabilities
  • Direct access to the local file system
  • Faster execution due to local resources

This is the default runtime used within OpenHands.

Remote Runtime

The Remote Runtime is designed for execution in a remote environment:

  • Connects to a remote server running the RuntimeClient
  • Executes actions by sending requests to the remote client
  • Supports distributed execution and cloud-based deployments
  • Ideal for production environments, scalability, and scenarios where local resource constraints are a concern

Key features:

  • Scalability and resource flexibility
  • Reduced local resource usage
  • Support for cloud-based deployments
  • Potential for improved security through isolation

At the time of this writing, this is mostly used in parallel evaluation, such as this example for SWE-Bench.

Related Components

  • The runtime interacts closely with the event system defined in the openhands.events module.
  • It relies on configuration classes from openhands.core.config.
  • Logging is handled through openhands.core.logger.

This section provides an overview of the OpenHands Runtime folder. For more detailed information on specific components or usage, please refer to the individual files and their docstrings.