Build an environment instance from config (internal helper, similar to tool's build). Args: env_config: Environment configuration Returns: EnvironmentConfig: Environment configuration with instance
(self, env_config: EnvironmentConfig)
| 415 | logger.warning(f"| ⚠️ Failed to add environment {env_config.name} to FAISS index: {e}") |
| 416 | |
| 417 | async def build(self, env_config: EnvironmentConfig) -> EnvironmentConfig: |
| 418 | """Build an environment instance from config (internal helper, similar to tool's build). |
| 419 | |
| 420 | Args: |
| 421 | env_config: Environment configuration |
| 422 | |
| 423 | Returns: |
| 424 | EnvironmentConfig: Environment configuration with instance |
| 425 | """ |
| 426 | if env_config.name in self._environment_configs: |
| 427 | existing_config = self._environment_configs[env_config.name] |
| 428 | if existing_config.instance is not None: |
| 429 | return existing_config |
| 430 | |
| 431 | try: |
| 432 | if env_config.cls is None: |
| 433 | raise ValueError(f"Cannot create environment {env_config.name}: no class provided. Class should be loaded during initialization.") |
| 434 | |
| 435 | env_instance = env_config.cls(**env_config.config) if env_config.config else env_config.cls() |
| 436 | |
| 437 | # Initialize environment if it has an initialize method |
| 438 | if hasattr(env_instance, "initialize"): |
| 439 | await env_instance.initialize() |
| 440 | |
| 441 | env_config.instance = env_instance |
| 442 | |
| 443 | # Generate rules if not already generated |
| 444 | if not env_config.rules: |
| 445 | env_config.rules = env_instance.get_rules() |
| 446 | |
| 447 | # Store metadata |
| 448 | self._environment_configs[env_config.name] = env_config |
| 449 | |
| 450 | logger.info(f"| ✅ Environment {env_config.name} created and stored") |
| 451 | |
| 452 | return env_config |
| 453 | except Exception as e: |
| 454 | logger.error(f"| ❌ Failed to create environment {env_config.name}: {e}") |
| 455 | raise |
| 456 | |
| 457 | async def register(self, |
| 458 | env_cls: Type[Environment], |
no test coverage detected