Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions provider/copilotprovider/copilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,15 @@ func (p *provider) assistantUsageUpdate(event copilot.SessionEvent, data *copilo
case data.FinishReason != nil:
update.FinishReason = *data.FinishReason
}
// Surface which model actually served the request, matching the Python
// client which carries it as additional_properties["model"]. Initialize the
// map lazily so existing/future properties are not overwritten.
if data.Model != "" {
if update.AdditionalProperties == nil {
update.AdditionalProperties = make(map[string]any)
}
update.AdditionalProperties["model"] = data.Model
}
return update
}

Expand Down
22 changes: 22 additions & 0 deletions provider/copilotprovider/copilot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,28 @@ func TestConvertToAgentResponseUpdate_UsageEvent_SurfacesReasoningTokens(t *test
}
}

// The usage event reports which model actually served the request; it must be
// surfaced on AdditionalProperties, matching the Python client.
func TestConvertToAgentResponseUpdate_UsageEvent_SurfacesModel(t *testing.T) {
runtime := newFakeRuntime(t,
sessionEvent("assistant.usage", map[string]any{
"model": "gpt-5",
"inputTokens": 10,
"outputTokens": 20,
}),
idleEvent(),
)
agent := copilotprovider.NewAgent(runtime.client(), copilotprovider.AgentConfig{})

response, err := runText(t, agent, "hello")
if err != nil {
t.Fatalf("RunText: %v", err)
}
if got, _ := response.AdditionalProperties["model"].(string); got != "gpt-5" {
t.Fatalf("AdditionalProperties[model] = %q, want gpt-5", got)
}
}

// A content-filter-triggered usage event must report the canonical
// "content_filter" finish reason, taking precedence over the raw finishReason,
// matching the Python client.
Expand Down
Loading