Spaces:
Paused
Paused
File size: 1,092 Bytes
8697ae6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | """EnvClient subclass for the HR Productivity Environment."""
from __future__ import annotations
from typing import Any, Dict
from openenv.core import EnvClient
from openenv.core.client_types import StepResult
from hr_env.models import HRAction, HRObservation, HRState
class HRProductivityEnv(EnvClient[HRAction, HRObservation, HRState]):
"""Typed client for connecting to the HR Productivity Environment server."""
def _step_payload(self, action: HRAction) -> Dict[str, Any]:
"""Serialize an HRAction for the WebSocket protocol."""
return action.model_dump(exclude_none=True)
def _parse_result(self, payload: Dict[str, Any]) -> StepResult[HRObservation]:
"""Parse a step/reset response into a StepResult."""
obs = HRObservation.model_validate(payload)
return StepResult(
observation=obs,
reward=obs.reward,
done=obs.done,
)
def _parse_state(self, payload: Dict[str, Any]) -> HRState:
"""Parse a state response into HRState."""
return HRState.model_validate(payload)
|