Account for Copilot reasoning tokens in usage details - #553
Merged
Quim Muntal (qmuntal) merged 1 commit intoJul 20, 2026
Merged
Conversation
assistantUsageUpdate mapped input, output, total, and cache-read tokens but dropped AssistantUsageData.ReasoningTokens, so the framework's dedicated ReasoningTokenCount field stayed zero for reasoning models. ReasoningTokens is a subset of the output tokens, so TotalTokenCount is unaffected; only the breakdown field was missing. Map ReasoningTokens to UsageDetails.ReasoningTokenCount, matching the OpenAI and Gemini providers.
Copilot started reviewing on behalf of
PratikDhanave (PratikDhanave)
July 19, 2026 11:08
View session
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Copilot provider’s assistant.usage event conversion to preserve the reasoning-token breakdown by mapping AssistantUsageData.ReasoningTokens into the framework’s UsageDetails.ReasoningTokenCount, matching the behavior of other providers (e.g., OpenAI).
Changes:
- Populate
UsageDetails.ReasoningTokenCountfrom CopilotreasoningTokenswhen convertingassistant.usageevents. - Add a unit test ensuring reasoning tokens are surfaced in the resulting
UsageContentdetails.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| provider/copilotprovider/copilot.go | Maps Copilot ReasoningTokens into UsageDetails.ReasoningTokenCount during usage-event conversion. |
| provider/copilotprovider/copilot_test.go | Adds a regression test asserting reasoningTokens is preserved in UsageDetails. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Quim Muntal (qmuntal)
approved these changes
Jul 20, 2026
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.
When converting a Copilot
assistant.usageevent,assistantUsageUpdatemapped input, output, total, and cache-read tokens but never readAssistantUsageData.ReasoningTokens:The SDK documents
ReasoningTokensas "Number of output tokens used for reasoning (e.g., chain-of-thought)." For a reasoning model those tokens were silently dropped: the framework’s dedicatedUsageDetails.ReasoningTokenCountfield (populated by the OpenAI and Gemini providers, summed byUsageDetails.Add) stayed0, so callers had no reasoning-token breakdown from Copilot.Fix
ReasoningTokensis a subset of the output tokens, soTotalTokenCount(input + output) already accounts for it and is left unchanged — only the missing breakdown field is added, consistent with the OpenAI providers.Test
TestConvertToAgentResponseUpdate_UsageEvent_SurfacesReasoningTokensdrives anassistant.usageevent withreasoningTokens: 8and assertsReasoningTokenCount == 8. It fails on the old code (0) and passes with the fix.