From 4daeeb0f0780a4a73276260b997bde1440bd3f2d Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Fri, 3 Oct 2025 04:51:49 -0400 Subject: [PATCH] Add some DebuggerDisplays / DebuggerTypeProxys to abstraction types (#1144) --- dotnet/src/Microsoft.Agents.AI.Abstractions/AIAgent.cs | 2 ++ .../Microsoft.Agents.AI.Abstractions/AIAgentMetadata.cs | 3 +++ .../AgentThreadMetadata.cs | 3 +++ .../InMemoryAgentThread.cs | 5 +++++ .../InMemoryChatMessageStore.cs | 9 +++++++++ .../ServiceIdAgentThread.cs | 2 ++ .../ChatClient/ChatClientAgentThread.cs | 8 ++++++++ 7 files changed, 32 insertions(+) diff --git a/dotnet/src/Microsoft.Agents.AI.Abstractions/AIAgent.cs b/dotnet/src/Microsoft.Agents.AI.Abstractions/AIAgent.cs index e80c5c8fc3..35aa866552 100644 --- a/dotnet/src/Microsoft.Agents.AI.Abstractions/AIAgent.cs +++ b/dotnet/src/Microsoft.Agents.AI.Abstractions/AIAgent.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Text.Json; using System.Threading; using System.Threading.Tasks; @@ -18,6 +19,7 @@ namespace Microsoft.Agents.AI; /// and process user requests. An agent instance may participate in multiple concurrent conversations, and each conversation /// may involve multiple agents working together. /// +[DebuggerDisplay("{DisplayName,nq}")] public abstract class AIAgent { /// Default ID of this agent instance. diff --git a/dotnet/src/Microsoft.Agents.AI.Abstractions/AIAgentMetadata.cs b/dotnet/src/Microsoft.Agents.AI.Abstractions/AIAgentMetadata.cs index f5f7d34c1c..6fe73c80cd 100644 --- a/dotnet/src/Microsoft.Agents.AI.Abstractions/AIAgentMetadata.cs +++ b/dotnet/src/Microsoft.Agents.AI.Abstractions/AIAgentMetadata.cs @@ -1,5 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. +using System.Diagnostics; + namespace Microsoft.Agents.AI; /// @@ -9,6 +11,7 @@ namespace Microsoft.Agents.AI; /// This class contains descriptive information about an agent that can be used for identification, /// telemetry, and logging purposes. /// +[DebuggerDisplay("ProviderName = {ProviderName}")] public class AIAgentMetadata { /// diff --git a/dotnet/src/Microsoft.Agents.AI.Abstractions/AgentThreadMetadata.cs b/dotnet/src/Microsoft.Agents.AI.Abstractions/AgentThreadMetadata.cs index e925c590fc..3a2d506745 100644 --- a/dotnet/src/Microsoft.Agents.AI.Abstractions/AgentThreadMetadata.cs +++ b/dotnet/src/Microsoft.Agents.AI.Abstractions/AgentThreadMetadata.cs @@ -1,10 +1,13 @@ // Copyright (c) Microsoft. All rights reserved. +using System.Diagnostics; + namespace Microsoft.Agents.AI; /// /// Provides metadata information about an instance. /// +[DebuggerDisplay("ConversationId = {ConversationId}")] public class AgentThreadMetadata { /// diff --git a/dotnet/src/Microsoft.Agents.AI.Abstractions/InMemoryAgentThread.cs b/dotnet/src/Microsoft.Agents.AI.Abstractions/InMemoryAgentThread.cs index 096ad17c30..af6080a715 100644 --- a/dotnet/src/Microsoft.Agents.AI.Abstractions/InMemoryAgentThread.cs +++ b/dotnet/src/Microsoft.Agents.AI.Abstractions/InMemoryAgentThread.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Text.Json; using System.Threading; using System.Threading.Tasks; @@ -23,6 +24,7 @@ namespace Microsoft.Agents.AI; /// unless explicitly serialized and restored. /// /// +[DebuggerDisplay("{DebuggerDisplay,nq}")] public abstract class InMemoryAgentThread : AgentThread { /// @@ -118,6 +120,9 @@ public abstract class InMemoryAgentThread : AgentThread protected internal override Task MessagesReceivedAsync(IEnumerable newMessages, CancellationToken cancellationToken = default) => this.MessageStore.AddMessagesAsync(newMessages, cancellationToken); + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private string DebuggerDisplay => $"Count = {this.MessageStore.Count}"; + internal sealed class InMemoryAgentThreadState { public JsonElement? StoreState { get; set; } diff --git a/dotnet/src/Microsoft.Agents.AI.Abstractions/InMemoryChatMessageStore.cs b/dotnet/src/Microsoft.Agents.AI.Abstractions/InMemoryChatMessageStore.cs index b14573ada1..17d1cdce93 100644 --- a/dotnet/src/Microsoft.Agents.AI.Abstractions/InMemoryChatMessageStore.cs +++ b/dotnet/src/Microsoft.Agents.AI.Abstractions/InMemoryChatMessageStore.cs @@ -3,6 +3,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text.Json; using System.Threading; @@ -26,6 +27,8 @@ namespace Microsoft.Agents.AI; /// message reduction strategies or alternative storage implementations. /// /// +[DebuggerDisplay("Count = {Count}")] +[DebuggerTypeProxy(typeof(DebugView))] public sealed class InMemoryChatMessageStore : ChatMessageStore, IList { private List _messages; @@ -226,4 +229,10 @@ public sealed class InMemoryChatMessageStore : ChatMessageStore, IList BeforeMessagesRetrieval } + + private sealed class DebugView(InMemoryChatMessageStore store) + { + [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)] + public ChatMessage[] Items => store._messages.ToArray(); + } } diff --git a/dotnet/src/Microsoft.Agents.AI.Abstractions/ServiceIdAgentThread.cs b/dotnet/src/Microsoft.Agents.AI.Abstractions/ServiceIdAgentThread.cs index 030d9eb600..22f9f98a83 100644 --- a/dotnet/src/Microsoft.Agents.AI.Abstractions/ServiceIdAgentThread.cs +++ b/dotnet/src/Microsoft.Agents.AI.Abstractions/ServiceIdAgentThread.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. using System; +using System.Diagnostics; using System.Text.Json; using Microsoft.Shared.Diagnostics; @@ -13,6 +14,7 @@ namespace Microsoft.Agents.AI; /// This class is designed for scenarios where conversation state is managed by an external service (such as a cloud-based AI service) /// rather than being stored locally. The thread maintains only the service identifier needed to reference the remote conversation state. /// +[DebuggerDisplay("ServiceThreadId = {ServiceThreadId}")] public abstract class ServiceIdAgentThread : AgentThread { /// diff --git a/dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgentThread.cs b/dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgentThread.cs index 676e20dc53..4c93fe4295 100644 --- a/dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgentThread.cs +++ b/dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgentThread.cs @@ -14,6 +14,7 @@ namespace Microsoft.Agents.AI; /// /// Provides a thread implementation for use with . /// +[DebuggerDisplay("{DebuggerDisplay,nq}")] public class ChatClientAgentThread : AgentThread { private string? _conversationId; @@ -207,6 +208,13 @@ public class ChatClientAgentThread : AgentThread } } + [DebuggerBrowsable(DebuggerBrowsableState.Never)] + private string DebuggerDisplay => + this._conversationId is { } conversationId ? $"ConversationId = {conversationId}" : + this._messageStore is InMemoryChatMessageStore inMemoryStore ? $"Count = {inMemoryStore.Count}" : + this._messageStore is { } store ? $"Store = {store.GetType().Name}" : + "Count = 0"; + internal sealed class ThreadState { public string? ConversationId { get; set; }