fix(crew): deduplicate manager agent token usage accounting - #4934
Closed
wishhyt wants to merge 1 commit into
Closed
fix(crew): deduplicate manager agent token usage accounting#4934wishhyt wants to merge 1 commit into
wishhyt wants to merge 1 commit into
Conversation
`calculate_usage_metrics` counted the manager agent's token usage twice: once via `_token_process.get_summary()` and again via `llm.get_token_usage_summary()`, because the two checks were independent if-blocks instead of mutually exclusive branches. Restructure to use the same if/else pattern as regular agents: prefer `BaseLLM.get_token_usage_summary()` when available, otherwise fall back to `_token_process`. Made-with: Cursor
Contributor
|
This PR is stale because it has been open for 45 days with no activity. |
Contributor
|
Closing this. The manager Direction: per-agent Follow the review on #7260 for that rework. This PR is not the shape we want to land. |
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.
Summary
Changes
Restructured to use the same if isinstance(llm, BaseLLM) / else pattern as regular agents.
Test plan
Run a hierarchical crew and verify usage_metrics values are not inflated
Note
Low Risk
Low risk: small, localized change to usage metrics aggregation logic that only affects reported token counts for hierarchical crews.
Overview
Fixes
Crew.calculate_usage_metrics()so the manager agent’s token usage is only added once by making theBaseLLM.get_token_usage_summary()path and the_token_process.get_summary()fallback mutually exclusive (matching the regular agent logic). This prevents inflatedusage_metrics/token totals when both mechanisms are present on the manager agent.Written by Cursor Bugbot for commit d2334c2. This will update automatically on new commits. Configure here.