Skip to content

Avoid reporting subagent token usage to the context window widget#3515

Open
bharatvansh wants to merge 1 commit intomicrosoft:mainfrom
bharatvansh:fix/subagent-usage-context-widget
Open

Avoid reporting subagent token usage to the context window widget#3515
bharatvansh wants to merge 1 commit intomicrosoft:mainfrom
bharatvansh:fix/subagent-usage-context-widget

Conversation

@bharatvansh
Copy link
Contributor

Summary

When a request is executed in a subagent context (i.e. request.subAgentInvocationId is set), we should not report token usage to the context window widget in the chat input. The widget should reflect only the parent request’s usage; otherwise subagent/tool traffic can inflate what the user sees.

Changes

  • Gate stream.usage(...) reporting in ToolCallingLoop so it only runs for non-subagent requests.
  • Add a unit test verifying:
    • regular requests report usage
    • subagent requests do not report usage

Why

Subagents may run additional model calls and tool loops. Reporting their usage to the parent request’s context widget misrepresents the request’s actual context usage and can confuse users.

Testing

  • npm run test:unit -- src/extension/intents/test/node/toolCallingLoopUsage.spec.ts

Notes

This change only affects usage reporting for the context window widget and does not change server requests or token accounting elsewhere.

Avoid reporting token usage from subagent requests to the context window widget. Add unit tests covering subagent vs regular usage reporting.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR prevents subagent token usage from being reported to the context window widget in the chat input, ensuring users only see token usage from the parent request.

Changes:

  • Added shouldReportUsageToContextWidget() method that returns false when subAgentInvocationId is set
  • Gated the stream.usage(...) call to only report usage for non-subagent requests
  • Added comprehensive unit tests verifying usage reporting behavior for both regular and subagent requests

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/extension/intents/node/toolCallingLoop.ts Added private helper method to check if usage should be reported and updated the usage reporting condition to exclude subagent requests
src/extension/intents/test/node/toolCallingLoopUsage.spec.ts New test file with comprehensive tests for usage reporting behavior in regular vs subagent contexts

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.

2 participants