AgentnessBench / tests /runtime /test_memory_multiagent_model.py
irregular6612's picture
feat(memory): AgentFrame model + multi-agent turn/checkpoint fields
26b05a6
Raw
History Blame Contribute Delete
1.62 kB
# tests/runtime/test_memory_multiagent_model.py
"""Multi-agent memory fields round-trip and stay backward compatible."""
from proteus.game.runtime.memory import (
AgentFrame, MemoryCheckpoint, MemoryTurn,
)
def test_agentframe_defaults():
a = AgentFrame(id="a0", kind="agent", pos=(3, 4), size=2)
assert a.alive is True and a.is_chosen is False and a.facing == "right"
def test_turn_multiagent_roundtrip():
t = MemoryTurn(
turn_idx=1, frame_ascii="", action="up",
focal_pos=(0, 0), predator_pos=(0, 0),
agents=[AgentFrame(id="a0", kind="agent", pos=(3, 4), size=2, is_chosen=True),
AgentFrame(id="predator", kind="predator", pos=(9, 9), size=3, facing="left")],
resources=[(5, 5)], events=["a1 eaten"],
)
back = MemoryTurn.model_validate_json(t.model_dump_json())
assert back.agents[0].is_chosen is True
assert back.agents[1].facing == "left"
assert back.resources == [(5, 5)] and back.events == ["a1 eaten"]
def test_checkpoint_chosen_id_and_backcompat():
ck = MemoryCheckpoint(
model="m", scenario="s", difficulty="easy", created_at="x",
outcome="survived", transparent_prompt="p", chosen_agent_id="a0",
)
back = MemoryCheckpoint.model_validate_json(ck.model_dump_json())
assert back.chosen_agent_id == "a0"
# Legacy single-agent turns still parse with empty multi-agent fields.
legacy = MemoryTurn(turn_idx=1, frame_ascii="x", action="up",
focal_pos=(1, 1), predator_pos=(2, 2))
assert legacy.agents == [] and legacy.resources == [] and legacy.events == []