Skip to content
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

.Net: Updated agent logs to include agent name #10330

Merged
merged 4 commits into from
Jan 29, 2025
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions dotnet/src/Agents/Abstractions/AgentChat.cs
Original file line number Diff line number Diff line change
@@ -213,7 +213,7 @@ protected async IAsyncEnumerable<ChatMessageContent> 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<ChatMessageContent> 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<ChatMessageContent> 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<StreamingChatMessageContent> 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<StreamingChatMessageContent> 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<StreamingChatMessageContent> 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<AgentChannel> 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<AgentChannel> 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;
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
<ItemGroup>
<Compile Include="$(RepoRoot)/dotnet/src/InternalUtilities/src/Diagnostics/*" Link="%(RecursiveDir)Utilities/%(Filename)%(Extension)" />
<Compile Include="$(RepoRoot)/dotnet/src/InternalUtilities/src/System/AppContextSwitchHelper.cs" Link="%(RecursiveDir)Utilities/%(Filename)%(Extension)" />
<Compile Include="$(RepoRoot)/dotnet/src/InternalUtilities/agents/Extensions/AgentExtensions.cs" Link="%(RecursiveDir)Utilities/%(Filename)%(Extension)" />
</ItemGroup>

<ItemGroup>
46 changes: 27 additions & 19 deletions dotnet/src/Agents/Abstractions/Logging/AgentChatLogMessages.cs
Original file line number Diff line number Diff line change
@@ -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,25 +22,26 @@ internal static partial class AgentChatLogMessages
/// <summary>
/// Logs retrieval of <see cref="AgentChat"/> messages.
/// </summary>
private static readonly Action<ILogger, string, string, string, Exception?> s_logAgentChatGetChatMessages =
LoggerMessage.Define<string, string, string>(
private static readonly Action<ILogger, string, string, string, string?, Exception?> s_logAgentChatGetChatMessages =
LoggerMessage.Define<string, string, string, string?>(
logLevel: LogLevel.Debug,
eventId: 0,
"[{MethodName}] Source: {MessageSourceType}/{MessageSourceId}.");
"[{MethodName}] Source: {MessageSourceType}/{MessageSourceId}/{MessageSourceName}.");

public static void LogAgentChatGetChatMessages(
this ILogger logger,
string methodName,
Agent? agent)
{
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,48 +76,51 @@ 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);

/// <summary>
/// Logs <see cref="AgentChat"/> invoked agent message
/// </summary>
[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);

/// <summary>
/// Logs retrieval of streamed <see cref="AgentChat"/> messages.
/// </summary>
private static readonly Action<ILogger, string, Type, string, ChatMessageContent, Exception?> s_logAgentChatInvokedStreamingAgentMessages =
LoggerMessage.Define<string, Type, string, ChatMessageContent>(
private static readonly Action<ILogger, string, Type, string, string, ChatMessageContent, Exception?> s_logAgentChatInvokedStreamingAgentMessages =
LoggerMessage.Define<string, Type, string, string, ChatMessageContent>(
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<ChatMessageContent> 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,36 +131,39 @@ 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);

/// <summary>
/// Logs <see cref="AgentChat"/> creating agent channel (started).
/// </summary>
[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);

/// <summary>
/// Logs <see cref="AgentChat"/> created agent channel (complete).
/// </summary>
[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);
}
7 changes: 4 additions & 3 deletions dotnet/src/Agents/Core/AgentGroupChat.cs
Original file line number Diff line number Diff line change
@@ -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<ChatMessageContent> 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<StreamingChatMessageContent> 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<Agent> 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;
}
1 change: 1 addition & 0 deletions dotnet/src/Agents/Core/Agents.Core.csproj
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@
<Compile Include="$(RepoRoot)/dotnet/src/InternalUtilities/src/Diagnostics/*" Link="%(RecursiveDir)Utilities/%(Filename)%(Extension)" />
<Compile Include="$(RepoRoot)/dotnet/src/InternalUtilities/src/System/TypeConverterFactory.cs" Link="%(RecursiveDir)Utilities/%(Filename)%(Extension)" />
<Compile Include="$(RepoRoot)/dotnet/src/InternalUtilities/src/System/AppContextSwitchHelper.cs" Link="%(RecursiveDir)Utilities/%(Filename)%(Extension)" />
<Compile Include="$(RepoRoot)/dotnet/src/InternalUtilities/agents/Extensions/AgentExtensions.cs" Link="%(RecursiveDir)Utilities/%(Filename)%(Extension)" />
</ItemGroup>

<ItemGroup>
Original file line number Diff line number Diff line change
@@ -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<Agent> SelectAgentAsync(IReadOnlyList<Agent> 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);

7 changes: 4 additions & 3 deletions dotnet/src/Agents/Core/Chat/TerminationStrategy.cs
Original file line number Diff line number Diff line change
@@ -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
/// <returns>True to terminate chat loop.</returns>
public async Task<bool> ShouldTerminateAsync(Agent agent, IReadOnlyList<ChatMessageContent> 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;
}
9 changes: 5 additions & 4 deletions dotnet/src/Agents/Core/ChatCompletionAgent.cs
Original file line number Diff line number Diff line change
@@ -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<ChatMessageContent> 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<ChatMessageContent> 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<StreamingChatMessageContent> 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<StreamingChatMessageContent> messages =
chatCompletionService.GetStreamingChatMessageContentsAsync(
@@ -113,7 +114,7 @@ public override async IAsyncEnumerable<StreamingChatMessageContent> 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();
14 changes: 10 additions & 4 deletions dotnet/src/Agents/Core/Logging/AgentGroupChatLogMessages.cs
Original file line number Diff line number Diff line change
@@ -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);

/// <summary>
/// Logs <see cref="AgentGroupChat"/> invoking agents (started).
@@ -40,14 +42,17 @@ public static partial void LogAgentGroupChatInvokingAgent(
logLevel: LogLevel.Debug,
eventId: 0,
"[{MethodName}] Invoking chat: {Agents}");

public static void LogAgentGroupChatInvokingAgents(
this ILogger logger,
string methodName,
IEnumerable<Agent> agents)
{
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);

/// <summary>
Original file line number Diff line number Diff line change
@@ -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);

/// <summary>
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -23,37 +23,40 @@ 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);

/// <summary>
/// Logs <see cref="TerminationStrategy"/> agent out of scope.
/// </summary>
[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);

/// <summary>
/// Logs <see cref="TerminationStrategy"/> evaluated criteria (complete).
/// </summary>
[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);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
// Copyright (c) Microsoft. All rights reserved.

using System.Diagnostics.CodeAnalysis;

namespace Microsoft.SemanticKernel.Agents.Extensions;

/// <summary>
/// Extension methods for <see cref="Agent"/>.
/// </summary>
[ExcludeFromCodeCoverage]
internal static class AgentExtensions
{
/// <summary>
@@ -12,8 +16,14 @@ internal static class AgentExtensions
/// </summary>
/// <param name="agent">The target agent</param>
/// <returns>The agent name as a non-empty string</returns>
public static string GetName(this Agent agent)
{
return agent.Name ?? agent.Id;
}
public static string GetName(this Agent agent) => agent.Name ?? agent.Id;

/// <summary>
/// Provides the display name of the agent.
/// </summary>
/// <param name="agent">The target agent</param>
/// <remarks>
/// Currently, it's intended for telemetry purposes only.
/// </remarks>
public static string GetDisplayName(this Agent agent) => agent.Name ?? "UnnamedAgent";
}