Instantiate the environment adapter specified in ``cfg["env"]``.
(cfg: dict)
| 96 | |
| 97 | |
| 98 | def get_adapter(cfg: dict): |
| 99 | """Instantiate the environment adapter specified in ``cfg["env"]``.""" |
| 100 | _register_builtins() |
| 101 | env_name = cfg.get("env", "alfworld") |
| 102 | if env_name not in _ENV_REGISTRY: |
| 103 | raise ValueError( |
| 104 | f"Unknown environment '{env_name}'. " |
| 105 | f"Available: {list(_ENV_REGISTRY.keys())}" |
| 106 | ) |
| 107 | adapter_cls = _ENV_REGISTRY[env_name] |
| 108 | |
| 109 | # Inspect adapter __init__ signature and only pass accepted kwargs |
| 110 | import inspect |
| 111 | sig = inspect.signature(adapter_cls.__init__) |
| 112 | accepted = set(sig.parameters.keys()) - {"self"} |
| 113 | adapter_kwargs: dict = {} |
| 114 | for key in accepted: |
| 115 | if key in cfg: |
| 116 | adapter_kwargs[key] = cfg[key] |
| 117 | |
| 118 | return adapter_cls(**adapter_kwargs) |
| 119 | |
| 120 | |
| 121 | # ── CLI ────────────────────────────────────────────────────────────────────── |
no test coverage detected