Skip to content

Surface the Copilot usage model in response metadata - #1115

Open
PratikDhanave (PratikDhanave) wants to merge 2 commits into
microsoft:mainfrom
PratikDhanaveFork:fix/copilot-usage-model
Open

PratikDhanave (PratikDhanave) wants to merge 2 commits into
microsoft:mainfrom
PratikDhanaveFork:fix/copilot-usage-model

Conversation

@PratikDhanave

Copy link
Copy Markdown
Contributor

The Copilot usage handler (assistantUsageUpdate) never read AssistantUsageData.Model, so a caller could not tell which model actually served the request (relevant when the Copilot backend auto-selects or falls back to a different model).

The Python client surfaces it as additional_properties={"model": model} on both run paths.

Change

  • In assistantUsageUpdate, set AdditionalProperties["model"] from data.Model when non-empty. AssistantUsageData.Model exists in the pinned copilot SDK; ResponseUpdate.AdditionalProperties already propagates to the collected response. No new public API.

Test

  • TestConvertToAgentResponseUpdate_UsageEvent_SurfacesModel: a usage event with model:"gpt-5" now surfaces AdditionalProperties["model"] == "gpt-5". Fails before (empty), passes after.

The usage handler never read AssistantUsageData.Model, so callers could not
tell which model actually served the request. Surface it on
AdditionalProperties["model"], matching the Python client.
Copilot AI lite review requested due to automatic review settings September 20, 2026 04:17
@github-actions github-actions Bot added area:provider Changes files in the provider area area:provider/copilot Changes files in the provider / copilot area size:small At most 30 changed lines across at most 2 files labels Sep 20, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The change is small, targeted, and includes a regression test covering the new behavior.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

This PR ensures the Copilot provider surfaces the actual model that served a request by copying AssistantUsageData.Model into response metadata (ResponseUpdate.AdditionalProperties["model"]), enabling callers to detect backend auto-selection or fallback behavior without introducing a new public API.

Changes:

  • Populate ResponseUpdate.AdditionalProperties["model"] from AssistantUsageData.Model when non-empty.
  • Add a unit test asserting the model value is present on the collected response’s AdditionalProperties.
File Description
provider/​copilotprovider/​copilot.go Adds propagation of the serving model into ResponseUpdate.AdditionalProperties.
provider/​copilotprovider/​copilot_test.go Adds a regression test that verifies the model is surfaced via response metadata.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +834 to +838
// Surface which model actually served the request, matching the Python
// client which carries it as additional_properties["model"].
if data.Model != "" {
update.AdditionalProperties = map[string]any{"model": data.Model}
}
@github-actions github-actions Bot added kind:code Changes production behavior or code kind:tests Changes tests, fixtures, or test infrastructure labels Sep 20, 2026
@github-actions

This comment has been minimized.

Set the usage model into a lazily-initialized AdditionalProperties map so
existing or future properties on the update are not overwritten.
@github-actions github-actions Bot added size:medium At most 100 changed lines across at most 5 files kind:dependencies Changes dependencies or manifests and removed size:small At most 30 changed lines across at most 2 files labels Sep 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Scope: user-visible behavior

Changed Go contract: assistantUsageUpdate in provider/copilotprovider/copilot.go now sets ResponseUpdate.AdditionalProperties["model"] from AssistantUsageData.Model (when non-empty), so it propagates onto the collected AgentResponse. No new exported symbols — an existing map is populated.

Upstream evidence reviewed:

  • Python: python/packages/github_copilot/agent_framework_github_copilot/_agent.py — both run paths build the usage update with additional_properties={"model": model} if model else None (around lines 973/1023 for the streaming path and 1120/1127 for the non-streaming path), sourced from event.data.model. This is an exact match for naming (model key), conditional gating (only set when non-empty/non-None), and source field.
  • .NET: dotnet/src/Microsoft.Agents.AI.GitHub.Copilot/GitHubCopilotAgent.cs, ConvertToAgentResponseUpdate(AssistantUsageEvent) / GetAdditionalCounts — currently only surfaces CacheWriteTokens, Cost, and Duration into UsageDetails.AdditionalCounts; it does not surface Model from the usage event at all today. This is a pre-existing .NET gap relative to Python, not something introduced or worsened by this Go PR.

Result: aligned. The Go change brings copilotprovider into parity with the Python github_copilot client's additional_properties["model"] behavior on usage events. The absence of the same field in .NET is a separate, pre-existing upstream inconsistency between Python and .NET — flagging it against this Go PR would be out of scope, since Go should track the strongest available upstream evidence (here, Python) rather than being held to the weaker/incomplete .NET surface. No divergent defaults, no new opt-in surface, no exported API change (AdditionalProperties is an existing field on ResponseUpdate), and the accompanying test (TestConvertToAgentResponseUpdate_UsageEvent_SurfacesModel) directly demonstrates the corrected behavior. Dependency bumps in go.mod/go.sum are incidental and out of scope for parity review.

Generated by Go API Consistency Review Agent · copilot · auto · 32.4 AIC · ⌖ 8.09 AIC · ⊞ 9.2K ·

@github-actions github-actions Bot added the parity-approved Go API consistency review found no parity issues label Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:provider/copilot Changes files in the provider / copilot area area:provider Changes files in the provider area kind:code Changes production behavior or code kind:dependencies Changes dependencies or manifests kind:tests Changes tests, fixtures, or test infrastructure parity-approved Go API consistency review found no parity issues size:medium At most 100 changed lines across at most 5 files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants