File size: 1,633 Bytes
9de6be7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
33
34
35
36
37
38
39
40
41
42
43
44
45
"""Null-control environment: every episode ends after one action with the same reward.

Every rollout in a GRPO group gets REWARD, so within-group variance and the
advantage are zero on every step. Purpose: measure the arena's evaluation with
no learning signal (plan/research/design.md, Batch B).
"""

from uuid import uuid4

from openenv.core.env_server.interfaces import Environment
from openenv.core.env_server.types import State

try:
    from ..models import NullAction, NullObservation
except ImportError:
    from models import NullAction, NullObservation

REWARD = 0.5
TASK_IDS = ("null",)
PROMPT = 'Reply with one JSON object: {"answer": "done"}. Any reply ends the episode.'


class NullEnvironment(Environment):
    SUPPORTS_CONCURRENT_SESSIONS: bool = True

    def __init__(self):
        self._state = State(episode_id=str(uuid4()), step_count=0)
        self._done = False

    def reset(self, seed=None, episode_id=None, task_id=None, **kwargs) -> NullObservation:
        if task_id is not None and task_id not in TASK_IDS:
            raise ValueError(f"unknown task_id {task_id!r}; known: {list(TASK_IDS)}")
        self._state = State(episode_id=episode_id or str(uuid4()), step_count=0)
        self._done = False
        return NullObservation(prompt=PROMPT, done=False, reward=0.0)

    def step(self, action: NullAction, timeout_s=None, **kwargs) -> NullObservation:  # type: ignore[override]
        self._state.step_count += 1
        self._done = True
        return NullObservation(prompt="Episode over.", done=True, reward=REWARD)

    @property
    def state(self) -> State:
        return self._state