Repository navigation
feat(cli): a run's usage and cost by role and model where runs end - #908
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
earakely-scale
marked this pull request as ready for review
November 24, 2026 04:26
… a failed usage read keeps the run Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…h uncounted usage as estimated Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…imated with an assumed rate Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…val totals summed from the runs' ledgers Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes
A run's usage and cost, split by role and by model, printed where runs end. The ledger on the task instance already holds every attempt's usage, priced from LiteLLM's map, judges' included (#877), with per-model rows; nothing printed it.
task/usage/summary.py:summarize(ledger)sums a task instance'susageby role (solver, user simulator, judge, in that order), then by model. An entry with per-model rows (models) splits along them, and one without counts under its own model. Usage the map couldn't price is counted as unpriced, never as $0. An unpriced part, apartialentry or a stillrunningone makes the total a lower bound; a cost priced on an assumed rate (cost_assumed: a cache rate the map lacks, or input whose cache inclusion the agent didn't say) makes it an upper bound. An eval's total is the samesummarizeover its runs' ledgers together. The cost and its bounds are worked out from the shares, by one rule for a share and for the total. Nothing new is stored: the summary is read from the ledger, so its total is the ledger's. The ledger'susage_totaldoesn't mark an upper bound; the summary readscost_assumedfrom the entries.cli/usage_output.py: the lines the summaries print.cost_line:cost: $0.0532 (solver gpt-4.1-mini $0.0412, 115k in, 1.2k out; user simulator gpt-4.1-nano $0.0016, 16k in, 210 out; judge claude-sonnet-4-6 $0.0104, 2.9k in, 120 out), withat leastfor a lower bound,at mostfor an upper bound,estimatedwhen it is both,unpricedfor usage nothing priced,partialon a share whose counts are a lower bound (its cost thenat least, orestimatedwith an assumed rate), and the attempts named when a run had more than one.sources_line:Costs priced from LiteLLM's price map, litellm@1.80.0.agent-env run: a cost line under each task run'smodels:line, acost over N runs:line under each eval, and the closing sources line.TaskRun.usageis the run's ledger, read back once its last write has landed;TaskRun.usage_summarysums it.eval run: each run's cost under its result, the runs' total, and the sources.task run: each run's cost, the total when--kis more than 1, and the sources.eval showdoesn't exist yet; when it lands, it prints the same split from the same function.Decisions
The format above, the full split on each run's line. Costs name LiteLLM's map version, as pricing does, not a price table's hash.
Tests
tst/unit/task/usage/summary_test.py: the split by role and model across steps, per-model rows split along their models, unpriced usage counted apart and making the total a lower bound, a cost on an assumed rate (an entry's or a per-model row's) at most and with uncounted usage estimated, partial and running entries, attempts, an eval's total over runs, number formats, and the closing line naming each source.tst/unit/bundle/run_test.py: a bundle run'susageis its ledger and its summary splits it;agent-env runprints each run's cost line, an eval's total and the sources line; a turn with cache reads on a model whose price has no cache rate, priced by the real pricing code, printsat most; a usage read that fails leaves the run's result.tst/unit/cli/submit_runs_test.py:eval runprints each run's cost and the total;task runprints its run's cost.tst/integration/cli/run_usage_by_model_test.py: on a real bundle run with an agent reporting two models, the summary's shares and total match the ledger, and the cost line names both models with their counts.E2E against the real proxy
On an admin host, through a logging pass-through in front of the real proxy, 30 minutes on two workers ($0.81). Each printed cost line was checked against its instance's ledger by a checker that works the split out on its own (not through this PR's code): each role and model's cost, tokens,
unpricedandpartial; the total and itsat least; the attempts. Each eval's printed total was checked against its runs' sum, the closing sources line against the ledgers' cost sources, and, for a completed run with nothing partial, each model's tokens against the proxy's.agent-env run --task: a Codex chat with a user simulator, a run with a direct and an agent judge (Claude Code), a Hermes chat; two of them with faults on 35% of callsagent-env run --evalover those three, once clean and once with faults on 20% of callscost over 3 runsequal the ledger and the runs' sumagent-env bundle register, thentask run --idandeval run --idon the stored tasks2 attempts; a cut-off turn makes its shareat least2 attempts, the drained turnpartial, the totalat leastat least, the cut-off sharepartialAll 21 printed run lines and 3 eval totals matched; the sources line named the installed map,
litellm@1.106.6. The round ran beforeat mostandestimatedand before a partial share's ownat least; those change the words on a share, not its figures, and the unit tests cover them.Docs
AGENTS.md's ledger paragraph namestask/usage/summary.py. For the docs: what the run summaries print, how to readat least,at most,estimated,unpricedandpartialin them, and that a run's total there equals its ledger's.🤖 Generated with Claude Code


Confidence Score: 5/5
The PR appears safe to merge; the latest change preserves the displayed output.Summary
Adds run costs split by role and model to
agent-env run,eval run, andtask run. The latest change names display constants without changing output.Reviews (10) · Last reviewed commit: "refactor(cli): wrap the dollars format" · Reviewed by Greptile