Skip to content

Add DebuggerDisplay attributes to Protocol types#1068

Merged
stephentoub merged 9 commits intomainfrom
copilot/add-debuggerdisplay-and-tostring
Dec 5, 2025
Merged

Add DebuggerDisplay attributes to Protocol types#1068
stephentoub merged 9 commits intomainfrom
copilot/add-debuggerdisplay-and-tostring

Conversation

Copy link
Contributor

Copilot AI commented Dec 5, 2025

Plan: Add DebuggerDisplay Attributes to Protocol Types

  • Add [DebuggerDisplay] to ContentBlock base class and derived types:
    • TextContentBlock - display text content preview (with null safety)
    • ImageContentBlock - display mime type and proper decoded byte length
    • AudioContentBlock - display mime type and proper decoded byte length
    • EmbeddedResourceBlock - display resource URI in quotes
    • ResourceLinkBlock - display URI and name with URI in quotes
    • ToolUseContentBlock - display tool name and ID (using string literal)
    • ToolResultContentBlock - dynamic display: show result content or error
  • Add [DebuggerDisplay] to ResourceContents base class and derived types:
    • TextResourceContents - display URI and text (with proper quotes and null safety)
    • BlobResourceContents - display URI, mime type, and proper decoded byte length
  • Add [DebuggerDisplay] to other commonly used Protocol types:
    • Tool - display name and description
    • Prompt - display name and description
    • Resource - display name and URI (using string literal)
    • PromptMessage - display role and text content when available
    • SamplingMessage - display role and text content when available
    • Icon - display source and mime type with source in quotes
  • Add ToString() override for TextContentBlock (represents text data, with null safety)
  • Add ToString() override for TextResourceContents (represents text data, with null safety)
  • Create DebuggerDisplayHelper internal class for shared utilities
  • Build and test changes
  • Address all PR feedback including code cleanup
  • Final code review
Original prompt

This section details on the original issue you should resolve

<issue_title>Need DebuggerDisplay or ToString on common types</issue_title>
<issue_description>ContentBlock and derived types, and ResourceContents and derived types at a minimum. Additionally, any other types that appear as part of the public surface and don't have good default debugger representations.

ToString should only be overidden if the type represents text data.

DebuggerDisplay should be added for types that can't provide a meaningful ToString overload and should give a useful representation of the type. Have a look at https://github.com/search?q=repo%3Adotnet%2Fextensions+path%3A%2F%5Esrc%5C%2FLibraries%5C%2FMicrosoft%5C.Extensions%5C.AI%5C.Abstractions%5C%2F%2F+DebuggerDisplay&type=code for inspiration.

For example https://github.com/dotnet/extensions/blob/4a49fcf893bc3e753a201c35b3c0bb4e264d1297/src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/DataContent.cs#L237

</issue_description>

<agent_instructions>Please add [DebuggerDisplay] attributes to types in the Protocol namespace that are commonly used and likely to be inspected in the debugger, e.g. the ones mentioned in the post. You can see the [DebuggerDisplay]s in Microsoft.Extensions.AI (https://github.com/dotnet/extensions) such as for TextContent, DataContent, etc. for inspiration.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI self-assigned this Dec 5, 2025
Copilot AI changed the title [WIP] Add DebuggerDisplay and ToString for common types Add DebuggerDisplay attributes to Protocol types Dec 5, 2025
Copilot AI requested a review from stephentoub December 5, 2025 20:58
@stephentoub stephentoub marked this pull request as ready for review December 5, 2025 21:00
- Show MimeType and byte length instead of base64 data for binary content
- Use string literals in DebuggerDisplay attribute where possible
- Make ToolResultContentBlock display more dynamic (show result or error)
- Show actual text content in PromptMessage when available

Co-authored-by: stephentoub <[email protected]>
Show actual text when Content contains a single TextContentBlock, similar to PromptMessage

Co-authored-by: stephentoub <[email protected]>
- Use proper base64 decoding with Base64.IsValid on NET or Convert.FromBase64String
- Add helper method GetBase64LengthDisplay for consistent base64 length display
- Use string literals in DebuggerDisplay attributes where possible
- Put URIs in quotes for better readability
- Use Text ?? "" and Uri ?? "" for null safety in ToString and DebuggerDisplay

Co-authored-by: stephentoub <[email protected]>
- Move try/catch inside #else block for Base64 validation
- Create DebuggerDisplayHelper internal class for shared base64 decoding logic
- Simplify DebuggerDisplay attribute escaping (use \" instead of \\\")
- Use DebuggerDisplayHelper in both ContentBlock types and BlobResourceContents

Co-authored-by: stephentoub <[email protected]>
Move the "invalid base64" return statement outside the #if/#else blocks to avoid duplication

Co-authored-by: stephentoub <[email protected]>
@stephentoub stephentoub enabled auto-merge (squash) December 5, 2025 23:01
@stephentoub stephentoub requested a review from halter73 December 5, 2025 23:05
@stephentoub stephentoub merged commit 1b52dda into main Dec 5, 2025
10 checks passed
@stephentoub stephentoub deleted the copilot/add-debuggerdisplay-and-tostring branch December 5, 2025 23:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Need DebuggerDisplay or ToString on common types

3 participants