Register an environment class. This will: - Create an environment instance - Create an `EnvironmentConfig` - Store it as the current config and append to version history - Register the version in `version_manager` and FAISS index Args
(self,
env_cls: Type[Environment],
env_config_dict: Optional[Dict[str, Any]] = None,
override: bool = False,
version: Optional[str] = None)
| 455 | raise |
| 456 | |
| 457 | async def register(self, |
| 458 | env_cls: Type[Environment], |
| 459 | env_config_dict: Optional[Dict[str, Any]] = None, |
| 460 | override: bool = False, |
| 461 | version: Optional[str] = None) -> EnvironmentConfig: |
| 462 | """Register an environment class. |
| 463 | |
| 464 | This will: |
| 465 | - Create an environment instance |
| 466 | - Create an `EnvironmentConfig` |
| 467 | - Store it as the current config and append to version history |
| 468 | - Register the version in `version_manager` and FAISS index |
| 469 | |
| 470 | Args: |
| 471 | env_cls: Environment class |
| 472 | env_config_dict: Configuration dict for environment initialization. |
| 473 | If None, will try to get from global config or use empty dict. |
| 474 | override: Whether to override existing registration |
| 475 | version: Optional version string. If None, auto-generates from version_manager. |
| 476 | |
| 477 | Returns: |
| 478 | EnvironmentConfig: Environment configuration |
| 479 | """ |
| 480 | try: |
| 481 | if env_config_dict is None: |
| 482 | # Fallback to global config by class name |
| 483 | env_config_key = inflection.underscore(env_cls.__name__) |
| 484 | env_config_dict = getattr(config, env_config_key, {}) if hasattr(config, env_config_key) else {} |
| 485 | |
| 486 | # Instantiate environment immediately (register is a runtime operation) |
| 487 | try: |
| 488 | env_instance = env_cls(**env_config_dict) |
| 489 | except Exception as e: |
| 490 | logger.error(f"| ❌ Failed to create environment instance for {env_cls.__name__}: {e}") |
| 491 | raise ValueError(f"Failed to instantiate environment {env_cls.__name__} with provided config: {e}") |
| 492 | |
| 493 | env_name = env_instance.name |
| 494 | env_description = env_instance.description |
| 495 | env_metadata = getattr(env_instance, 'metadata', {}) |
| 496 | env_require_grad = getattr(env_instance, 'require_grad', False) |
| 497 | |
| 498 | if not env_name: |
| 499 | raise ValueError("Environment.name cannot be empty.") |
| 500 | |
| 501 | if env_name in self._environment_configs and not override: |
| 502 | raise ValueError(f"Environment '{env_name}' already registered. Use override=True to replace it.") |
| 503 | |
| 504 | # Get or generate version from version_manager |
| 505 | if version is None: |
| 506 | env_version = await version_manager.get_version("environment", env_name) |
| 507 | else: |
| 508 | env_version = version |
| 509 | |
| 510 | # Get environment code |
| 511 | env_code = dynamic_manager.get_full_module_source(env_cls) |
| 512 | |
| 513 | # Build actions from environment class (same as _load_from_registry) |
| 514 | actions = {} |
nothing calls this directly
no test coverage detected