Add an AgentRunResponse ctor accepting a ChatResponse (#204)

* Add an AgentRunResponse ctor accepting a ChatResponse

* Update dotnet/src/Microsoft.Extensions.AI.Agents.Abstractions/AgentRunResponseUpdate.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Stephen Toub
2025-07-21 14:49:47 +00:00
committed by GitHub
co-authored by Copilot
parent a8fadbc49c
commit d964b05ae7
6 changed files with 85 additions and 62 deletions
@@ -43,6 +43,28 @@ public class AgentRunResponseTests
Assert.Same(messages, response.Messages);
}
[Fact]
public void ConstructorWithChatResponseRoundtrips()
{
ChatResponse chatResponse = new()
{
AdditionalProperties = new(),
CreatedAt = new DateTimeOffset(2022, 1, 1, 0, 0, 0, TimeSpan.Zero),
Messages = [new(ChatRole.Assistant, "This is a test message.")],
RawRepresentation = new object(),
ResponseId = "responseId",
Usage = new UsageDetails(),
};
AgentRunResponse response = new(chatResponse);
Assert.Same(chatResponse.AdditionalProperties, response.AdditionalProperties);
Assert.Equal(chatResponse.CreatedAt, response.CreatedAt);
Assert.Same(chatResponse.Messages, response.Messages);
Assert.Equal(chatResponse.ResponseId, response.ResponseId);
Assert.Same(chatResponse.RawRepresentation, response.RawRepresentation);
Assert.Same(chatResponse.Usage, response.Usage);
}
[Fact]
public void PropertiesRoundtrip()
{
@@ -24,6 +24,35 @@ public class AgentRunResponseUpdateTests
Assert.Equal(string.Empty, update.ToString());
}
[Fact]
public void ConstructorWithChatResponseUpdateRoundtrips()
{
ChatResponseUpdate chatResponseUpdate = new()
{
AdditionalProperties = new(),
AuthorName = "author",
Contents = [new TextContent("hello")],
ConversationId = "conversationId",
CreatedAt = new DateTimeOffset(2022, 1, 1, 0, 0, 0, TimeSpan.Zero),
FinishReason = ChatFinishReason.Length,
MessageId = "messageId",
ModelId = "modelId",
RawRepresentation = new object(),
ResponseId = "responseId",
Role = ChatRole.Assistant,
};
AgentRunResponseUpdate response = new(chatResponseUpdate);
Assert.Same(chatResponseUpdate.AdditionalProperties, response.AdditionalProperties);
Assert.Equal(chatResponseUpdate.AuthorName, response.AuthorName);
Assert.Same(chatResponseUpdate.Contents, response.Contents);
Assert.Equal(chatResponseUpdate.CreatedAt, response.CreatedAt);
Assert.Equal(chatResponseUpdate.MessageId, response.MessageId);
Assert.Same(chatResponseUpdate.RawRepresentation, response.RawRepresentation);
Assert.Equal(chatResponseUpdate.ResponseId, response.ResponseId);
Assert.Equal(chatResponseUpdate.Role, response.Role);
}
[Fact]
public void PropertiesRoundtrip()
{