Add some DebuggerDisplays / DebuggerTypeProxys to abstraction types (#1144)

This commit is contained in:
Stephen Toub
2025-10-03 04:51:49 -04:00
committed by GitHub
Unverified
parent c543dbaa92
commit 4daeeb0f07
7 changed files with 32 additions and 0 deletions
@@ -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.
/// </remarks>
[DebuggerDisplay("{DisplayName,nq}")]
public abstract class AIAgent
{
/// <summary>Default ID of this agent instance.</summary>
@@ -1,5 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.
using System.Diagnostics;
namespace Microsoft.Agents.AI;
/// <summary>
@@ -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.
/// </remarks>
[DebuggerDisplay("ProviderName = {ProviderName}")]
public class AIAgentMetadata
{
/// <summary>
@@ -1,10 +1,13 @@
// Copyright (c) Microsoft. All rights reserved.
using System.Diagnostics;
namespace Microsoft.Agents.AI;
/// <summary>
/// Provides metadata information about an <see cref="AgentThread"/> instance.
/// </summary>
[DebuggerDisplay("ConversationId = {ConversationId}")]
public class AgentThreadMetadata
{
/// <summary>
@@ -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.
/// </para>
/// </remarks>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public abstract class InMemoryAgentThread : AgentThread
{
/// <summary>
@@ -118,6 +120,9 @@ public abstract class InMemoryAgentThread : AgentThread
protected internal override Task MessagesReceivedAsync(IEnumerable<ChatMessage> 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; }
@@ -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.
/// </para>
/// </remarks>
[DebuggerDisplay("Count = {Count}")]
[DebuggerTypeProxy(typeof(DebugView))]
public sealed class InMemoryChatMessageStore : ChatMessageStore, IList<ChatMessage>
{
private List<ChatMessage> _messages;
@@ -226,4 +229,10 @@ public sealed class InMemoryChatMessageStore : ChatMessageStore, IList<ChatMessa
/// </summary>
BeforeMessagesRetrieval
}
private sealed class DebugView(InMemoryChatMessageStore store)
{
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
public ChatMessage[] Items => store._messages.ToArray();
}
}
@@ -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.
/// </remarks>
[DebuggerDisplay("ServiceThreadId = {ServiceThreadId}")]
public abstract class ServiceIdAgentThread : AgentThread
{
/// <summary>
@@ -14,6 +14,7 @@ namespace Microsoft.Agents.AI;
/// <summary>
/// Provides a thread implementation for use with <see cref="ChatClientAgent"/>.
/// </summary>
[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; }