Answer stability round 1: 0 🔴, 6 🟡 (0 misread); slim chunk_figures, type a call's kind, keep the state through replace_json, add the missing state and raise tests
This commit is contained in:
@@ -65,21 +65,15 @@ def chunk_figures(chunk: Chunk, home: str, history: list[BranchChunk] | None = N
|
||||
launches = agent_calls(chunk.worker)
|
||||
reported = results(chunk.worker)
|
||||
delegated = [delegation(subagent, launches, reported, cycles) for subagent in chunk.subagents]
|
||||
spent = [Spent("worker", str(rung_at(cycles, message.at)), message) for message in messages(chunk.worker)]
|
||||
spent += [Spent(one.kind, one.rung, message) for one in delegated for message in one.messages]
|
||||
judged = [judged for kept in chunk.outcomes for judged in judge_costs(kept)]
|
||||
dollars, unattributed = costed(spent, judged, chunk.project, recorded_costs(chunk.worker))
|
||||
dollars, unattributed = chunk_dollars(chunk, cycles, delegated)
|
||||
start = route_from(cycles[0][1]) if cycles else None
|
||||
reports: dict[str, Reports] = {}
|
||||
for one in delegated:
|
||||
reports[one.kind] = reports.get(one.kind, Reports(0, 0, 0)) + Reports(1, one.report_chars, one.read_chars)
|
||||
return ChunkFigures(
|
||||
dollars=dollars,
|
||||
start=start.rung if start and start.item else None,
|
||||
rounds_past_first=rounds_past_first(commit_titles(chunk.worker, home)),
|
||||
unfinished=sum(len(UNFINISHED_AT.findall(kept)) for kept in chunk.outcomes),
|
||||
delegated=collections.Counter(one.rung for one in delegated),
|
||||
reports=reports,
|
||||
reports=reports_by_type(delegated),
|
||||
escalated=escalations(launches),
|
||||
unattributed=unattributed,
|
||||
lacking=transcripts_lacking(launches, chunk.subagents),
|
||||
@@ -87,6 +81,21 @@ def chunk_figures(chunk: Chunk, home: str, history: list[BranchChunk] | None = N
|
||||
)
|
||||
|
||||
|
||||
def chunk_dollars(chunk: Chunk, cycles: list[tuple[str, str]], delegated: list[Delegation]) -> tuple[Dollars, float]:
|
||||
"""What costed makes of the messages of the worker, each on the rung of the cycle it ran in, and of its subagents, and of the chunk's judge runs."""
|
||||
spent = [Spent("worker", str(rung_at(cycles, message.at)), message) for message in messages(chunk.worker)]
|
||||
spent += [Spent(one.kind, one.rung, message) for one in delegated for message in one.messages]
|
||||
judged = [judged for kept in chunk.outcomes for judged in judge_costs(kept)]
|
||||
return costed(spent, judged, chunk.project, recorded_costs(chunk.worker))
|
||||
|
||||
|
||||
def reports_by_type(delegated: list[Delegation]) -> dict[str, Reports]:
|
||||
reports: dict[str, Reports] = {}
|
||||
for one in delegated:
|
||||
reports[one.kind] = reports.get(one.kind, Reports(0, 0, 0)) + Reports(1, one.report_chars, one.read_chars)
|
||||
return reports
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Delegation:
|
||||
"""One subagent as the figures count it: its type, the rung it ran on, the characters of its report and of the tool results it read, and its messages."""
|
||||
@@ -141,13 +150,16 @@ def agent_calls(worker: list[dict]) -> dict[str, tuple[str, dict]]:
|
||||
|
||||
def rung_at(cycles: list[tuple[str, str]], timestamp: str) -> Rung | str:
|
||||
"""The rung of the cycle running at timestamp: the worker named by the first outcome stamped at or after it, or else by the last outcome. A worker line route_from cannot read is returned as its text, and "unrouted" where no outcome names a worker."""
|
||||
# An outcome is stamped to the second, as 2026-10-15T00:00:00Z, and a message to the millisecond, so the message's stamp is cut to the second to compare them as text.
|
||||
second = timestamp[:19] + "Z"
|
||||
found = next((rung for stamp, rung in cycles if stamp >= second), cycles[-1][1] if cycles else "unrouted")
|
||||
found = next((rung for stamp, rung in cycles if stamp >= to_the_second(timestamp)), cycles[-1][1] if cycles else "unrouted")
|
||||
route = route_from(found)
|
||||
return route.rung if route else found
|
||||
|
||||
|
||||
def to_the_second(timestamp: str) -> str:
|
||||
"""A message's stamp, such as 2026-10-15T00:00:00.123Z, cut to the second, as an outcome is stamped: 2026-10-15T00:00:00Z. Stamps in that one form sort as text in time order."""
|
||||
return timestamp[:19] + "Z"
|
||||
|
||||
|
||||
def subagent_rung(entries: list[dict], arguments: dict, worker: Rung | str) -> Rung:
|
||||
"""The model the subagent ran, at the effort its Agent call set, or else at the worker's."""
|
||||
model = next((message["model"] for entry in entries if entry.get("type") == "assistant" and isinstance(message := entry.get("message"), dict) and isinstance(message.get("model"), str)), str(arguments.get("model") or "unknown"))
|
||||
|
||||
Reference in New Issue
Block a user