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
-
Initialization:
- The
Runtimeis initialized with configuration and event stream. - Environment variables are set up using
ainitmethod. - Plugins are loaded and initialized.
- The
-
Action Handling:
- The
Runtimereceives actions through the event stream. - Actions are validated and routed to appropriate execution methods.
- The
-
Action Execution:
- Different types of actions are executed:
- Bash commands using
runmethod - IPython cells using
run_ipythonmethod - File operations (read/write) using
readandwritemethods - Web browsing using
browseandbrowse_interactivemethods
- Bash commands using
- Different types of actions are executed:
-
Observation Generation:
- After action execution, corresponding observations are generated.
- Observations are added to the event stream.
-
Plugin Integration:
- Plugins like Jupyter and AgentSkills are initialized and integrated into the runtime.
-
Sandbox Environment:
- The
RuntimeClientsets 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.
- The
-
Browser Interactions:
- Web browsing actions are handled using the
BrowserEnvclass.
- Web browsing actions are handled using the
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.
Related Components
- The runtime interacts closely with the event system defined in the
openhands.eventsmodule. - 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.