Repository navigation
feat(protocol): Usage gives a turn's counts by model, and the host prices each model at its own rate - #887
Merged
Conversation
…ices each model at its own rate Usage.models holds a ModelUsage per model a turn's calls used (its calls, token and cache counts, and the agent's own cost for them), covering every call the turn counted. The host prices each model's counts at that model's map rate and the step's entry keeps a row per model, its cost_usd their sum; a turn without them is priced at the role's model, as before. The echo test agent reports a breakdown on a usage-models line, for the integration test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
earakely-scale
marked this pull request as ready for review
November 23, 2026 17:09
…gent's figure stands in only when complete, and from_dict refuses a falsy models value - Usage: a count a turn with models leaves out, that every row gives, is the rows' sum; so is the includes-cache flag the rows agree on. A model-only turn is priced from its rows. - RoleUsage: the agent's or endpoint's figure stands in for the map only when every turn, or every share of a model, carried one; a sum of some isn't the cost, so a model the map lacks is unpriced instead. - Usage.from_dict passes any non-null models value to the constructor, which refuses one that isn't a list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t share a count A row that can't be priced, one missing its output say, leaves the entry unpriced instead of the turn being left out. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…y complete ones stand in for the map The agent's or endpoint's figures stand in for a price only when every turn, or every share of a model, gave one; their sum is kept beside the cost either way, as before, so an entry with a cut-off turn keeps the agent's figure. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ls' rows, and a shared cost-fields type - _total, _tokens and _agreed sum a role's turns and a model's shares alike; _priced is _cost_of, so it isn't mistaken for model_pricing's own _priced. - Cost.fields writes the uncached input and unit prices only when the cost has them, so an entry priced per model needs no keys popped. - CostFields holds the cost keys ModelEntry and UsageEntry share. - _by_model files a turn's rows under their models, and a turn without them under the role's, in plain if/else. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
earakely-scale
added a commit
that referenced
this pull request
Nov 23, 2026
… reported one; tests take the new floor As the host's rule since #887: a sum of some calls' figures isn't the model's cost, so the host prices it from the map. The agents' image-contract tests and the proxy usage integration test take the 0.1.640 floor and the turn's rows. 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
The first half of P16 (FD-6744): the protocol gains a turn's counts by model, and the host prices each model at its own rate. Today the host prices a role's whole turn at the role's one model. A Claude Code turn with a Haiku subagent under a Sonnet solver, or a Gemini turn with side calls on flash-lite, is therefore priced at the solver's rate, and the cost is off with nothing marking it. The agents that fill the breakdown come in the second PR, after the release that publishes this protocol, since agent images install the protocol from PyPI.
Usage.modelsis a list ofModelUsage, one per model the turn's calls used. Each row has the model's name as called, itscalls, its token and cache counts (read asUsage's are, with its owninput_includes_cache), and the agent's owncost_usdfor them when it has one.Usagevalidates the rows like its own counts,to_dictwrites them only when there are some, andfrom_dictreads them from mappings. An older reader ignores the key.RoleUsage.entryprices each model's counts at that model's map rate. A turn with no breakdown counts toward the role's model.models), with the row's counts and its cost fields (cost_usd,cost_status,cost_source,unit_prices,uncached_input_tokens).cost_usdis the rows' sum. Since no single rate applies, the entry has nounit_pricesoruncached_input_tokensof its own.usage-models, so the integration test can send one over A2A.Decisions (made with Edgar, 2026-11-23)
Usage, not aprovider_detailsconvention. That's why this ships as two PRs with a release between them.Also in this PR, how the entry is costed:
no_price), as today. Each row keeps its own cost, so the other models' costs stay visible.reportedfromharness, since the entry is only as sure as its least sure row. The total is still the sum.reported_cost_usdstill shows the figures that came, summed, as before, so an entry with a cut-off turn keeps the agent's figure for its other turns. For a judge whose endpoint billed only some calls, it now shows the bills that came instead of null.Tests
packages/agentenv-protocol/tests/test_usage_models.py: rows round-trip, are written only when present, are read from mappings with unknown keys ignored, have their counts, cost and flag validated, and must name their model.modelsmust be a list, andfrom_dictrefuses a falsy non-list. A turn that gives only its rows takes their sums as its counts.tst/unit/task_step/usage_models_test.py:tst/integration/cli/run_usage_by_model_test.py: the echo agent sends a breakdown over A2A. The step's entry has a row per model at each model's real map rate, and the task instance's ledger total equals their sum.E2E
tst/integration/cli/run_usage_by_model_test.py, Docker): the echo agent sent a two-model breakdown (gpt-4.1-mini and gpt-4o-mini) over A2A. The step's entry had a row per model at each model's rate from LiteLLM's installed map, with no entry-levelunit_prices. The task instance'susage_total.cost_usdequalled the rows' sum.models, entry-levelunit_prices). Today's agents send no breakdown, so their costs don't change.Model spend: about $0.82 at list prices. The agent side, including a Claude Code turn with a Haiku subagent checked against the CLI's own cost, is the second PR's e2e.
Docs
For FD-6263 and FD-6442:
modelsrows, and that itscost_usdis their sum;unit_pricesoruncached_input_tokens;Usage.modelsandModelUsage.The protocol README and
AGENTS.mdsay it already.🤖 Generated with Claude Code


Confidence Score: 5/5
The PR appears safe to merge; no new actionable issues were found.Summary
Adds
Usage.modelsand prices each model at its own rate.Diagram
%%{init: {'theme': 'neutral'}}%% flowchart LR A[Turn usage] --> B{Model rows supplied?} B -->|Yes| C[Group shares by model] B -->|No| D[Use the role's model] C --> E[Price each model] E --> F[Sum model costs] D --> G[Price role usage] F --> H[Step usage entry] G --> HReviews (8) · Last reviewed commit: "refactor(usage): one set of summing help..." · Reviewed by Greptile