Spaces:
Sleeping
Sleeping
Fix client._parse_result to unwrap {observation,reward,done} payload
Browse filesThe env-server returns StepResult-shaped responses where the
observation fields are nested under an 'observation' key. The old
parser passed the whole payload as kwargs to FinancialObservation,
which only fails loudly on pydantic 2.13's strict 'extra=forbid' mode
(silent on older pydantic). Now we extract payload['observation']
and pull reward/done from the top-level keys, with a fallback to
the unwrapped shape for older openenv-core versions.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
client.py
CHANGED
|
@@ -32,11 +32,17 @@ class FinancialTaskEnv(EnvClient["FinancialAction", "FinancialObservation", Stat
|
|
| 32 |
return action.model_dump()
|
| 33 |
|
| 34 |
def _parse_result(self, payload: Dict[str, Any]) -> StepResult[FinancialObservation]:
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
return StepResult(
|
| 37 |
observation=obs,
|
| 38 |
-
reward=
|
| 39 |
-
done=
|
| 40 |
)
|
| 41 |
|
| 42 |
def _parse_state(self, payload: Dict[str, Any]) -> Any:
|
|
|
|
| 32 |
return action.model_dump()
|
| 33 |
|
| 34 |
def _parse_result(self, payload: Dict[str, Any]) -> StepResult[FinancialObservation]:
|
| 35 |
+
# The env-server wraps responses as {observation: {...}, reward, done}.
|
| 36 |
+
# Older openenv-core versions returned the obs at the top level, so we
|
| 37 |
+
# fall back to using the whole payload if no 'observation' key is present.
|
| 38 |
+
obs_data = payload.get("observation", payload) if isinstance(payload, dict) else {}
|
| 39 |
+
obs = FinancialObservation(**obs_data)
|
| 40 |
+
reward = payload.get("reward", obs.reward) if isinstance(payload, dict) else obs.reward
|
| 41 |
+
done = payload.get("done", obs.done) if isinstance(payload, dict) else obs.done
|
| 42 |
return StepResult(
|
| 43 |
observation=obs,
|
| 44 |
+
reward=reward if isinstance(reward, (int, float)) else 0.0,
|
| 45 |
+
done=bool(done),
|
| 46 |
)
|
| 47 |
|
| 48 |
def _parse_state(self, payload: Dict[str, Any]) -> Any:
|