Repository navigation
fix(budget): pass the handoff call's usage split to the run budget - #136
Open
Siddhant-K-code wants to merge 1 commit into
Open
Siddhant-K-code wants to merge 1 commit into
Siddhant-K-code wants to merge 1 commit into
Conversation
At the context ceiling a stage asks its model for a handoff, and that call was charged with record_tokens(total) alone. Cached input was billed at full price, so a handoff on a long cached prefix used up the budget faster than the same tokens anywhere else, and its prompt, output and reasoning tokens were missing from the spend report. _write_handoff now returns the call's usage metadata instead of the total, and the caller passes the cached, prompt, output and reasoning counts, like the other direct model calls. A test with a cached, reasoning handoff fails on main (all 10,000 tokens charged fresh) and passes here. The ADK invariants, wire, fork and spend observation suites, the changed-file mutants and pre-commit pass. Assisted-by: GitHub Copilot
This branch has not been deployed
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.
At the context ceiling,
_make_node_context_ceiling_before_model_callbackasks the stage's model for a handoff and charges that call withbc.record_tokens(used), whereusedis onlytotal_token_count. The other direct calls (consolidator, planner, calibrator,meter_response_usage) pass the full split, and this one was missed in #78.So for the handoff call:
What changes
_write_handoffreturns(text, usage_metadata)instead of(text, total), and("", None)when there is no model or the call fails.cached_count,prompt_count,output_countandreasoning_counttorecord_tokens, the same way the calibrator does.Tests
test_node_context_handoff_is_charged_with_its_usage_splitintests/test_adk_invariants.pyruns a handoff with 8,000 of 10,000 tokens cached and 400 reasoning tokens, then checks the cached, fresh, prompt, output and reasoning totals. On main it fails, charging all 10,000 tokens as fresh.test_adk_invariants.py,test_p2_llm_wire.py,test_fork.pyandtest_spend_observations.pypass, pre-commit passes, and the 12 mutants for the changed files are killed.