Spaces:
Runtime error
Runtime error
Commit ·
8064ddd
1
Parent(s): ef90792
feat(cp8): additive per-turn distance/post-position trace fields
Browse files- proteus/runtime/trace.py +12 -0
- tests/runtime/test_trace.py +12 -0
proteus/runtime/trace.py
CHANGED
|
@@ -43,6 +43,12 @@ class TurnTrace(BaseModel):
|
|
| 43 |
or inline ``<think>`` whitespace-split count), if available.
|
| 44 |
input_tokens: Act-call token usage — prompt/input side.
|
| 45 |
output_tokens: Act-call token usage — completion/output side.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
"""
|
| 47 |
|
| 48 |
turn_idx: int
|
|
@@ -67,6 +73,12 @@ class TurnTrace(BaseModel):
|
|
| 67 |
thinking_tokens: int = 0
|
| 68 |
input_tokens: int = 0
|
| 69 |
output_tokens: int = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
|
| 72 |
class SessionTrace(BaseModel):
|
|
|
|
| 43 |
or inline ``<think>`` whitespace-split count), if available.
|
| 44 |
input_tokens: Act-call token usage — prompt/input side.
|
| 45 |
output_tokens: Act-call token usage — completion/output side.
|
| 46 |
+
post_focal_pos: Focal ``(x, y)`` AFTER the move (CP8; None on old traces).
|
| 47 |
+
post_predator_pos: Predator ``(x, y)`` AFTER the threat advanced (CP8).
|
| 48 |
+
pre_bfs_distance: BFS focal→predator BEFORE the move — observed risk (CP8).
|
| 49 |
+
post_bfs_distance: BFS focal→predator AFTER the turn — realised safety (CP8).
|
| 50 |
+
agent_distance_delta: Chase-corrected action quality vs the PRE-move
|
| 51 |
+
predator cell (spec §6.2; CP8).
|
| 52 |
"""
|
| 53 |
|
| 54 |
turn_idx: int
|
|
|
|
| 73 |
thinking_tokens: int = 0
|
| 74 |
input_tokens: int = 0
|
| 75 |
output_tokens: int = 0
|
| 76 |
+
# CP8 additive distance fields (spec §6.2/§7); None on pre-CP8 traces.
|
| 77 |
+
post_focal_pos: tuple[int, int] | None = None
|
| 78 |
+
post_predator_pos: tuple[int, int] | None = None
|
| 79 |
+
pre_bfs_distance: int | None = None
|
| 80 |
+
post_bfs_distance: int | None = None
|
| 81 |
+
agent_distance_delta: float | None = None
|
| 82 |
|
| 83 |
|
| 84 |
class SessionTrace(BaseModel):
|
tests/runtime/test_trace.py
CHANGED
|
@@ -53,3 +53,15 @@ def test_sessiontrace_defaults_and_nesting():
|
|
| 53 |
assert restored == s # full round-trip fidelity
|
| 54 |
assert restored.turns[0].focal_pos == (3, 3) # nested tuple coerced back
|
| 55 |
assert restored.metrics["motive_reading_accuracy"] == 100.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
assert restored == s # full round-trip fidelity
|
| 54 |
assert restored.turns[0].focal_pos == (3, 3) # nested tuple coerced back
|
| 55 |
assert restored.metrics["motive_reading_accuracy"] == 100.0
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def test_turntrace_distance_fields_default_none_and_round_trip():
|
| 59 |
+
from proteus.runtime.trace import TurnTrace
|
| 60 |
+
t = TurnTrace(
|
| 61 |
+
turn_idx=1, observation="o", action="up", motive_action="up",
|
| 62 |
+
habit_action="left", is_diagnostic=True, was_congruent=True,
|
| 63 |
+
reward=1.0, focal_pos=(3, 3), predator_pos=(5, 3),
|
| 64 |
+
)
|
| 65 |
+
assert t.post_focal_pos is None and t.pre_bfs_distance is None
|
| 66 |
+
t2 = TurnTrace.model_validate_json(t.model_dump_json())
|
| 67 |
+
assert t2.agent_distance_delta is None
|