Repository navigation
feat(optimization): report the run's cost by role and phase - #618
Conversation
c8e35bf to
554576d
Compare
|
Assessment: Comment The cost accounting is correct. I followed every path that writes Review Categories
Moving the proposer totals onto the event log, so they no longer need their own copy in |
The result's four cost fields hid where a run's spend went. agent_cost counted only each trial's last attempt, retry_cost added the agent's earlier attempts to the failed judges' usage, and search_cost was one total over every proposer with no failure counts. OptimizationResult.cost (RunCost) replaces them. The agent's and the judges' usage is reported per split over every attempt; the agent's cell also counts trials, attempts to run the agent, and failed attempts, and the judges' cell counts attempts with a failed evaluator. Each block of the search gets its proposer's reported usage and its failed attempts (proposer_retry and proposer_error events). summary() shows the total and a table with one row per role. The rollouts' other agents (benchmark_usage, a simulated user) are a role of RunCost too, per split over every attempt, replacing benchmark_cost; the summary's tokens table shows one row per role with its failed attempts. The cost is built in _finish from every saved trial and every event, so a killed iteration's spend still counts after a resume. That made Optimizer._search_cost and ResumeState.search_cost a second copy of the proposer sum, so they are removed; the proposer log callback now checks that a proposer_usage event carries a Usage before writing it, which the running sum used to enforce.
… fix for an old result, and count every role in the UI's cost - `AgentSpend.failed` counts `agent_failure` attempts only, as `CandidateScores.failures` does; `AgentSpend.infrastructure` counts the `infrastructure_invalid` ones (throttling, a lost sandbox). - Each `RunCost` field documents what its `failed` counts. - Loading a `result.json` written before `cost` raises an error that names the resume that rewrites it. - The UI's cost figure and spend-by-iteration chart count every role and every attempt, as `cost` does.
554576d to
6513452
Compare
…d attempts again Splitting them into AgentSpend.infrastructure hid them: the summary showed no column for it. The summary note now says plainly that infrastructure failures such as throttling count.
|
Assessment: Comment Re-reviewed at Still open
Verification:
|
|
Assessment: Comment Re-reviewed through
Both look right. The new error message points to a fix that works: Remaining items
The error for an old result is a good fix: it names what changed and how to recover. |
…d trajectory-free reports Replace agent_cost/judge_cost/search_cost/retry_cost with result.cost by role and split (strands-agents/evals#618), and update the quickstart's Tokens table from the same run. Show a JsonField on a number, a boolean, or a set of values, which now reaches the factory typed and is searched with TPE (strands-agents#599). Say that report rows name their transcript instead of carrying the trajectory (strands-agents#610).
Description
OptimizationResultreports what a run spent in four fields, and they hide where the spend went:agent_costcounts only each trial's last attempt, so an attempt that a re-run pass replaced, or thatExperimentretried on throttling, is missing from the agent's cost.retry_costholds those earlier attempts, but it adds the agent's usage in them to the failed judges' usage, so neither role's total can be read off.search_costis one total over every proposer, with no per-block figure and no count of failed proposer attempts.For example, take a one-iteration run of the smoke-test agent (a scripted model that reports tokens) where one trial's sandbox fails after the agent ran, and one judge raises after its model call. Both are retried. Over every attempt, the agent used 33,882 tokens and the judges 3,080. The result reported
agent_cost33,182 (summed over splits),judge_cost3,040, andretry_cost740, which is the agent's 700 and the judge's 40 added together.This PR replaces the four fields with one
cost: RunCost, by role and phase:cost.agent[split]is anAgentSpend: the agent's usage on that split's trials over every attempt, the trial count, the attempts to run the agent, and how many of those failed (agent_failureorinfrastructure_invalid).cost.judges[split]is aSpend: the evaluators' usage on those trials, the failed judges of earlier attempts included, and the attempts with a failed evaluator.cost.proposers[block]is aSpendfor each block of the search: what its proposer reported spending, and its failed attempts (proposer_retryandproposer_errorevents).cost.totalsums every role.Splits are the phases, as elsewhere in the module: train is the search, and validation and test are the end phase.
usage.model_callsis each role's model call count. The optimizer doesn't record how many times it calledpropose, so that count isn't reported._finishbuildsRunCostfrom every saved trial and every event. A killed iteration's trials and proposer calls still count after a resume, as before. Because the proposer figures now come from the event log,Optimizer._search_costandResumeState.search_costwere a second copy of the same sum, and this PR removes them. Adding a proposer'sproposer_usageevent to_search_costwas also what rejected an event without aUsagebefore it was written. The proposerlogcallback now checks the type itself, so a bad event still ends the search withproposer_errorinstead of being saved and failing_finishlater, on every resume.summary()replaces its cost sentence with the total tokens and a table: tokens per split, model calls, the agent's attempts, and each role's failed attempts, one row per role, then the total.Behavior changes:
agent_cost,search_cost,judge_costandretry_costare removed; readresult.costinstead. They exist only on this workstream branch, since feat(optimization): the Optimizer: the loop, the end phase, resume, and the results API #535, and in no release.summary()are different.Spend,AgentSpendandRunCostare exported fromstrands_evals.optimization.result.jsonwritten before this change no longer loads withOptimizationResult.from_file. Resuming the finished run rewrites it. Run directories and event logs are unchanged, so earlier runs resume as before.Related Issues
Part of #442. The cost fields were introduced in #535.
Documentation PR
None
Type of Change
Breaking change
Testing
New tests:
tests/strands_evals/optimization/test_result.py(new file, mirroringresult.py):test_the_agent_and_the_judges_count_every_attempt_each_in_its_own_role: hand-built trial records with a re-run pass, a throttled attempt, judge-only re-runs (one aftercompleted, one afterevaluator_invalid), an agent failure, and a trial leftinfrastructure_invalid. It checks each split's usage, trials, attempts and failed attempts for the agent and the judges.test_each_block_gets_its_proposers_spend_and_failed_attempts: every block appears in the search's order, a block that reported nothing is zero, a block only the events name comes last, and both kinds ofproposer_usageevent and both failure events count.test_the_summary_table_has_a_row_per_role_and_the_total.tests/strands_evals/optimization/test_smoke.py::test_retried_agent_and_judge_spend_counts_in_their_own_roles: the example above on a realOptimizerrun. The agent's cost equals its usage over every attempt, which is more than its last attempts' usage, with one more attempt than trials and one failed. The judges' cost is one judgment more than the trial count, with one failed attempt.tests/strands_evals/optimization/test_optimizer.py::test_a_proposer_usage_event_without_a_usage_is_refused_before_it_is_written: the search stops withproposer_error, the event names theTypeError, and noproposer_usageevent is written.Updated tests: the killed-run tests that read
ResumeState.search_costandOptimizer._search_costnow read each block's proposer tokens from the run's event log, the way the result counts them. They now check per-block figures, for example{"structure": 10, "numbers": 10}where they checked a total of 20, andtest_a_proposers_spend_on_no_patch_is_counted_and_survives_resumeis renamedtest_a_proposers_spend_on_no_patch_is_counted_under_its_block, since it no longer reads a resume state. TheResumeState.search_costassertion intests/strands_evals/optimization/record/test_resume.pyis deleted with the field;test_result.pyand the killed-run tests cover what it checked. Other tests that read the old fields now readresult.cost.On
workstream/optimizer-workflow, the new cost tests fail: the result has nocost, and its old fields give the figures in the example above.Results:
pytest tests/strands_evals/optimization tests/strands_evals/types/optimization: 1461 passed, 1 xfailed.ruff checkandruff format --checkon the changed files: clean.mypy -p strands_evals: no errors in the optimization module. The 24 errors it reports in other modules are already onworkstream/optimizer-workflow.I ran
hatch run prepareChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.