diff --git a/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/ChatCompletions/Models/StopSequences.cs b/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/ChatCompletions/Models/StopSequences.cs index bed3b2a3206..3a97f2f19b0 100644 --- a/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/ChatCompletions/Models/StopSequences.cs +++ b/dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/ChatCompletions/Models/StopSequences.cs @@ -183,7 +183,7 @@ public override void Write(Utf8JsonWriter writer, StopSequences? value, JsonSeri } else if (value.IsSequences) { - JsonSerializer.Serialize(writer, value.Sequences, ChatCompletionsJsonContext.Default.IReadOnlyListMessageContentPart); + JsonSerializer.Serialize(writer, value.Sequences, ChatCompletionsJsonContext.Default.IListString); } else { diff --git a/dotnet/tests/Microsoft.Agents.AI.Hosting.OpenAI.UnitTests/OpenAIChatCompletionsSerializationTests.cs b/dotnet/tests/Microsoft.Agents.AI.Hosting.OpenAI.UnitTests/OpenAIChatCompletionsSerializationTests.cs index edf11fbf6bb..86e9292d62b 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Hosting.OpenAI.UnitTests/OpenAIChatCompletionsSerializationTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Hosting.OpenAI.UnitTests/OpenAIChatCompletionsSerializationTests.cs @@ -54,6 +54,25 @@ public void Deserialize_BasicRequest_RoundTrip() Assert.Equal(request.Messages.Count, roundtripped.Messages.Count); } + [Fact] + public void Serialize_RequestWithMultipleStopSequences_WritesStringArray() + { + // Arrange + string originalJson = LoadChatCompletionsTraceFile("basic/request.json"); + CreateChatCompletion request = JsonSerializer.Deserialize(originalJson, ChatCompletions.ChatCompletionsJsonContext.Default.CreateChatCompletion)!; + request.Stop = StopSequences.FromSequences(["END", "STOP"]); + + // Act + string json = JsonSerializer.Serialize(request, ChatCompletions.ChatCompletionsJsonContext.Default.CreateChatCompletion); + using JsonDocument document = JsonDocument.Parse(json); + + // Assert +JsonElement stop = document.RootElement.GetProperty("stop"); +Assert.Equal(JsonValueKind.Array, stop.ValueKind); +string[] stopValues = stop.EnumerateArray().Select(static e => e.GetString()!).ToArray(); +Assert.Equal(["END", "STOP"], stopValues); + } + [Fact] public void Deserialize_BasicRequest_HasMessages() {