@@ -97,8 +97,9 @@ conversationHistory[lastMessageIndex] is ChatMessage lastMessage &&
9797 /// <remarks>
9898 /// <para>
9999 /// This function only considers the <see cref="ChatMessage.Text"/> and ignores any <see cref="AIContent"/>s
100- /// present within the <see cref="ChatMessage.Contents"/> of the <paramref name="message"/> that are not
101- /// <see cref="TextContent"/>s.
100+ /// (present within the <see cref="ChatMessage.Contents"/> of the <paramref name="message"/>) that are not
101+ /// <see cref="TextContent"/>s. If the <paramref name="message"/> does not contain any <see cref="TextContent"/>s
102+ /// then this function returns an empty string.
102103 /// </para>
103104 /// <para>
104105 /// The returned string is prefixed with the <see cref="ChatMessage.Role"/> and
@@ -112,6 +113,12 @@ public static string RenderText(this ChatMessage message)
112113 {
113114 _ = Throw . IfNull ( message ) ;
114115
116+ if ( ! message . Contents . OfType < TextContent > ( ) . Any ( ) )
117+ {
118+ // Don't render messages (such as messages with role ChatRole.Tool) that don't contain any textual content.
119+ return string . Empty ;
120+ }
121+
115122 string ? author = message . AuthorName ;
116123 string role = message . Role . Value ;
117124 string ? content = message . Text ;
@@ -129,8 +136,10 @@ public static string RenderText(this ChatMessage message)
129136 /// <remarks>
130137 /// <para>
131138 /// This function only considers the <see cref="ChatMessage.Text"/> and ignores any <see cref="AIContent"/>s
132- /// present within the <see cref="ChatMessage.Contents"/> of the <paramref name="messages"/> that are not
133- /// <see cref="TextContent"/>s.
139+ /// (present within the <see cref="ChatMessage.Contents"/> of the <paramref name="messages"/>) that are not
140+ /// <see cref="TextContent"/>s. Any <paramref name="messages"/> that contain no <see cref="TextContent"/>s will be
141+ /// skipped and will not be rendered. If none of the <paramref name="messages"/> include any
142+ /// <see cref="TextContent"/>s then this function will return an empty string.
134143 /// </para>
135144 /// <para>
136145 /// The rendered <paramref name="messages"/> are each prefixed with the <see cref="ChatMessage.Role"/> and
0 commit comments