Skip to content

feat(cli): a run's usage and cost by role and model where runs end - #908

Merged
earakely-scale merged 7 commits into
mainfrom
edgararakelyan/fd5961-run-result-usage
Nov 24, 2026
Merged

earakely-scale merged 7 commits into
mainfrom
edgararakelyan/fd5961-run-result-usage

Conversation

@earakely-scale

@earakely-scale earakely-scale commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

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's usage by 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, a partial entry or a still running one 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 same summarize over 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's usage_total doesn't mark an upper bound; the summary reads cost_assumed from 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), with at least for a lower bound, at most for an upper bound, estimated when it is both, unpriced for usage nothing priced, partial on a share whose counts are a lower bound (its cost then at least, or estimated with 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.
  • Where it prints:
    • agent-env run: a cost line under each task run's models: line, a cost over N runs: line under each eval, and the closing sources line. TaskRun.usage is the run's ledger, read back once its last write has landed; TaskRun.usage_summary sums 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 --k is more than 1, and the sources.
  • eval show doesn'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's usage is its ledger and its summary splits it; agent-env run prints 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, prints at most; a usage read that fails leaves the run's result.
  • tst/unit/cli/submit_runs_test.py: eval run prints each run's cost and the total; task run prints 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, unpriced and partial; the total and its at 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.

Scenario Printed runs Result
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 calls 5 lines equal the ledger; tokens equal the proxy per model
agent-env run --eval over those three, once clean and once with faults on 20% of calls 6 runs, 2 totals each run's line and the eval's cost over 3 runs equal the ledger and the runs' sum
agent-env bundle register, then task run --id and eval run --id on the stored tasks 4 runs, 1 total same, through the run index's instances
A step that fails, rolls back and runs again (faults on its model's calls), completing or failing 2 2 attempts; a cut-off turn makes its share at least
A sibling's retry draining a running chat, the run failing 2 2 attempts, the drained turn partial, the total at least
Ctrl-C mid-run 2 the cancelled run's line prints with what it spent, at least, the cut-off share partial

All 21 printed run lines and 3 eval totals matched; the sources line named the installed map, litellm@1.106.6. The round ran before at most and estimated and before a partial share's own at least; those change the words on a share, not its figures, and the unit tests cover them.

Docs

AGENTS.md's ledger paragraph names task/usage/summary.py. For the docs: what the run summaries print, how to read at least, at most, estimated, unpriced and partial in them, and that a run's total there equals its ledger's.

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence 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, and task run. The latest change names display constants without changing output.

  • Task runs now expose ledger usage grouped by role and model.
  • Run summaries now show costs beside results and totals for grouped runs.

Reviews (10) · Last reviewed commit: "refactor(cli): wrap the dollars format" · Reviewed by Greptile

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@earakely-scale
earakely-scale marked this pull request as ready for review November 24, 2026 04:26
@earakely-scale
earakely-scale requested a review from a team as a code owner November 24, 2026 04:26
Comment thread src/agent_env/cli/eval/run.py Resolved
Comment thread src/agent_env/bundle/run.py Resolved
Comment thread src/agent_env/task/usage/summary.py Resolved
… a failed usage read keeps the run

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread src/agent_env/bundle/run.py Resolved
…h uncounted usage as estimated

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread src/agent_env/cli/usage_output.py Resolved
earakely-scale and others added 2 commits November 23, 2026 21:10
…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>
Comment thread src/agent_env/cli/usage_output.py Resolved
earakely-scale and others added 2 commits November 23, 2026 22:16
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@earakely-scale
earakely-scale merged commit 9ac22e1 into main Nov 24, 2026
35 checks passed
@earakely-scale
earakely-scale deleted the edgararakelyan/fd5961-run-result-usage branch November 24, 2026 06:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant