Answer architecture round 1: 1 🔴, 8 🟡 (0 misread); one reader per message, prices and Spent block moved, one table of larv-review commands
This commit is contained in:
@@ -181,7 +181,7 @@ def annotation_of(cycle: Cycle, transcript_path: str, entries: list[Entry], judg
|
||||
if isinstance(subagents, Failure):
|
||||
return subagents
|
||||
spent = spend.spent(since, entries, subagents, judge_of(cycle).model, judged.tokens)
|
||||
return outcomes.Annotation(cycle.config, spend.spent_block(since, spent), judged.reversed)
|
||||
return outcomes.Annotation(cycle.config, outcomes.spent_block(since, spent), judged.reversed)
|
||||
|
||||
|
||||
def ruling_outcome(cycle: Cycle, ruling: Interrupt | QuotedAnswer, quoted_answers: int, annotation: outcomes.Annotation) -> str:
|
||||
|
||||
@@ -7,16 +7,12 @@ import json
|
||||
import pathlib
|
||||
import typing
|
||||
|
||||
from claude_code.entries import AssistantTurn, Entry
|
||||
from claude_code.entries import AssistantTurn, Entry, messages
|
||||
from failure import Failure
|
||||
from routing_figures.prices import PRICES
|
||||
from claude_code.transcript import read_transcript
|
||||
from transcript_archive.outcomes import SPENT
|
||||
from transcript_archive.outcomes import Spender
|
||||
from claude_code.tokens import Tokens, tokens_of
|
||||
|
||||
KINDS = "input, cache write 5m, cache write 1h, cache read, output"
|
||||
# Who spent, such as `worker`, `judge` or `Explore "Search the hooks"`, and the model they ran on.
|
||||
Spender = tuple[str, str]
|
||||
WORKER = "worker"
|
||||
JUDGE = "judge"
|
||||
|
||||
@@ -38,14 +34,10 @@ def spent(since: str, worker: list[Entry], subagents: list[Subagent], judge_mode
|
||||
|
||||
|
||||
def thread_spend(entries: list[Entry], since: str) -> dict[str, Tokens]:
|
||||
"""Each model's tokens in one transcript's messages written after since. A message's usage repeats in each entry of it, so each message counts once, by its id."""
|
||||
"""Each model's tokens in one transcript's messages written after since. Each message counts once."""
|
||||
start = moment(since) if since else None
|
||||
counted: dict[str, AssistantTurn] = {}
|
||||
for entry in entries:
|
||||
if isinstance(entry, AssistantTurn) and entry.model and (start is None or later(entry.timestamp, start)):
|
||||
counted.setdefault(entry.message_id or entry.uuid, entry)
|
||||
found: dict[str, Tokens] = {}
|
||||
for turn in counted.values():
|
||||
for turn, *_ in messages(entry for entry in entries if isinstance(entry, AssistantTurn) and entry.model and (start is None or later(entry.timestamp, start))):
|
||||
found[turn.model] = found.get(turn.model, Tokens()).plus(tokens_of(turn.usage))
|
||||
return found
|
||||
|
||||
@@ -84,13 +76,3 @@ def subagent_name(transcript: pathlib.Path) -> str:
|
||||
# One line for the type, since a line break could forge an archive line such as `Config: `; json.dumps escapes the description's.
|
||||
kind, description = " ".join(str(meta.get("agentType") or "subagent").split()), str(meta.get("description") or "")
|
||||
return f"{kind} {json.dumps(description, ensure_ascii=False)}" if description else kind
|
||||
|
||||
|
||||
def spent_block(since: str, found: dict[Spender, Tokens]) -> str:
|
||||
"""The archive's block for what the stretch spent, then the list prices in force for each model in it; empty where nothing was spent."""
|
||||
if not found:
|
||||
return ""
|
||||
spenders = [f"- {name}, {model}: {', '.join(map(str, (tokens.input, tokens.write_5m, tokens.write_1h, tokens.read, tokens.output)))}" for (name, model), tokens in found.items()]
|
||||
priced = [f"- {model}: {price.input:g}, {price.write_5m:g}, {price.write_1h:g}, {price.read:g}, {price.output:g}" for model in dict.fromkeys(model for _, model in found) if (price := PRICES.get(model))]
|
||||
prices = ["", f"List prices in dollars per million tokens of {KINDS}:", *priced] if priced else []
|
||||
return "\n".join([f"{SPENT}{since or 'the chunk began'}, in tokens of {KINDS}:", *spenders, *prices])
|
||||
|
||||
Reference in New Issue
Block a user