.NET: Clean / address some message warnings (#291)

* WIP

* Structured Output sample

* Update dotnet/samples/GettingStarted/Steps/Step06_ChatClientAgent_StructuredOutputs.cs

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

* Address xml and comment targeting the Structured Output context

* Update with proposed fix for Persistent ChatClient

* Address PR feedback

* Address minor warnings

* Address initialization

* Address initialization

* Address PR comments, update suggestions

* Revert changes to NullableAttributese.cs

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Chris <66376200+crickman@users.noreply.github.com>
This commit is contained in:
Roger Barreto
2025-08-05 12:55:44 +00:00
committed by GitHub
co-authored by Copilot Chris
parent cbb05e210f
commit 9faa27b8eb
19 changed files with 63 additions and 73 deletions
@@ -1,6 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.
#pragma warning disable CA1019
#pragma warning disable CA1019, RCS1251, IDE0300
namespace System.Diagnostics.CodeAnalysis;
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.
#pragma warning disable RCS1157 // Composite enum value contains undefined flag
namespace System.Diagnostics.CodeAnalysis;
/// <summary>
@@ -41,12 +41,17 @@ public partial class ConcurrentOrchestration : OrchestratingAgent
return f;
}
return static async (responses, cancellationToken) =>
new AgentRunResponse([.. responses.Where(r => r.Messages.Count > 0).Select(r =>
{
var messages = r.Messages;
return messages.Count > 0 ? messages[messages.Count - 1] : new();
})]);
return (responses, cancellationToken)
=> Task.FromResult(
new AgentRunResponse([.. responses
.Where(r => r.Messages.Count > 0)
.Select(r =>
{
var messages = r.Messages;
return messages.Count > 0 ? messages[messages.Count - 1] : new();
})
])
);
}
set => this._aggregationFunc = value;
}
@@ -509,6 +509,7 @@ namespace Azure.AI.Agents.Persistent
// We need to extract the run ID and ensure that the ToolOutput we send back to Azure
// is only the call ID.
string[]? runAndCallIDs;
#pragma warning disable CA1031 // Do not catch general exception types
try
{
runAndCallIDs = JsonSerializer.Deserialize(frc.CallId, AgentsChatClientJsonContext.Default.StringArray);
@@ -517,6 +518,7 @@ namespace Azure.AI.Agents.Persistent
{
continue;
}
#pragma warning restore CA1031 // Do not catch general exception types
if (runAndCallIDs is null ||
runAndCallIDs.Length != 2 ||
@@ -2,7 +2,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
@@ -126,7 +125,7 @@ public sealed class ChatClientAgent : AIAgent
}
// Convert the chat response messages to a valid IReadOnlyCollection for notification signatures below.
var chatResponseMessages = chatResponse.Messages as IReadOnlyCollection<ChatMessage> ?? chatResponse.Messages.ToArray();
var chatResponseMessages = chatResponse.Messages as IReadOnlyCollection<ChatMessage> ?? [.. chatResponse.Messages];
await this.NotifyThreadOfNewMessagesAsync(chatClientThread, chatResponseMessages, cancellationToken).ConfigureAwait(false);
@@ -174,7 +173,7 @@ public sealed class ChatClientAgent : AIAgent
}
var chatResponse = responseUpdates.ToChatResponse();
var chatResponseMessages = chatResponse.Messages as IReadOnlyCollection<ChatMessage> ?? chatResponse.Messages.ToArray();
var chatResponseMessages = chatResponse.Messages as IReadOnlyCollection<ChatMessage> ?? [.. chatResponse.Messages];
// We can derive the type of supported thread from whether we have a conversation id,
// so let's update it and set the conversation id for the service thread case.
@@ -72,28 +72,11 @@ public sealed class TestConfiguration
this._configRoot = configRoot;
}
/// <summary>
/// Provides access to the configuration root for the application.
/// </summary>
private static IConfigurationRoot? ConfigurationRoot => s_instance?._configRoot;
/// <summary>
/// Gets the configuration settings for the AzureAI integration.
/// </summary>
public static AzureAIConfig AzureAI => LoadSection<AzureAIConfig>();
/// <summary>
/// Retrieves a configuration section based on the specified key.
/// </summary>
/// <param name="caller">The key identifying the configuration section to retrieve. Cannot be null or empty.</param>
/// <returns>The <see cref="IConfigurationSection"/> corresponding to the specified key.</returns>
/// <exception cref="InvalidOperationException">Thrown if the configuration root is not initialized or the specified key does not correspond to a valid section.</exception>
private static IConfigurationSection GetSection(string caller)
{
return s_instance?._configRoot.GetSection(caller) ??
throw new InvalidOperationException(caller);
}
private static T LoadSection<T>([CallerMemberName] string? caller = null)
{
if (s_instance is null)