OpenEnv

repository·main·Indexed 25 days ago

https://github.com/huggingface/openenv

A unified framework for creating, deploying, and using isolated execution environments for agentic Reinforcement Learning (RL) training. OpenEnv uses Gymnasium-style APIs to provide a standardized interface for agents to interact with complex environments, including the Agent World Model (AWM) and Atari environments.

Tokens
276.9K
Snippets
633
Records
1.1K
Agent score
81%

What's inside openenv

  1. Overview of Runtime Providers

    main

    A Runtime Provider is responsible for starting an environment server and returning a base_url that an EnvClient uses to connect. OpenEnv uses a ContainerProvider contract, allowing you to switch between local environments (like Docker) and cloud sandboxes (like Daytona or Modal) with minimal code changes.

    Available Providers

    ProviderBackendInstall Command
    LocalDockerProviderLocal Docker daemon(core)
    DockerSwarmProviderDocker Swarm cluster(core)
    UVProviderLocal process via uv (no container)(core)
    DaytonaProviderDaytona cloud sandboxespip install openenv[daytona]
    ACASandboxProviderAzure Container Apps Sandboxespip install openenv[aca]
    ModalProviderModal sandboxespip install openenv[modal]
    KubernetesProviderKubernetes cluster(planned)

    Note: Cloud provider SDKs are optional extras and are imported lazily. Core providers are re-exported from the runtime package, while cloud providers must be imported from their specific modules.

  2. Overview of OpenEnv: Agentic Execution Environments

    main

    OpenEnv is a unified framework designed for building, deploying, and interacting with isolated execution environments for agentic reinforcement learning. It is optimized for tasks like code generation, web browsing, and game playing.

    Key features include:

    • Gymnasium-Style APIs: Uses familiar step(), reset(), and state() interfaces for integration with RL frameworks.
    • Container-First Design: Environments are packaged as containers for reproducible deployment.
    • HTTP-Native: Environments can be deployed as HTTP services for distributed training and remote execution.
    • Secure Isolation: Provides sandboxed environments to run untrusted agent code safely.
    • Rich Environment Library: Includes pre-built environments for various domains (games, coding, web, etc.).
    • CLI Tools: Provides a command-line interface for managing and deploying environments.
  3. Overview of the Grid World Environment dynamics

    main

    The Grid World environment is a deterministic 5x5 square grid designed for Reinforcement Learning (RL) prototyping.

    Environment Specifications:

    • Grid Size: 5x5
    • Agent Start: (0,0) (top-left)
    • Goal Position: (4,4) (bottom-right)
    • Actions: UP, DOWN, LEFT, RIGHT
    • Dynamics: Deterministic. Actions move the agent one step in the chosen direction. If an action would move the agent off the grid, the agent remains in its current cell.
    • Reward Function (Sparse):
      • -0.1 per step (living cost).
      • +1.0 for reaching the goal at (4,4).
    • Termination: The episode ends when the agent reaches the goal.
  4. Overview of the OpenEnv Framework

    main
    OpenEnv is an end-to-end framework designed for creating, deploying, and using isolated execution environments for agentic Reinforcement Learning (RL) training. It follows a client-server architecture where environments are hosted as FastAPI servers within Docker containers. Clients interact with these environments through type-safe HTTP APIs, providing a standardized interface for agentic tasks, code execution, and computational workloads.
  5. Overview of the OpenApp Environment

    main

    The OpenApp environment is a web application simulation ecosystem built on top of BrowserGym and the OpenApps framework. It allows agents to interact with a suite of simulated web applications using browser-based actions like clicking, filling forms, navigating, and scrolling.

    Key Features:

    • Multiple Apps: Includes calendar, todo list, messenger, and map applications.
    • Browser-Based Actions: Supports standard UI interactions.
    • Task-Based Evaluation: Supports optional task goals with automatic reward calculation.
    • Configurable: Allows customization of app configurations and behaviors.

    Ideal Use Cases:

    • Training and evaluating UI agents.
    • Testing web automation strategies.
    • Researching human-computer interaction.
    • Developing multimodal agents.
  6. Overview of the Pelican SVG Environment

    main

    The Pelican SVG Environment is a reproducible, executable target for testing and training models on blind vector drawing. The model is tasked with generating an SVG of an animal riding a vehicle without seeing the result, requiring it to maintain spatial arrangements in its latent space.

    It is designed for:

    • Evaluation: Scoring frontier models via HF Inference Providers using examples/pelican_svg_eval.py.
    • Training: Running reinforcement learning (e.g., GRPO) against the environment using TRL via examples/pelican_svg_grpo.py.

    While inspired by Simon Willison's 'pelican riding a bicycle' prompt, this environment expands the task catalogue to include 30 different combinations of animals and vehicles to ensure the scorer measures drawing ability rather than memorized patterns.

  7. Explore Community Environments

    main

    OpenEnv supports various community-maintained environments designed for specific agent training and evaluation tasks. Two notable examples include:

    • RLVE Gym: A suite of 400 environments that procedurally generate reasoning problems for Language Model (LM) training. It features configurable difficulty levels.
    • Reasoning Core: Provides formally verifiable symbolic reasoning tasks covering domains such as logic, mathematics, planning, and syntax.

    You can find detailed documentation and hosted versions for these environments on Hugging Face Spaces.

  8. Project Structure of OpenCode Environment

    main

    The opencode_env package is organized into several functional modules:

    • Client & Models: client.py provides the OpenCodeEnv (based on MCPToolClient), while models.py defines data structures like RolloutResult, RolloutTurn, and OpenCodeState.
    • Core Logic: config.py handles configuration via OpenCodeConfig, task.py defines OpenCodeTask, and opencode_runtime.py manages the opencode.json builder and commands.
    • Server Implementation: Located in server/, this includes the FastAPI application (app.py), the MCPEnvironment which exposes the run_rollout tool, and a Gradio-based web UI (gradio_ui.py).
    • Sandbox Backend: The sandbox/ directory contains implementations for sandboxed execution, including an E2B implementation (e2b.py) and interception logic for logprob capture (interception.py).
    • CLI Utilities: harness.py provides OpenCodeSession and OpenCodeSessionFactory for CLI-only usage.
  9. Use the REPL Environment for Python execution

    main

    The repl_env provides a Python REPL environment designed for Recursive Language Model (RLM) execution. It allows a model to inspect context, execute Python code with persistent state across turns, and call LLM/RLM queries directly from within the REPL.

    Key capabilities include:

    • Executing Python code.
    • Calling llm_query(...) or rlm_query(...) for recursive child runs.
    • Terminating with FINAL(...), FINAL_VAR(...), or by setting answer = {"content": ..., "ready": True}.
    import asyncio
    from repl_env import REPLEnv
    
    async def main():
        async with REPLEnv(base_url="http://127.0.0.1:8000") as env:
            await env.reset(context="alpha beta gamma", task_prompt="Count the words")
            await env.execute("count = len(context.split())")
            await env.execute("print(FINAL(count))")
    
    asyncio.run(main())
  10. Supported OpenSpiel Games

    main

    The environment supports 6 games across two categories:

    Single-Player Games (No Opponent)

    • catch: Move horizontally to catch a falling ball.
    • cliff_walking: Navigate grid without falling off cliff.
    • 2048: Classic tile-merging puzzle.
    • blackjack: Simplified blackjack (HIT/STAND only).

    Multi-Player Games (with Bot Opponent)

    • tic_tac_toe: Classic 3x3 game.
    • kuhn_poker: 2-player simplified poker (game theory benchmark).
  11. OpenEnv Walkthrough Overview

    main
    OpenEnv provides a hands-on framework for building, deploying, and scaling Reinforcement Learning (RL) environments. The project is structured into several learning modules covering fundamentals, deployment strategies, scaling infrastructure, and training workflows.
  12. Understand the core abstractions in openenv.core

    main

    The openenv.core package is the foundation for building and running agentic execution environments. It is organized into several functional areas:

    • Server: Provides primitives for environment servers, including interfaces for Message, ModelTokenizer, Transform, and Environment. It also includes types for server modes, health status, and communication (e.g., StepRequest, Observation, Action).
    • Clients: Offers various client implementations to interact with environments, including EnvClient (base), SyncEnvClient (synchronous), GenericEnvClient, and specialized LLMClient implementations (e.g., OpenAIClient, AnthropicClient).
    • MCP (Model Context Protocol): Implements MCP-backed environments via MCPEnvironment and provides specialized MCP types and clients (MCPClientBase, MCPToolClient) for tool-calling workflows.
    • Rubrics: Provides a framework for evaluating agent performance using Rubric implementations, including containers like Sequential, WeightedSum, and LLMJudge for LLM-based evaluation.
    • Container Providers: Supports running environments across different runtimes via providers like LocalDockerProvider, DockerSwarmProvider, UVProvider, ModalProvider, and others.

    For detailed implementation guides, refer to the building an environment guide.