-
Notifications
You must be signed in to change notification settings - Fork 144
add HuggingFace-style AutoEnv and AutoAction classes #222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
I just noticed that there is some file in |
|
Very cool PR @wukaixingxp ! There are a few things that concern me, which I think we should discuss / solve at a high level before going into the details.
Just an idea, but due to the challenges above. It might be best to solve this problem on the client side first, before moving on to the server side. In principle, a declared env like |
Thanks for your feedback! It is really helpful! I will remove the _manifest and use the |
@wukaixingxp In general, it's best to interface with hub repos via their |
|
@burtenshaw do you want to take another look? I managed to get HF space working and added some test cases from envs import AutoEnv, AutoAction
# Load from HuggingFace Space using repo ID
env = AutoEnv.from_name("wukaixingxp/coding-env-test")
# Reset environment
observation = env.reset()
print(f"Reset observation: {observation}")
# Get action class
CodeAction = AutoAction.from_name("wukaixingxp/coding-env-test")
# Create and execute action
action = CodeAction(code="print('Hello!')")
result = env.step(action) # Returns StepResult object, not tuple
# Access result properties
print(f"Observation: {result.observation}")
print(f"Reward: {result.reward}")
print(f"Done: {result.done}")
# Clean up
env.close()logs: |
burtenshaw
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wukaixingxp Nice work! This is looking much closer. I've done a first high level review on the structure. Mainly just to bring it inline with #232 and decouple this feature from src/envs completely.
This is the high level results, but I've also commented on files to clarify:
- merge
releasefor the structural changes from #232 so that the import can befrom openenv import AutoWhatever. - create a module in
src/openenv/autoand expose the auto classes at the library root so the above works. - rename
from_nametofrom_hub. This is more consistent and will explain to users what they are calling.
Let me know if you need a hand with merging #232.
examples/auto_env_example.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this from the PR and add an md file in docs that explains how to use it.
src/envs/__init__.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This directory will be removed in #232 .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After merging #232 this will need to reside at src/openenv/auto/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise, after merging #232 this will need to reside at src/openenv/auto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise, after merging #232 this will need to reside at src/openenv/auto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice.
|
@burtenshaw sure.. I wonder if the #232 will be merged to main soon so I can rebase my change to that? |
Yeah. That would be great. We're waiting for reviews and targeting #239 in the meantime. |
|
@burtenshaw do you want to keep |
|
@wukaixingxp Sure. #232 is now up to date with main. |
Add HuggingFace-style auto-discovery system for environments: - AutoEnv.from_hub(name): Factory to auto-detect and instantiate environment clients - AutoAction.from_hub(name): Factory to load action classes for environments - EnvironmentDiscovery: Package discovery using importlib.metadata and openenv.yaml manifests - Support for local packages (openenv-*) and HuggingFace Hub Includes comprehensive tests and documentation.
Adds improved handling for factory functions in load_environment_metadata, using inspect.isclass/isfunction for more robust type detection.
This commit addresses the failing CI/CD tests in PR meta-pytorch#222 by: 1. **Fix importlib cache invalidation**: Added `importlib.invalidate_caches()` call in `_discover_installed_packages()` to ensure newly installed packages are detected after runtime pip installs. Previously, when packages were installed via `_install_from_path()`, the importlib.metadata cache wasn't invalidated, causing discovery to fail. 2. **Fix discovery refresh after install**: In `_ensure_package_from_hub()`, added missing `discover(use_cache=False)` call after installing a new package. This ensures the discovery system refreshes and picks up the newly installed environment. 3. **Skip integration tests in CI**: Updated `.github/workflows/test.yml` to skip tests marked with `integration`, `network`, or `docker` markers. These tests require external resources (HuggingFace Spaces, Docker daemon) that aren't available or reliable in CI environments. 4. **Add pytest markers configuration**: Added `[tool.pytest.ini_options]` to `pyproject.toml` with proper marker definitions to eliminate pytest warnings and document test categories. The root cause was that after `pip install -e` at runtime, Python's importlib.metadata.distributions() iterator didn't pick up the newly installed package without explicit cache invalidation. This caused AutoEnv.from_hub() to fail with "No OpenEnv environments found" error in CI.
| from __future__ import annotations | ||
|
|
||
| from openenv.core.env_server.types import Action, Observation, State | ||
| from dataclasses import dataclass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's best to move this to pydantic whilst we're working on it.
|
Hey @wukaixingxp, I've tested the install process from spaces and I think we should take a slightly different approach. At the moment, iiuc, the module downloads the space repo installs with pip. Some issues with this are:
Based on these, I would recommend changing the logic to avoid download and use |
AutoEnv & AutoAction: Auto-Discovery System for OpenEnv
Overview
The auto-discovery system provides two main classes:
AutoEnv: Automatically loads and instantiates environment clientsAutoAction: Automatically loads action classes for environmentsBoth classes work with:
pip install openenv-<env-name>Quick Start
Basic Usage
Instead of manually importing specific environment classes:
You can now use the auto-discovery API:
AutoEnv API
AutoEnv.from_env(name, **kwargs)Create an environment client from a name or HuggingFace Hub repository.
Parameters:
name: Environment name or Hub repo ID"coding","coding-env","coding_env""meta-pytorch/coding-env","username/env-name"base_url: Optional base URL for HTTP connectiondocker_image: Optional Docker image name (overrides default)container_provider: Optional container providerwait_timeout: Timeout for container startup (default: 30s)env_vars: Optional environment variables for the container**kwargs: Additional arguments passed to the client classReturns: Instance of the environment client class
Examples:
AutoEnv.list_environments()List all available environments.
AutoEnv.get_env_info(name)Get detailed information about an environment.
AutoEnv.get_env_class(name)Get the environment class (not an instance).
AutoAction API
AutoAction.from_env(name)Get the Action class from an environment name or HuggingFace Hub repository.
Parameters:
name: Environment name or Hub repo IDReturns: Action class (not an instance!)
Examples:
AutoAction.from_hub(env_name)Alias for
from_env()for backward compatibility.AutoAction.list_actions()List all available action classes.
AutoAction.get_action_info(name)Get detailed information about an action class.
HuggingFace Hub Integration
Loading from HuggingFace Spaces
AutoEnv can automatically connect to environments running on HuggingFace Spaces:
The system automatically:
username/repo-name)https://username-repo-name.hf.space)Complete Workflow Example
Here's a complete example showing the auto-discovery workflow: