Spaces:
Runtime error
Runtime error
Commit ·
80c8b11
1
Parent(s): 749c5ae
feat(errand): results summary (event choices, closest persona, headline metrics) in review
Browse files
proteus/game/runtime/interactive.py
CHANGED
|
@@ -100,8 +100,32 @@ class InteractiveSession:
|
|
| 100 |
for t in trace.turns
|
| 101 |
],
|
| 102 |
}
|
|
|
|
|
|
|
| 103 |
return st
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
def step(self, action: str, probe_answer: str = "") -> dict:
|
| 106 |
if self._is_done():
|
| 107 |
raise core.SessionFinishedError("session already finished")
|
|
|
|
| 100 |
for t in trace.turns
|
| 101 |
],
|
| 102 |
}
|
| 103 |
+
if self._scenario_name == "errand_runner":
|
| 104 |
+
st["review"]["errand"] = self._errand_summary(trace)
|
| 105 |
return st
|
| 106 |
|
| 107 |
+
def _errand_summary(self, trace) -> dict:
|
| 108 |
+
from proteus.game.scenarios import errand_world as w
|
| 109 |
+
m = trace.metrics
|
| 110 |
+
scen = self._scenario
|
| 111 |
+
observed = {
|
| 112 |
+
"crosswalk": "cross" if any(t.action != "stay" for t in trace.turns) else "wait",
|
| 113 |
+
"construction": "pass", # coarse display; refined record not tracked per-turn
|
| 114 |
+
"wallet": "grab" if not scen._wallet_present else "ignore",
|
| 115 |
+
"pedestrian": "help" if scen._ped_rescued else "ignore",
|
| 116 |
+
}
|
| 117 |
+
def score(pid):
|
| 118 |
+
pol = w.PERSONAS[pid]
|
| 119 |
+
return sum(1 for k in ("wallet", "pedestrian") if pol[k] == observed[k])
|
| 120 |
+
closest = max(w.PERSONAS, key=score)
|
| 121 |
+
headline = {
|
| 122 |
+
"discovery": float(m.get("discovery_turn", 0.0)),
|
| 123 |
+
"generalizability": float(m.get("generalizability", 0.0)),
|
| 124 |
+
"coherence": float(m.get("coherence", 0.0)),
|
| 125 |
+
}
|
| 126 |
+
return {"events": observed, "closest_persona": closest,
|
| 127 |
+
"closest_label": w.PERSONA_LABELS[closest], "headline": headline}
|
| 128 |
+
|
| 129 |
def step(self, action: str, probe_answer: str = "") -> dict:
|
| 130 |
if self._is_done():
|
| 131 |
raise core.SessionFinishedError("session already finished")
|
tests/runtime/test_errand_discovery.py
CHANGED
|
@@ -115,3 +115,15 @@ def test_full_session_runs_and_emits_discovery_metric():
|
|
| 115 |
assert trace.metrics["discovery_identified"] == 100.0, (
|
| 116 |
f"Expected 100.0 but got {trace.metrics['discovery_identified']}"
|
| 117 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
assert trace.metrics["discovery_identified"] == 100.0, (
|
| 116 |
f"Expected 100.0 but got {trace.metrics['discovery_identified']}"
|
| 117 |
)
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def test_review_has_errand_summary_when_done():
|
| 121 |
+
from proteus.game.runtime.interactive import InteractiveSession
|
| 122 |
+
s = InteractiveSession("errand_runner", seed=7, play_turns=2, use_default_memory=False)
|
| 123 |
+
s.step("stay"); s.step("stay")
|
| 124 |
+
rv = s.state()["review"]
|
| 125 |
+
assert rv is not None and "errand" in rv
|
| 126 |
+
es = rv["errand"]
|
| 127 |
+
assert set(es["events"]) == {"crosswalk", "construction", "wallet", "pedestrian"}
|
| 128 |
+
assert es["closest_persona"] in {"civic", "warm_outlaw", "opportunist"}
|
| 129 |
+
assert {"discovery", "generalizability", "coherence"} <= set(es["headline"])
|