File size: 2,379 Bytes
d4716c0
45330f2
 
 
e343386
 
426093b
 
 
 
 
 
e343386
 
45330f2
d4716c0
45330f2
e343386
d4716c0
45330f2
 
 
 
 
 
 
261988e
 
 
 
 
e343386
 
45330f2
d4716c0
45330f2
 
 
 
 
d4716c0
e343386
 
 
 
 
 
d4716c0
e343386
 
 
45330f2
e343386
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
46
47
48
49
50
51
52
53
54
"""template's handover memory is generated by a HIDDEN PERSONA weight vector
(a reference-policy self-play episode), not hand-written — per the agentness
design (docs/agentness_game_design_from_paper.md §3-4). The raw weights never
leak; only the public persona_weight_id + the behaviour trajectory are stored."""
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.scenarios.base import get_scenario
from proteus.game.runtime.memory import MemoryCheckpoint
from proteus.game.runtime.session import SessionRunner


def test_default_memory_is_persona_generated():
    scenario = get_scenario("template")()
    ckpt = scenario.default_memory(42, Difficulty.EASY)
    assert isinstance(ckpt, MemoryCheckpoint)
    assert ckpt.scenario == "template"
    # Hidden persona weight vector -> only the public id is recorded.
    assert ckpt.persona_weight_id == "risk_averse"
    assert ckpt.model == "persona:risk_averse"
    # The memory is the reference policy's actual played trajectory.
    assert len(ckpt.memory_turns) >= 1
    # The raw weights must NOT leak into the participant-visible brief.
    assert "risk_cost" not in ckpt.transparent_prompt
    # Compact frames: prose coords + a wall-rectangle list, never the
    # 4096-char ASCII map of the 64x64 field.
    assert all(len(mt.frame_ascii) < 600 for mt in ckpt.memory_turns)
    # EASY has walls, so the per-turn observation names them.
    assert all("Walls (blocked rectangles" in mt.frame_ascii for mt in ckpt.memory_turns)


def test_default_memory_is_deterministic():
    scenario = get_scenario("template")()
    a = scenario.default_memory(42, Difficulty.EASY)
    b = scenario.default_memory(42, Difficulty.EASY)
    assert a.model_dump() == b.model_dump()


def test_template_session_shows_persona_memory_by_default():
    def feed():
        seq = iter(["stay"] * 5)
        return lambda _p: next(seq)

    agent = HumanAgent(input_fn=feed(), output_fn=lambda _t: None)
    runner = SessionRunner(
        "template", agent, difficulty=Difficulty.EASY, seed=42,
        play_turns=3, use_probe=False,
    )
    trace = runner.run()
    # The turn-1 observation carries the (persona-generated) memory block.
    assert "MEMORY" in trace.turns[0].observation