diff --git a/dotnet/src/Agents/Abstractions/AgentChat.cs b/dotnet/src/Agents/Abstractions/AgentChat.cs index f458739e3bb4..f0699f5d7c7d 100644 --- a/dotnet/src/Agents/Abstractions/AgentChat.cs +++ b/dotnet/src/Agents/Abstractions/AgentChat.cs @@ -213,7 +213,7 @@ protected async IAsyncEnumerable InvokeAgentAsync( { this.SetActivityOrThrow(); // Disallow concurrent access to chat history - this.Logger.LogAgentChatInvokingAgent(nameof(InvokeAgentAsync), agent.GetType(), agent.Id); + this.Logger.LogAgentChatInvokingAgent(nameof(InvokeAgentAsync), agent.GetType(), agent.Id, agent.GetDisplayName()); try { @@ -226,7 +226,7 @@ protected async IAsyncEnumerable InvokeAgentAsync( await foreach ((bool isVisible, ChatMessageContent message) in channel.InvokeAsync(agent, cancellationToken).ConfigureAwait(false)) { - this.Logger.LogAgentChatInvokedAgentMessage(nameof(InvokeAgentAsync), agent.GetType(), agent.Id, message); + this.Logger.LogAgentChatInvokedAgentMessage(nameof(InvokeAgentAsync), agent.GetType(), agent.Id, agent.GetDisplayName(), message); messages.Add(message); @@ -248,7 +248,7 @@ protected async IAsyncEnumerable InvokeAgentAsync( .Select(kvp => new ChannelReference(kvp.Value, kvp.Key)); this._broadcastQueue.Enqueue(channelRefs, messages); - this.Logger.LogAgentChatInvokedAgent(nameof(InvokeAgentAsync), agent.GetType(), agent.Id); + this.Logger.LogAgentChatInvokedAgent(nameof(InvokeAgentAsync), agent.GetType(), agent.Id, agent.GetDisplayName()); } finally { @@ -272,7 +272,7 @@ protected async IAsyncEnumerable InvokeStreamingAge { this.SetActivityOrThrow(); // Disallow concurrent access to chat history - this.Logger.LogAgentChatInvokingAgent(nameof(InvokeAgentAsync), agent.GetType(), agent.Id); + this.Logger.LogAgentChatInvokingAgent(nameof(InvokeAgentAsync), agent.GetType(), agent.Id, agent.GetDisplayName()); try { @@ -290,7 +290,7 @@ protected async IAsyncEnumerable InvokeStreamingAge this.History.AddRange(messages); - this.Logger.LogAgentChatInvokedStreamingAgentMessages(nameof(InvokeAgentAsync), agent.GetType(), agent.Id, messages); + this.Logger.LogAgentChatInvokedStreamingAgentMessages(nameof(InvokeAgentAsync), agent.GetType(), agent.Id, agent.GetDisplayName(), messages); // Broadcast message to other channels (in parallel) // Note: Able to queue messages without synchronizing channels. @@ -300,7 +300,7 @@ protected async IAsyncEnumerable InvokeStreamingAge .Select(kvp => new ChannelReference(kvp.Value, kvp.Key)); this._broadcastQueue.Enqueue(channelRefs, messages); - this.Logger.LogAgentChatInvokedAgent(nameof(InvokeAgentAsync), agent.GetType(), agent.Id); + this.Logger.LogAgentChatInvokedAgent(nameof(InvokeAgentAsync), agent.GetType(), agent.Id, agent.GetDisplayName()); } finally { @@ -433,7 +433,7 @@ private async Task GetOrCreateChannelAsync(Agent agent, Cancellati AgentChannel? channel = await this.SynchronizeChannelAsync(channelKey, cancellationToken).ConfigureAwait(false); if (channel is null) { - this.Logger.LogAgentChatCreatingChannel(nameof(InvokeAgentAsync), agent.GetType(), agent.Id); + this.Logger.LogAgentChatCreatingChannel(nameof(InvokeAgentAsync), agent.GetType(), agent.Id, agent.GetDisplayName()); channel = await agent.CreateChannelAsync(cancellationToken).ConfigureAwait(false); @@ -445,7 +445,7 @@ private async Task GetOrCreateChannelAsync(Agent agent, Cancellati await channel.ReceiveAsync(this.History, cancellationToken).ConfigureAwait(false); } - this.Logger.LogAgentChatCreatedChannel(nameof(InvokeAgentAsync), agent.GetType(), agent.Id); + this.Logger.LogAgentChatCreatedChannel(nameof(InvokeAgentAsync), agent.GetType(), agent.Id, agent.GetDisplayName()); } return channel; diff --git a/dotnet/src/Agents/Abstractions/Agents.Abstractions.csproj b/dotnet/src/Agents/Abstractions/Agents.Abstractions.csproj index 86d2f37c2b66..364e8419f0d1 100644 --- a/dotnet/src/Agents/Abstractions/Agents.Abstractions.csproj +++ b/dotnet/src/Agents/Abstractions/Agents.Abstractions.csproj @@ -20,6 +20,7 @@ + diff --git a/dotnet/src/Agents/Abstractions/Logging/AgentChatLogMessages.cs b/dotnet/src/Agents/Abstractions/Logging/AgentChatLogMessages.cs index ebd9e83b42ce..22c2bda0e5da 100644 --- a/dotnet/src/Agents/Abstractions/Logging/AgentChatLogMessages.cs +++ b/dotnet/src/Agents/Abstractions/Logging/AgentChatLogMessages.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Microsoft.Extensions.Logging; +using Microsoft.SemanticKernel.Agents.Extensions; namespace Microsoft.SemanticKernel.Agents; @@ -21,11 +22,12 @@ internal static partial class AgentChatLogMessages /// /// Logs retrieval of messages. /// - private static readonly Action s_logAgentChatGetChatMessages = - LoggerMessage.Define( + private static readonly Action s_logAgentChatGetChatMessages = + LoggerMessage.Define( logLevel: LogLevel.Debug, eventId: 0, - "[{MethodName}] Source: {MessageSourceType}/{MessageSourceId}."); + "[{MethodName}] Source: {MessageSourceType}/{MessageSourceId}/{MessageSourceName}."); + public static void LogAgentChatGetChatMessages( this ILogger logger, string methodName, @@ -33,13 +35,13 @@ public static void LogAgentChatGetChatMessages( { if (logger.IsEnabled(LogLevel.Debug)) { - if (null == agent) + if (agent is null) { - s_logAgentChatGetChatMessages(logger, methodName, "primary", "primary", null); + s_logAgentChatGetChatMessages(logger, methodName, "primary", "primary", null, null); } else { - s_logAgentChatGetChatMessages(logger, methodName, agent.GetType().Name, agent.Id, null); + s_logAgentChatGetChatMessages(logger, methodName, agent.GetType().Name, agent.Id, agent.GetDisplayName(), null); } } } @@ -74,12 +76,13 @@ public static partial void LogAgentChatAddedMessages( [LoggerMessage( EventId = 0, Level = LogLevel.Debug, - Message = "[{MethodName}] Invoking agent {AgentType}/{AgentId}.")] + Message = "[{MethodName}] Invoking agent {AgentType}/{AgentId}/{AgentName}.")] public static partial void LogAgentChatInvokingAgent( this ILogger logger, string methodName, Type agentType, - string agentId); + string agentId, + string agentName); /// /// Logs invoked agent message @@ -87,35 +90,37 @@ public static partial void LogAgentChatInvokingAgent( [LoggerMessage( EventId = 0, Level = LogLevel.Trace, - Message = "[{MethodName}] Agent message {AgentType}/{AgentId}: {Message}.")] + Message = "[{MethodName}] Agent message {AgentType}/{AgentId}/{AgentName}: {Message}.")] public static partial void LogAgentChatInvokedAgentMessage( this ILogger logger, string methodName, Type agentType, string agentId, + string agentName, ChatMessageContent message); /// /// Logs retrieval of streamed messages. /// - private static readonly Action s_logAgentChatInvokedStreamingAgentMessages = - LoggerMessage.Define( + private static readonly Action s_logAgentChatInvokedStreamingAgentMessages = + LoggerMessage.Define( logLevel: LogLevel.Debug, eventId: 0, - "[{MethodName}] Agent message {AgentType}/{AgentId}: {Message}."); + "[{MethodName}] Agent message {AgentType}/{AgentId}/{AgentName}: {Message}."); public static void LogAgentChatInvokedStreamingAgentMessages( this ILogger logger, string methodName, Type agentType, string agentId, + string agentName, IList messages) { if (logger.IsEnabled(LogLevel.Debug)) { foreach (ChatMessageContent message in messages) { - s_logAgentChatInvokedStreamingAgentMessages(logger, methodName, agentType, agentId, message, null); + s_logAgentChatInvokedStreamingAgentMessages(logger, methodName, agentType, agentId, agentName, message, null); } } } @@ -126,12 +131,13 @@ public static void LogAgentChatInvokedStreamingAgentMessages( [LoggerMessage( EventId = 0, Level = LogLevel.Information, - Message = "[{MethodName}] Invoked agent {AgentType}/{AgentId}.")] + Message = "[{MethodName}] Invoked agent {AgentType}/{AgentId}/{AgentName}.")] public static partial void LogAgentChatInvokedAgent( this ILogger logger, string methodName, Type agentType, - string agentId); + string agentId, + string agentName); /// /// Logs creating agent channel (started). @@ -139,12 +145,13 @@ public static partial void LogAgentChatInvokedAgent( [LoggerMessage( EventId = 0, Level = LogLevel.Debug, - Message = "[{MethodName}] Creating channel for {AgentType}: {AgentId}")] + Message = "[{MethodName}] Creating channel for {AgentType}: {AgentId}/{AgentName}")] public static partial void LogAgentChatCreatingChannel( this ILogger logger, string methodName, Type agentType, - string agentId); + string agentId, + string agentName); /// /// Logs created agent channel (complete). @@ -152,10 +159,11 @@ public static partial void LogAgentChatCreatingChannel( [LoggerMessage( EventId = 0, Level = LogLevel.Information, - Message = "[{MethodName}] Created channel for {AgentType}: {AgentId}")] + Message = "[{MethodName}] Created channel for {AgentType}: {AgentId}/{AgentName}")] public static partial void LogAgentChatCreatedChannel( this ILogger logger, string methodName, Type agentType, - string agentId); + string agentId, + string agentName); } diff --git a/dotnet/src/Agents/Core/AgentGroupChat.cs b/dotnet/src/Agents/Core/AgentGroupChat.cs index 5d80f969eb4e..2fee70eb8da7 100644 --- a/dotnet/src/Agents/Core/AgentGroupChat.cs +++ b/dotnet/src/Agents/Core/AgentGroupChat.cs @@ -8,6 +8,7 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.SemanticKernel.Agents.Chat; +using Microsoft.SemanticKernel.Agents.Extensions; namespace Microsoft.SemanticKernel.Agents; @@ -134,7 +135,7 @@ public async IAsyncEnumerable InvokeAsync( { this.EnsureStrategyLoggerAssignment(); - this.Logger.LogAgentGroupChatInvokingAgent(nameof(InvokeAsync), agent.GetType(), agent.Id); + this.Logger.LogAgentGroupChatInvokingAgent(nameof(InvokeAsync), agent.GetType(), agent.Id, agent.GetDisplayName()); this.AddAgent(agent); @@ -163,7 +164,7 @@ public async IAsyncEnumerable InvokeStreamingAsync( { this.EnsureStrategyLoggerAssignment(); - this.Logger.LogAgentGroupChatInvokingAgent(nameof(InvokeAsync), agent.GetType(), agent.Id); + this.Logger.LogAgentGroupChatInvokingAgent(nameof(InvokeAsync), agent.GetType(), agent.Id, agent.GetDisplayName()); this.AddAgent(agent); @@ -255,7 +256,7 @@ private async Task SelectAgentAsync(CancellationToken cancellationToken) throw; } - this.Logger.LogAgentGroupChatSelectedAgent(nameof(InvokeAsync), agent.GetType(), agent.Id, this.ExecutionSettings.SelectionStrategy.GetType()); + this.Logger.LogAgentGroupChatSelectedAgent(nameof(InvokeAsync), agent.GetType(), agent.Id, agent.GetDisplayName(), this.ExecutionSettings.SelectionStrategy.GetType()); return agent; } diff --git a/dotnet/src/Agents/Core/Agents.Core.csproj b/dotnet/src/Agents/Core/Agents.Core.csproj index da87688ac22f..46c0aa95e196 100644 --- a/dotnet/src/Agents/Core/Agents.Core.csproj +++ b/dotnet/src/Agents/Core/Agents.Core.csproj @@ -22,6 +22,7 @@ + diff --git a/dotnet/src/Agents/Core/Chat/SequentialSelectionStrategy.cs b/dotnet/src/Agents/Core/Chat/SequentialSelectionStrategy.cs index 4983d0752414..45d21f5c51d8 100644 --- a/dotnet/src/Agents/Core/Chat/SequentialSelectionStrategy.cs +++ b/dotnet/src/Agents/Core/Chat/SequentialSelectionStrategy.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using Microsoft.SemanticKernel.Agents.Extensions; namespace Microsoft.SemanticKernel.Agents.Chat; @@ -42,7 +43,7 @@ protected override Task SelectAgentAsync(IReadOnlyList agents, IRe Agent agent = agents[this._index]; - this.Logger.LogSequentialSelectionStrategySelectedAgent(nameof(NextAsync), this._index, agents.Count, agent.Id); + this.Logger.LogSequentialSelectionStrategySelectedAgent(nameof(NextAsync), this._index, agents.Count, agent.Id, agent.GetDisplayName()); return Task.FromResult(agent); diff --git a/dotnet/src/Agents/Core/Chat/TerminationStrategy.cs b/dotnet/src/Agents/Core/Chat/TerminationStrategy.cs index b50f6bd96d11..280a07aeaecf 100644 --- a/dotnet/src/Agents/Core/Chat/TerminationStrategy.cs +++ b/dotnet/src/Agents/Core/Chat/TerminationStrategy.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; +using Microsoft.SemanticKernel.Agents.Extensions; namespace Microsoft.SemanticKernel.Agents.Chat; @@ -55,19 +56,19 @@ public abstract class TerminationStrategy /// True to terminate chat loop. public async Task ShouldTerminateAsync(Agent agent, IReadOnlyList history, CancellationToken cancellationToken = default) { - this.Logger.LogTerminationStrategyEvaluatingCriteria(nameof(ShouldTerminateAsync), agent.GetType(), agent.Id); + this.Logger.LogTerminationStrategyEvaluatingCriteria(nameof(ShouldTerminateAsync), agent.GetType(), agent.Id, agent.GetDisplayName()); // `Agents` must contain `agent`, if `Agents` not empty. if ((this.Agents?.Count ?? 0) > 0 && !this.Agents!.Any(a => a.Id == agent.Id)) { - this.Logger.LogTerminationStrategyAgentOutOfScope(nameof(ShouldTerminateAsync), agent.GetType(), agent.Id); + this.Logger.LogTerminationStrategyAgentOutOfScope(nameof(ShouldTerminateAsync), agent.GetType(), agent.Id, agent.GetDisplayName()); return false; } bool shouldTerminate = await this.ShouldAgentTerminateAsync(agent, history, cancellationToken).ConfigureAwait(false); - this.Logger.LogTerminationStrategyEvaluatedCriteria(nameof(ShouldTerminateAsync), agent.GetType(), agent.Id, shouldTerminate); + this.Logger.LogTerminationStrategyEvaluatedCriteria(nameof(ShouldTerminateAsync), agent.GetType(), agent.Id, agent.GetDisplayName(), shouldTerminate); return shouldTerminate; } diff --git a/dotnet/src/Agents/Core/ChatCompletionAgent.cs b/dotnet/src/Agents/Core/ChatCompletionAgent.cs index 770153bbfb1e..e669cb14ae70 100644 --- a/dotnet/src/Agents/Core/ChatCompletionAgent.cs +++ b/dotnet/src/Agents/Core/ChatCompletionAgent.cs @@ -5,6 +5,7 @@ using System.Text.Json; using System.Threading; using System.Threading.Tasks; +using Microsoft.SemanticKernel.Agents.Extensions; using Microsoft.SemanticKernel.ChatCompletion; using Microsoft.SemanticKernel.Services; @@ -59,7 +60,7 @@ public override async IAsyncEnumerable InvokeAsync( int messageCount = chat.Count; - this.Logger.LogAgentChatServiceInvokingAgent(nameof(InvokeAsync), this.Id, chatCompletionService.GetType()); + this.Logger.LogAgentChatServiceInvokingAgent(nameof(InvokeAsync), this.Id, this.GetDisplayName(), chatCompletionService.GetType()); IReadOnlyList messages = await chatCompletionService.GetChatMessageContentsAsync( @@ -68,7 +69,7 @@ await chatCompletionService.GetChatMessageContentsAsync( kernel, cancellationToken).ConfigureAwait(false); - this.Logger.LogAgentChatServiceInvokedAgent(nameof(InvokeAsync), this.Id, chatCompletionService.GetType(), messages.Count); + this.Logger.LogAgentChatServiceInvokedAgent(nameof(InvokeAsync), this.Id, this.GetDisplayName(), chatCompletionService.GetType(), messages.Count); // Capture mutated messages related function calling / tools for (int messageIndex = messageCount; messageIndex < chat.Count; messageIndex++) @@ -104,7 +105,7 @@ public override async IAsyncEnumerable InvokeStream int messageCount = chat.Count; - this.Logger.LogAgentChatServiceInvokingAgent(nameof(InvokeAsync), this.Id, chatCompletionService.GetType()); + this.Logger.LogAgentChatServiceInvokingAgent(nameof(InvokeAsync), this.Id, this.GetDisplayName(), chatCompletionService.GetType()); IAsyncEnumerable messages = chatCompletionService.GetStreamingChatMessageContentsAsync( @@ -113,7 +114,7 @@ public override async IAsyncEnumerable InvokeStream kernel, cancellationToken); - this.Logger.LogAgentChatServiceInvokedStreamingAgent(nameof(InvokeAsync), this.Id, chatCompletionService.GetType()); + this.Logger.LogAgentChatServiceInvokedStreamingAgent(nameof(InvokeAsync), this.Id, this.GetDisplayName(), chatCompletionService.GetType()); AuthorRole? role = null; StringBuilder builder = new(); diff --git a/dotnet/src/Agents/Core/Logging/AgentGroupChatLogMessages.cs b/dotnet/src/Agents/Core/Logging/AgentGroupChatLogMessages.cs index 03b9d27f1c8d..81552b57887e 100644 --- a/dotnet/src/Agents/Core/Logging/AgentGroupChatLogMessages.cs +++ b/dotnet/src/Agents/Core/Logging/AgentGroupChatLogMessages.cs @@ -4,6 +4,7 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; using Microsoft.Extensions.Logging; +using Microsoft.SemanticKernel.Agents.Extensions; namespace Microsoft.SemanticKernel.Agents; @@ -25,12 +26,13 @@ internal static partial class AgentGroupChatLogMessages [LoggerMessage( EventId = 0, Level = LogLevel.Debug, - Message = "[{MethodName}] Invoking chat: {AgentType}: {AgentId}")] + Message = "[{MethodName}] Invoking chat: {AgentType}: {AgentId}/{AgentName}")] public static partial void LogAgentGroupChatInvokingAgent( this ILogger logger, string methodName, Type agentType, - string agentId); + string agentId, + string agentName); /// /// Logs invoking agents (started). @@ -40,6 +42,7 @@ public static partial void LogAgentGroupChatInvokingAgent( logLevel: LogLevel.Debug, eventId: 0, "[{MethodName}] Invoking chat: {Agents}"); + public static void LogAgentGroupChatInvokingAgents( this ILogger logger, string methodName, @@ -47,7 +50,9 @@ public static void LogAgentGroupChatInvokingAgents( { if (logger.IsEnabled(LogLevel.Debug)) { - s_logAgentGroupChatInvokingAgents(logger, methodName, string.Join(", ", agents.Select(a => $"{a.GetType()}:{a.Id}")), null); + var agentsMessage = string.Join(", ", agents.Select(a => $"{a.GetType()}:{a.Id}/{a.GetDisplayName()}")); + + s_logAgentGroupChatInvokingAgents(logger, methodName, agentsMessage, null); } } @@ -81,12 +86,13 @@ public static partial void LogAgentGroupChatNoAgentSelected( [LoggerMessage( EventId = 0, Level = LogLevel.Information, - Message = "[{MethodName}] Agent selected {AgentType}: {AgentId} by {StrategyType}")] + Message = "[{MethodName}] Agent selected {AgentType}: {AgentId}/{AgentName} by {StrategyType}")] public static partial void LogAgentGroupChatSelectedAgent( this ILogger logger, string methodName, Type agentType, string agentId, + string agentName, Type strategyType); /// diff --git a/dotnet/src/Agents/Core/Logging/ChatCompletionAgentLogMessages.cs b/dotnet/src/Agents/Core/Logging/ChatCompletionAgentLogMessages.cs index 038c19359cc8..e34a6d102b8f 100644 --- a/dotnet/src/Agents/Core/Logging/ChatCompletionAgentLogMessages.cs +++ b/dotnet/src/Agents/Core/Logging/ChatCompletionAgentLogMessages.cs @@ -23,11 +23,12 @@ internal static partial class ChatCompletionAgentLogMessages [LoggerMessage( EventId = 0, Level = LogLevel.Debug, - Message = "[{MethodName}] Agent #{AgentId} Invoking service {ServiceType}.")] + Message = "[{MethodName}] Agent {AgentId}/{AgentName} Invoking service {ServiceType}.")] public static partial void LogAgentChatServiceInvokingAgent( this ILogger logger, string methodName, string agentId, + string agentName, Type serviceType); /// @@ -36,11 +37,12 @@ public static partial void LogAgentChatServiceInvokingAgent( [LoggerMessage( EventId = 0, Level = LogLevel.Information, - Message = "[{MethodName}] Agent #{AgentId} Invoked service {ServiceType} with message count: {MessageCount}.")] + Message = "[{MethodName}] Agent {AgentId}/{AgentName} Invoked service {ServiceType} with message count: {MessageCount}.")] public static partial void LogAgentChatServiceInvokedAgent( this ILogger logger, string methodName, string agentId, + string agentName, Type serviceType, int messageCount); @@ -50,10 +52,11 @@ public static partial void LogAgentChatServiceInvokedAgent( [LoggerMessage( EventId = 0, Level = LogLevel.Information, - Message = "[{MethodName}] Agent #{AgentId} Invoked service {ServiceType}.")] + Message = "[{MethodName}] Agent {AgentId}/{AgentName} Invoked service {ServiceType}.")] public static partial void LogAgentChatServiceInvokedStreamingAgent( this ILogger logger, string methodName, string agentId, + string agentName, Type serviceType); } diff --git a/dotnet/src/Agents/Core/Logging/SequentialSelectionStrategyLogMessages.cs b/dotnet/src/Agents/Core/Logging/SequentialSelectionStrategyLogMessages.cs index e201dddcd9c0..7af1ddd93b63 100644 --- a/dotnet/src/Agents/Core/Logging/SequentialSelectionStrategyLogMessages.cs +++ b/dotnet/src/Agents/Core/Logging/SequentialSelectionStrategyLogMessages.cs @@ -22,11 +22,12 @@ internal static partial class SequentialSelectionStrategyLogMessages [LoggerMessage( EventId = 0, Level = LogLevel.Information, - Message = "[{MethodName}] Selected agent ({AgentIndex} / {AgentCount}): {AgentId}")] + Message = "[{MethodName}] Selected agent ({AgentIndex} / {AgentCount}): {AgentId}/{AgentName}")] public static partial void LogSequentialSelectionStrategySelectedAgent( this ILogger logger, string methodName, int agentIndex, int agentCount, - string agentId); + string agentId, + string agentName); } diff --git a/dotnet/src/Agents/Core/Logging/TerminationStrategyLogMessages.cs b/dotnet/src/Agents/Core/Logging/TerminationStrategyLogMessages.cs index adbf5ad7b689..79f2e2047f8b 100644 --- a/dotnet/src/Agents/Core/Logging/TerminationStrategyLogMessages.cs +++ b/dotnet/src/Agents/Core/Logging/TerminationStrategyLogMessages.cs @@ -23,12 +23,13 @@ internal static partial class TerminationStrategyLogMessages [LoggerMessage( EventId = 0, Level = LogLevel.Debug, - Message = "[{MethodName}] Evaluating termination for agent {AgentType}: {AgentId}.")] + Message = "[{MethodName}] Evaluating termination for agent {AgentType}: {AgentId}/{AgentName}.")] public static partial void LogTerminationStrategyEvaluatingCriteria( this ILogger logger, string methodName, Type agentType, - string agentId); + string agentId, + string agentName); /// /// Logs agent out of scope. @@ -36,12 +37,13 @@ public static partial void LogTerminationStrategyEvaluatingCriteria( [LoggerMessage( EventId = 0, Level = LogLevel.Debug, - Message = "[{MethodName}] {AgentType} agent out of scope for termination: {AgentId}.")] + Message = "[{MethodName}] {AgentType} agent out of scope for termination: {AgentId}/{AgentName}.")] public static partial void LogTerminationStrategyAgentOutOfScope( this ILogger logger, string methodName, Type agentType, - string agentId); + string agentId, + string agentName); /// /// Logs evaluated criteria (complete). @@ -49,11 +51,12 @@ public static partial void LogTerminationStrategyAgentOutOfScope( [LoggerMessage( EventId = 0, Level = LogLevel.Information, - Message = "[{MethodName}] Evaluated termination for agent {AgentType}: {AgentId} - {TerminationResult}")] + Message = "[{MethodName}] Evaluated termination for agent {AgentType}: {AgentId}/{AgentName} - {TerminationResult}")] public static partial void LogTerminationStrategyEvaluatedCriteria( this ILogger logger, string methodName, Type agentType, string agentId, + string agentName, bool terminationResult); } diff --git a/dotnet/src/InternalUtilities/agents/Extensions/AgentExtensions.cs b/dotnet/src/InternalUtilities/agents/Extensions/AgentExtensions.cs index 871162c27961..bf8c993b210e 100644 --- a/dotnet/src/InternalUtilities/agents/Extensions/AgentExtensions.cs +++ b/dotnet/src/InternalUtilities/agents/Extensions/AgentExtensions.cs @@ -1,9 +1,13 @@ // Copyright (c) Microsoft. All rights reserved. + +using System.Diagnostics.CodeAnalysis; + namespace Microsoft.SemanticKernel.Agents.Extensions; /// /// Extension methods for . /// +[ExcludeFromCodeCoverage] internal static class AgentExtensions { /// @@ -12,8 +16,14 @@ internal static class AgentExtensions /// /// The target agent /// The agent name as a non-empty string - public static string GetName(this Agent agent) - { - return agent.Name ?? agent.Id; - } + public static string GetName(this Agent agent) => agent.Name ?? agent.Id; + + /// + /// Provides the display name of the agent. + /// + /// The target agent + /// + /// Currently, it's intended for telemetry purposes only. + /// + public static string GetDisplayName(this Agent agent) => !string.IsNullOrWhiteSpace(agent.Name) ? agent.Name! : "UnnamedAgent"; }