-
Notifications
You must be signed in to change notification settings - Fork 113
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
…from_image to from_name
## Summary
Refactored AutoEnv and AutoAction APIs to use a simpler, more intuitive naming scheme:
- `AutoEnv.from_docker_image()` → `AutoEnv.from_name()`
- `AutoAction.from_image()` → `AutoAction.from_name()`
- `AutoEnv.from_name()` (old, returned class) → `AutoEnv.get_env_class()`
## Changes
### API Updates
- **AutoEnv.from_name()**: Now accepts simplified environment names
- Supports multiple formats: "coding-env", "coding", "coding-env:v1.0"
- Automatically appends ":latest" tag if not provided
- Automatically adds "-env" suffix if not present
- **AutoAction.from_name()**: Mirrors AutoEnv behavior
- Accepts "coding-env", "coding", or "coding-env:v1.0"
- Returns the Action class for the environment
- **AutoEnv.get_env_class()**: Renamed from old `from_name()` to avoid confusion
- Returns environment class (not an instance) by environment key
### Files Modified
- `src/envs/auto_env.py`: Renamed methods and updated docstrings
- `src/envs/auto_action.py`: Renamed methods and updated docstrings
- `src/envs/__init__.py`: Updated package documentation
- `examples/auto_env_example.py`: Updated all examples to use new API
- `tests/envs/test_auto_integration.py`: Updated tests and fixed assertions
## Benefits
- **Simpler API**: Users can write `AutoEnv.from_name("coding-env")` instead of `AutoEnv.from_docker_image("coding-env:latest")`
- **Flexible**: Accepts multiple name formats (with/without suffix and tag)
- **Consistent**: Both AutoEnv and AutoAction follow the same pattern
- **Clearer**: Method names better reflect what they do
## Testing
All 10 integration tests pass ✅
## Migration Guide
```python
# Old API
env = AutoEnv.from_docker_image("coding-env:latest")
Action = AutoAction.from_image("coding-env:latest")
# New API (simpler!)
env = AutoEnv.from_name("coding-env")
Action = AutoAction.from_name("coding-env")
```
## Related
Part of the larger AutoEnv refactoring effort to improve developer experience.
- Removed from_hub() method as HuggingFace Hub integration is planned for future PR - Updated class docstrings to remove from_hub references - Updated error messages in __init__ - All tests still pass (10/10 integration tests) HuggingFace Hub integration will be added in a future PR when ready.
- Fixed test_infer_with_underscores: BrowsergymEnv → BrowserGymEnv - Fixed test_infer_special_case_sumo_rl: SumoRlEnv → SumoRLEnv - Fixed test_infer_dipg_safety: DipgSafetyEnv → DIPGSafetyEnv, DipgSafetyAction → DIPGAction - Fixed test_create_from_complex_env: BrowsergymEnv → BrowserGymEnv These tests were expecting simplified class names, but the actual classes in the codebase use acronyms (Gym, RL, DIPG). The inference algorithm correctly produces the actual class names that exist in the code. ✅ All 65 tests now pass!
Make AutoAction API consistent with AutoEnv by removing from_env(). ## Rationale - AutoAction.from_env() was redundant with from_name() - Both methods did the exact same thing (just different input handling) - AutoEnv only has from_name(), not from_env() - Having one clear method is better than two redundant ones ## Changes - Removed AutoAction.from_env() method (33 lines) - Updated all examples to use from_name() - Updated all tests to use from_name() - Updated docstrings and error messages ## API Consistency Both AutoEnv and AutoAction now have matching APIs: - from_name(name) - Main method (flexible input) - get_*_class/info() - Get class/info - list_*() - List all ## Testing ✅ All 10 integration tests pass ✅ from_name() handles all cases: 'coding', 'coding-env', 'coding-env:latest' This makes the API cleaner and easier to learn!
|
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 |
AutoEnv & AutoAction: Auto-Discovery System for OpenEnv
🎯 Overview
Based on the discussion in #171, this PR introduces AutoEnv and AutoAction - a HuggingFace-style auto-discovery system that makes working with OpenEnv environments dramatically simpler and more scalable. Instead of manually maintaining registries, environments are now automatically discovered and loaded on-demand.
Key Innovation: Environments self-describe their structure through
openenv.yamlmanifests or conventional directory layouts, enabling OpenEnv to scale to thousands of environments on platforms like Hugging Face Hub.🚀 Before & After
Before (Manual approach)
After (Auto-discovery approach)
📦 What's Included
1. 🔍 Auto-Discovery System (
src/envs/_discovery.py)Core discovery engine
src/envs/directory.discovery_cache.jsonwith freshness validationExample:
Discovered environments:
2. 📋 Manifest Parser (
src/envs/_manifest.py)Environment metadata system
openenv.yamlmanifest filespyproject.tomlExample
openenv.yaml:Convention-based inference (when
openenv.yamlmissing):3. 🤖 AutoEnv Class (
src/envs/auto_env.py)Smart environment loader
Core Methods:
AutoEnv.from_name(name)- Create environment from simple nameAutoEnv.get_env_class(name)- Get environment class (not instance)AutoEnv.list_environments()- Show all available environmentsAutoEnv.get_env_info(name)- Get detailed environment metadataFeatures:
"coding","coding-env","coding-env:v1.0"Example:
4. 🎬 AutoAction Class (
src/envs/auto_action.py)Smart action class loader
Core Methods:
AutoAction.from_name(name)- Get action class from nameAutoAction.from_env(env_name)- Get action class by environment keyAutoAction.list_actions()- Show all available action classesAutoAction.get_action_info(name)- Get action class metadataExample:
5. ✅ Comprehensive Testing
949 lines across 3 test files
tests/envs/test_manifest.py- Manifest parser tests (33 tests)tests/envs/test_discovery.py- Discovery system tests (32 tests)tests/envs/test_auto_integration.py- Integration tests (10 tests)Test Results: ✅ 65/65 tests passing (100%!)
6. 📚 Examples & Documentation
examples/auto_env_example.py- Comprehensive usage examples (317 lines)src/envs/__init__.py🎨 Key Features
1. Flexible Name Formats
2. Smart Caching
.discovery_cache.json3. Excellent Error Messages
4. Type-Safe Metadata
📊 Architecture
🔧 Implementation Details
Discovery Algorithm
src/envs/directory, skip hidden dirsopenenv.yaml, fallback to conventions.discovery_cache.jsonwith mtimesClass Name Inference
Performance Optimizations
📈 Benefits
✅ Scalability: No manual registry maintenance needed
✅ Decentralized: Environments self-describe their structure
✅ Developer-Friendly: Clean, simple API following HuggingFace conventions
✅ Performance: Caching prevents repeated filesystem scans
✅ Type-Safe: Rich metadata with clear types
✅ Extensible: Easy to add new discovery sources (pip packages, HF Hub)
✅ Excellent DX: Clear errors with helpful suggestions
🎯 Use Cases
1. Quick Prototyping
2. Dynamic Environment Loading
3. Environment Discovery
4. CI/CD Testing
📋 Files Changed
New Files (5)
src/envs/_discovery.py(413 lines) - Auto-discovery enginesrc/envs/_manifest.py(378 lines) - Manifest parsersrc/envs/auto_env.py(470 lines) - AutoEnv classsrc/envs/auto_action.py(365 lines) - AutoAction classexamples/auto_env_example.py(317 lines) - Usage examplesNew Test Files (3)
tests/envs/test_discovery.py(421 lines) - Discovery teststests/envs/test_manifest.py(393 lines) - Manifest teststests/envs/test_auto_integration.py(135 lines) - Integration testsModified Files
src/envs/__init__.py- Package documentationsrc/envs/browsergym_env/openenv.yaml- Example manifestsrc/envs/coding_env/openenv.yaml- Example manifestGenerated Files
src/envs/.discovery_cache.json- Discovery cache (should be gitignored)🧪 Testing
Test Coverage
Test Breakdown:
All tests pass successfully:
Manual Testing
Logs:
🚦 Migration Guide
For Library Users
No migration needed! The old API still works:
For Environment Developers
Optional but recommended: Add
openenv.yamlto your environment:If you follow the standard directory structure,
openenv.yamlis optional!🔮 Future Enhancements
Planned Features
trust_remote_code"python" → "coding"style aliasesopenenv.yamlPotential Extensions
🎓 Design Philosophy
This implementation follows several key principles:
openenv.yamlif you follow conventionsopenenv.yamladds features but isn't required📝 Notes
Cache File
The
.discovery_cache.jsonfile is auto-generated and should be added to.gitignore:Backward Compatibility
🙏 Acknowledgments
This implementation was inspired by: