Expand description
P4b (COMPOSABLE-HARNESS-DESIGN.md §5.2 “P4”, §1.6/§3.1, catalog §4a
“Turn/step usage records surfaced per turn”): persisted per-turn
token/usage records. crate::AgentEvent::Usage already streams this
data live (UX-23); this module makes it DURABLE session data — a typed,
serde-round-trippable record, not a lossy display-only channel (§1.13’s
lossless/sidecar discipline: this is typed session data, exactly like
crate::reduce::ReductionLog, not a text notice).
Structs§
- Usage
Record - One model round-trip’s token accounting, with the context a bare
Usagelacks: which turn it was and which model served it (D9 “model provenance” — obligation 6’s “served-model provenance” row). Deliberately flat/typed (not a formatted string) so it survives a save/load round trip byte-for-byte in the fields that matter, and so a future reader (adoctor/inspect statscommand, a cost dashboard) can aggregate it without re-parsing text.
Functions§
- from_
jsonl - Parse a JSONL usage log back into records — the exact inverse of
to_jsonl. Blank lines are skipped (tolerates a trailing newline or hand-edited whitespace); a malformed line is a hard error (unlike the hooks/sidecar “fail open” posture — a corrupt usage record should be visible, not silently dropped, since it’s accounting data). - to_
jsonl - Serialize
recordsas JSONL (oneUsageRecordper line) — the same shape every other append-log in this crate uses (the transcript, the sidecar). Never fails on an empty slice (produces an empty string).