Repository navigation
[dotnet-port-api] Add Response.ModelID #1156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
01a5b62
11706f4
2b1d5cf
0cf7a0c
234cf7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,10 @@ type Response struct { | |
| // ID identifies this response. | ||
| ID string `json:",omitzero"` | ||
|
|
||
| // ModelID is the identifier of the model that produced this response, when | ||
| // the provider supplies it. It is empty otherwise. | ||
| ModelID string `json:",omitzero"` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Parity concern (unresolved from prior review): Upstream .NET and Python deliberately keep model identity on the lower-level chat-response contract and omit it from the agent-level response contract that Go's
Go has no chat-level response type distinct from
Comment on lines
+48
to
+50
|
||
|
|
||
| // ConversationID identifies conversation history retained after this response | ||
| // by the service or per-service-call history persistence. When nil, the response | ||
| // does not claim that its messages can be recovered from a retained conversation. | ||
|
|
@@ -160,6 +164,7 @@ func (resp *Response) ToUpdates() []*ResponseUpdate { | |
| AgentID: resp.AgentID, | ||
| MessageID: msg.ID, | ||
| ResponseID: resp.ID, | ||
| ModelID: resp.ModelID, | ||
|
|
||
| ConversationID: resp.ConversationID, | ||
| FinishReason: resp.FinishReason, | ||
| AuthorName: msg.AuthorName, | ||
|
|
@@ -169,11 +174,12 @@ func (resp *Response) ToUpdates() []*ResponseUpdate { | |
| }) | ||
| } | ||
|
|
||
| if hasAdditionalProperties || resp.ContinuationToken != "" { | ||
| if hasAdditionalProperties || resp.ContinuationToken != "" || resp.ModelID != "" { | ||
|
|
||
| extra := &ResponseUpdate{ | ||
| AdditionalProperties: resp.AdditionalProperties, | ||
| AgentID: resp.AgentID, | ||
| ResponseID: resp.ID, | ||
| ModelID: resp.ModelID, | ||
| ConversationID: resp.ConversationID, | ||
| ContinuationToken: resp.ContinuationToken, | ||
| CreatedAt: resp.CreatedAt, | ||
|
|
@@ -216,6 +222,7 @@ func (resp *Response) Update(update *ResponseUpdate) { | |
| // clear values already received for the response. | ||
| resp.AgentID = cmp.Or(update.AgentID, resp.AgentID) | ||
| resp.ID = cmp.Or(update.ResponseID, resp.ID) | ||
| resp.ModelID = cmp.Or(update.ModelID, resp.ModelID) | ||
| if update.ConversationID != nil { | ||
| resp.ConversationID = update.ConversationID | ||
| } | ||
|
|
@@ -313,6 +320,11 @@ type ResponseUpdate struct { | |
| // ResponseID identifies the response of which this update is a part. | ||
| ResponseID string | ||
|
|
||
| // ModelID is the identifier of the model that produced this update, when the | ||
| // provider supplies it. It is typically set on updates that carry provider | ||
| // response metadata. | ||
| ModelID string `json:",omitzero"` | ||
|
|
||
| // ConversationID identifies history retained by the service or per-service-call | ||
| // history persistence. Providers set it only when later requests can refer to that | ||
| // history instead of resending the messages. Nil means this update does not | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1119,6 +1119,7 @@ func responsesProcessResponse(resp *responses.Response, seqNum int64, yield func | |
|
|
||
| currentUpdate := &agent.ResponseUpdate{ | ||
| ResponseID: resp.ID, | ||
| ModelID: resp.Model, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ModelID is only propagated on non-streaming responses across three providers This PR populates
Upstream M.E.AI sets
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed — ModelID is now set on the streaming updates for all three providers: OpenAI Responses threads the model through responsesStreamState from the lifecycle events' Response.Model; Anthropic reads it from the message_start Message.Model; Gemini reads each chunk's ModelVersion (and the final usage update). Added TestStreamingModelIDSurfaced to lock in the Collect() round-trip. |
||
| FinishReason: finishReason, | ||
| CreatedAt: time.Unix(int64(resp.CreatedAt), 0), | ||
| Role: message.RoleAssistant, | ||
|
|
@@ -1140,6 +1141,7 @@ func responsesProcessResponse(resp *responses.Response, seqNum int64, yield func | |
| } | ||
| currentUpdate.MessageID = out.ID | ||
| currentUpdate.ResponseID = resp.ID | ||
| currentUpdate.ModelID = resp.Model | ||
| currentUpdate.FinishReason = finishReason | ||
| // Only set ContinuationToken if it's not empty | ||
| if contToken != "" { | ||
|
|
@@ -1429,6 +1431,7 @@ func responsesErrorContent(msg string, code string, details string) *message.Err | |
| type responsesStreamState struct { | ||
| mcpApprovalRequests map[string]*message.ToolApprovalRequestContent | ||
| messageID string | ||
| model string | ||
| role message.Role | ||
| anyFunctions bool | ||
| // imagePartialsSeen records image-generation item IDs that emitted a | ||
|
|
@@ -1447,12 +1450,23 @@ func responsesProcessStreamingUpdate(update responses.ResponseStreamEventUnion, | |
| Role: role, | ||
| Contents: contents, | ||
| MessageID: state.messageID, | ||
| ModelID: state.model, | ||
| ResponseID: responseID, | ||
| RawRepresentation: update, | ||
| } | ||
| return u | ||
| } | ||
|
|
||
| // setModel records the response model from a lifecycle event so this and | ||
| // every subsequent streaming update carries it, matching the non-streaming | ||
| // path. The createUpdate above runs before this, so stamp u directly too. | ||
| setModel := func(u *agent.ResponseUpdate, model string) { | ||
| if model != "" { | ||
| state.model = model | ||
| u.ModelID = model | ||
| } | ||
| } | ||
|
|
||
| // Lifecycle metadata belongs to the response, not the active message. | ||
| // Omit its MessageID without resetting the state used by content updates. | ||
| var u *agent.ResponseUpdate | ||
|
|
@@ -1462,6 +1476,7 @@ func responsesProcessStreamingUpdate(update responses.ResponseStreamEventUnion, | |
| u.MessageID = "" | ||
| u.CreatedAt = time.Unix(int64(event.Response.CreatedAt), 0) | ||
| u.ResponseID = event.Response.ID | ||
| setModel(u, event.Response.Model) | ||
| u.AdditionalProperties = responsesPopulateAdditionalProperties(&event.Response) | ||
| if contToken := createContinuationToken(event.Response.ID, event.SequenceNumber, event.Response.Status, isBackground); contToken != "" { | ||
| u.ContinuationToken = contToken | ||
|
|
@@ -1472,6 +1487,7 @@ func responsesProcessStreamingUpdate(update responses.ResponseStreamEventUnion, | |
| u.MessageID = "" | ||
| u.CreatedAt = time.Unix(int64(event.Response.CreatedAt), 0) | ||
| u.ResponseID = event.Response.ID | ||
| setModel(u, event.Response.Model) | ||
| u.AdditionalProperties = responsesPopulateAdditionalProperties(&event.Response) | ||
| if contToken := createContinuationToken(event.Response.ID, event.SequenceNumber, event.Response.Status, isBackground); contToken != "" { | ||
| u.ContinuationToken = contToken | ||
|
|
@@ -1482,6 +1498,7 @@ func responsesProcessStreamingUpdate(update responses.ResponseStreamEventUnion, | |
| u.MessageID = "" | ||
| u.CreatedAt = time.Unix(int64(event.Response.CreatedAt), 0) | ||
| u.ResponseID = event.Response.ID | ||
| setModel(u, event.Response.Model) | ||
| u.AdditionalProperties = responsesPopulateAdditionalProperties(&event.Response) | ||
| if contToken := createContinuationToken(event.Response.ID, event.SequenceNumber, event.Response.Status, isBackground); contToken != "" { | ||
| u.ContinuationToken = contToken | ||
|
|
@@ -1509,6 +1526,7 @@ func responsesProcessStreamingUpdate(update responses.ResponseStreamEventUnion, | |
| u.MessageID = "" | ||
| u.CreatedAt = time.Unix(int64(event.Response.CreatedAt), 0) | ||
| u.ResponseID = event.Response.ID | ||
| setModel(u, event.Response.Model) | ||
| u.FinishReason = responsesFinishReason(&event.Response) | ||
| if state.anyFunctions && u.FinishReason == "stop" { | ||
| u.FinishReason = "tool_calls" | ||
|
|
@@ -1524,6 +1542,7 @@ func responsesProcessStreamingUpdate(update responses.ResponseStreamEventUnion, | |
| u.MessageID = "" | ||
| u.CreatedAt = time.Unix(int64(event.Response.CreatedAt), 0) | ||
| u.ResponseID = event.Response.ID | ||
| setModel(u, event.Response.Model) | ||
| u.FinishReason = responsesFinishReason(&event.Response) | ||
| u.AdditionalProperties = responsesPopulateAdditionalProperties(&event.Response) | ||
| if contToken := createContinuationToken(event.Response.ID, event.SequenceNumber, event.Response.Status, isBackground); contToken != "" { | ||
|
|
@@ -1535,6 +1554,7 @@ func responsesProcessStreamingUpdate(update responses.ResponseStreamEventUnion, | |
| u.MessageID = "" | ||
| u.CreatedAt = time.Unix(int64(event.Response.CreatedAt), 0) | ||
| u.ResponseID = event.Response.ID | ||
| setModel(u, event.Response.Model) | ||
| u.AdditionalProperties = responsesPopulateAdditionalProperties(&event.Response) | ||
| if failure := responsesFailureContent(&event.Response); failure != nil { | ||
| u.Contents = []message.Content{failure} | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR adds
ModelIDtoagent.Response/agent.ResponseUpdate(the Go equivalent of upstreamAgentResponse/AgentResponseUpdate, notChatResponse/ChatResponseUpdate). Upstream,ModelId/modelexists only on the lower-levelChatResponse/ChatResponseUpdatetypes:Microsoft.Agents.AI.Abstractions/AgentResponse.csandAgentResponseUpdate.cshave noModelIdproperty (properties areAgentId,ResponseId,ContinuationToken,CreatedAt,FinishReason,Usage,RawRepresentation,AdditionalProperties).ModelIdis folded only inAIAgentChatClient.CloneWithConversationIdonChatResponse(dotnet/src/Microsoft.Agents.AI/ChatClient/AIAgentChatClient.cs:368), and referenced inAgentResponseUpdateTests.ConstructorWithChatResponseUpdateRoundtrips(dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentResponseUpdateTests.cs:42) as aChatResponseUpdatefield that is not asserted to roundtrip ontoAgentResponseUpdate.AgentResponse.__init__/AgentResponseUpdate.__init__(python/packages/core/agent_framework/_types.py:2848and:3134) take nomodel/model_idparameter, while the siblingChatResponse.__init__/ChatResponseUpdate.__init__(same file,:2449and:2735) do.So both upstream implementations deliberately keep model identity at the chat-client layer and omit it from the agent-level response contract. Adding
ModelIDunconditionally to Go'sagent.Response/ResponseUpdate(theAgentResponseanalog) is a divergence from that design, not merely an idiomatic Go difference — it's a new agent-level field neither upstream implementation exposes.Suggested resolution: either (a) confirm with maintainers this is an intentional Go-specific enhancement over the agent-level contract (and document that divergence), or (b) if a
ModelIDsurface is wanted, scope it to a chat-level type analogous toChatResponse/ChatResponseUpdateif/when Go introduces one, rather thanagent.Response.