"""The agent plays auto-regressively: each turn's observation carries the model's OWN prior moves this run AND the handover memory every turn (not just turn 1, not just the current grid) — so a stateless agent can maintain its trajectory.""" from __future__ import annotations import proteus.game.scenarios # noqa: F401 from proteus.game.agents.human import HumanAgent from proteus.game.engine.difficulty import Difficulty from proteus.game.runtime.session import SessionRunner def _human(actions): feed = iter(actions) return HumanAgent(input_fn=lambda _p: next(feed), output_fn=lambda _t: None) def _move_log(observation: str) -> str: """The 'your moves so far' segment of an observation (empty if absent).""" if "Your moves so far" not in observation: return "" return observation.split("Your moves so far", 1)[1].split("Now:", 1)[0] def test_memory_shown_every_turn_and_prior_actions_are_auto_regressive(): actions = ["up", "left", "down", "right"] runner = SessionRunner( "template", _human(actions), difficulty=Difficulty.EASY, seed=42, play_turns=len(actions), use_probe=False, ) trace = runner.run() # template attaches a persona memory by default -> it is present on EVERY # turn now (previously only turn 1). assert all("MEMORY" in t.observation for t in trace.turns) # Turn 1: nothing chosen yet. assert _move_log(trace.turns[0].observation) == "" # Turn 2: the turn-1 move is fed back. assert "up" in _move_log(trace.turns[1].observation) # Turn 3: the running line of play accumulates (auto-regressive). log3 = _move_log(trace.turns[2].observation) assert "up" in log3 and "left" in log3 # Turn 4: all three prior moves. log4 = _move_log(trace.turns[3].observation) assert log4.count(",") == 2 # three actions -> two separators