|
14 | 14 | as fallback when the full vagen package is not installed) |
15 | 15 |
|
16 | 16 | Usage with VAGEN training: |
17 | | - Register in env_registry.yaml: |
| 17 | + 1. Register the env on the GPU VM: |
| 18 | + from openadapt_evals.adapters.verl_env import register_in_vagen |
| 19 | + register_in_vagen("/path/to/vagen/configs/env_registry.yaml") |
| 20 | +
|
| 21 | + 2. Or manually add to vagen/configs/env_registry.yaml: |
18 | 22 | env_registry: |
19 | 23 | WAADesktop: openadapt_evals.adapters.verl_env.WAADesktopEnv |
20 | 24 |
|
21 | | - Training config: |
| 25 | + 3. Training config (envs section): |
22 | 26 | envs: |
23 | 27 | - name: WAADesktop |
24 | 28 | n_envs: 8 |
|
44 | 48 | import io |
45 | 49 | import logging |
46 | 50 | import re |
| 51 | +from pathlib import Path |
47 | 52 | from typing import Any |
48 | 53 |
|
49 | 54 | from openadapt_evals.adapters.base import BenchmarkAction, BenchmarkObservation |
@@ -354,3 +359,110 @@ async def step( |
354 | 359 | ) |
355 | 360 |
|
356 | 361 | return obs_dict, reward, done, info |
| 362 | + |
| 363 | + |
| 364 | +# --- VAGEN registration helpers --- |
| 365 | + |
| 366 | +ENV_REGISTRY_KEY = "WAADesktop" |
| 367 | +ENV_CLASS_PATH = "openadapt_evals.adapters.verl_env.WAADesktopEnv" |
| 368 | + |
| 369 | + |
| 370 | +def register_in_vagen(registry_yaml_path: str | Path | None = None) -> bool: |
| 371 | + """Register WAADesktopEnv in VAGEN's env_registry.yaml. |
| 372 | +
|
| 373 | + If VAGEN is installed and importable, also registers via the Python API. |
| 374 | + Otherwise, edits the YAML file directly. |
| 375 | +
|
| 376 | + Args: |
| 377 | + registry_yaml_path: Path to vagen/configs/env_registry.yaml. |
| 378 | + If None, attempts to find it from the vagen package location. |
| 379 | +
|
| 380 | + Returns: |
| 381 | + True if registration succeeded. |
| 382 | + """ |
| 383 | + # Try programmatic registration first (if vagen is installed) |
| 384 | + try: |
| 385 | + from vagen.envs.registry import register_env |
| 386 | + |
| 387 | + register_env(ENV_REGISTRY_KEY, WAADesktopEnv) |
| 388 | + logger.info("Registered %s in VAGEN env registry (Python API)", ENV_REGISTRY_KEY) |
| 389 | + return True |
| 390 | + except ImportError: |
| 391 | + pass |
| 392 | + |
| 393 | + # Fall back to YAML file editing |
| 394 | + if registry_yaml_path is None: |
| 395 | + # Try to find it from common locations |
| 396 | + candidates = [ |
| 397 | + Path.home() / "verl-agent" / "vagen" / "configs" / "env_registry.yaml", |
| 398 | + Path.home() / "VAGEN" / "vagen" / "configs" / "env_registry.yaml", |
| 399 | + ] |
| 400 | + for candidate in candidates: |
| 401 | + if candidate.exists(): |
| 402 | + registry_yaml_path = candidate |
| 403 | + break |
| 404 | + |
| 405 | + if registry_yaml_path is not None: |
| 406 | + registry_yaml_path = Path(registry_yaml_path) |
| 407 | + if not registry_yaml_path.exists(): |
| 408 | + logger.warning("Registry file not found: %s", registry_yaml_path) |
| 409 | + return False |
| 410 | + |
| 411 | + if registry_yaml_path is None: |
| 412 | + logger.warning( |
| 413 | + "Cannot find env_registry.yaml. Register manually by adding:\n" |
| 414 | + " %s: %s\n" |
| 415 | + "to vagen/configs/env_registry.yaml", |
| 416 | + ENV_REGISTRY_KEY, |
| 417 | + ENV_CLASS_PATH, |
| 418 | + ) |
| 419 | + return False |
| 420 | + |
| 421 | + content = registry_yaml_path.read_text() |
| 422 | + |
| 423 | + if ENV_REGISTRY_KEY in content: |
| 424 | + logger.info("%s already registered in %s", ENV_REGISTRY_KEY, registry_yaml_path) |
| 425 | + return True |
| 426 | + |
| 427 | + # Add entry to the env_registry section |
| 428 | + entry = f" {ENV_REGISTRY_KEY}: {ENV_CLASS_PATH}\n" |
| 429 | + if "env_registry:" in content: |
| 430 | + content = content.replace("env_registry:\n", f"env_registry:\n{entry}", 1) |
| 431 | + else: |
| 432 | + content += f"\nenv_registry:\n{entry}" |
| 433 | + |
| 434 | + registry_yaml_path.write_text(content) |
| 435 | + logger.info("Registered %s in %s", ENV_REGISTRY_KEY, registry_yaml_path) |
| 436 | + return True |
| 437 | + |
| 438 | + |
| 439 | +def generate_env_spec( |
| 440 | + server_url: str = "http://localhost:5001", |
| 441 | + task_id: str = "REPLACE_WITH_WAA_TASK_UUID", |
| 442 | + n_envs: int = 8, |
| 443 | + max_turns: int = 15, |
| 444 | +) -> dict[str, Any]: |
| 445 | + """Generate a VAGEN EnvSpec dict for WAA desktop training. |
| 446 | +
|
| 447 | + Returns a dict suitable for inclusion in a VAGEN training config YAML |
| 448 | + under the ``envs`` key. |
| 449 | +
|
| 450 | + Example: |
| 451 | + spec = generate_env_spec(server_url="http://10.0.0.5:5001", task_id="abc-123") |
| 452 | + # Write to YAML or pass to AgenticDataset |
| 453 | + """ |
| 454 | + return { |
| 455 | + "name": ENV_REGISTRY_KEY, |
| 456 | + "n_envs": n_envs, |
| 457 | + "data_source": "waa", |
| 458 | + "seed": [1, 100, 1], |
| 459 | + "max_turns": max_turns, |
| 460 | + "response_length_per_turn": 512, |
| 461 | + "config": { |
| 462 | + "server_url": server_url, |
| 463 | + "task_id": task_id, |
| 464 | + "max_steps": max_turns, |
| 465 | + "evaluate_at_done": True, |
| 466 | + "action_type": "fractional", |
| 467 | + }, |
| 468 | + } |
0 commit comments