Class ChatMessages
A whole conversation: the scrolling list of messages, plus the empty, loading and budget-exhausted states that stand in for it.
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class ChatMessages : BaseVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder
Remarks
This is the container the rest of the chat display suite composes into. It owns no message rendering of its own beyond layout: a user message becomes a ChatMessageBubble with its chips, an assistant message becomes a bubble whose reasoning and tool calls are collapsed into ChatActivityTimeline runs, and a system message becomes a destructive banner rather than a bubble at all.
Three things are worth knowing before wiring one up.
Turns are resolved in one forward pass. Each assistant message is told which user message prompted it and how long the answer took. Scanning backwards from every message would make a long conversation cost O(n²) to build; carrying the last user message forward is the same answer. A durationMs reported by the backend always beats the gap derived from the two createdAt stamps.
Which message streams has two sources. streamingMessageId names one outright; with no id set, isLoading streams the last message instead. The explicit id wins, because a backend that inserts a message after the streaming one would otherwise move the spinner.
Tool rendering is a seam, not a feature. What a tool call looks like is a product decision, so
it is delegated to IChatToolRenderer the way a custom gradient picker is delegated
to ICustomColorGradientFieldPicker. Without one, tool calls are still listed in the timeline.
Setting any property rebuilds the tree, so a caller pushing a stream of tokens should re-set messages rather than mutating a ChatMessage in place.
Examples
A short conversation with a tool call.
var conversation = new ChatMessages
{
messages = new[]
{
new ChatMessage { id = "u1", role = ChatRole.User, content = "Make the player jump higher" },
new ChatMessage
{
id = "a1",
role = ChatRole.Assistant,
durationMs = 5200,
parts = new[]
{
ChatMessagePart.Thinking("The jump force lives on the controller."),
ChatMessagePart.ToolCall("t1", "read_file", "Read PlayerController.cs"),
ChatMessagePart.ToolResult("t1", "read_file", "…"),
ChatMessagePart.Text("I raised the jump force to 8."),
},
},
},
};
conversation.retryRequested += message => Resend(message);
parentElement.Add(conversation);
In UXML. Messages are supplied from C#, the copy and flags are attributes.
<appui:ChatMessages empty-title="How can I help you?" merge-thinking="true" />
Constructors
ChatMessages()
Default constructor.
Declaration
public ChatMessages()
Fields
bannerIconUssClassName
The styling class of a banner's warning glyph.
Declaration
public const string bannerIconUssClassName = "appui-chat-messages__banner-icon"
Field Value
| Type | Description |
|---|---|
| string |
bannerLabelUssClassName
The styling class of a banner's text.
Declaration
public const string bannerLabelUssClassName = "appui-chat-messages__banner-label"
Field Value
| Type | Description |
|---|---|
| string |
bannerUssClassName
The styling class of a destructive banner: a system message, or the budget notice.
Declaration
public const string bannerUssClassName = "appui-chat-messages__banner"
Field Value
| Type | Description |
|---|---|
| string |
chipUssClassName
The styling class of a chip in a user message's sent-with row.
Declaration
public const string chipUssClassName = "appui-chat-messages__chip"
Field Value
| Type | Description |
|---|---|
| string |
defaultBudgetBanner
The notice appended under a conversation whose budget is gone.
Declaration
public const string defaultBudgetBanner = "Budget exhausted. You can no longer send messages."
Field Value
| Type | Description |
|---|---|
| string |
defaultEmptyTitle
The title shown over an empty conversation.
Declaration
public const string defaultEmptyTitle = "How can I help you?"
Field Value
| Type | Description |
|---|---|
| string |
defaultExhaustedDescription
The description shown under defaultExhaustedTitle.
Declaration
public const string defaultExhaustedDescription = "You have used all your available points. Start a new chat or contact your administrator to increase your budget."
Field Value
| Type | Description |
|---|---|
| string |
defaultExhaustedTitle
The title shown when the budget is gone and there is nothing to show.
Declaration
public const string defaultExhaustedTitle = "Budget exhausted"
Field Value
| Type | Description |
|---|---|
| string |
defaultLoadingLabel
The label shown next to the conversation-loading spinner.
Declaration
public const string defaultLoadingLabel = "Loading conversation…"
Field Value
| Type | Description |
|---|---|
| string |
emptyDescriptionUssClassName
The styling class of the empty-state description.
Declaration
public const string emptyDescriptionUssClassName = "appui-chat-messages__empty-description"
Field Value
| Type | Description |
|---|---|
| string |
emptyIconUssClassName
The styling class of the warning glyph fronting the budget-exhausted empty state.
Declaration
public const string emptyIconUssClassName = "appui-chat-messages__empty-icon"
Field Value
| Type | Description |
|---|---|
| string |
emptyTitleUssClassName
The styling class of the empty-state title.
Declaration
public const string emptyTitleUssClassName = "appui-chat-messages__empty-title"
Field Value
| Type | Description |
|---|---|
| string |
emptyUssClassName
The styling class of the empty-state block.
Declaration
public const string emptyUssClassName = "appui-chat-messages__empty"
Field Value
| Type | Description |
|---|---|
| string |
emptyVariantUssClassName
The styling class toggled while the conversation is empty.
Declaration
public const string emptyVariantUssClassName = "appui-chat-messages--empty"
Field Value
| Type | Description |
|---|---|
| string |
listUssClassName
The styling class of the centred column the messages live in.
Declaration
public const string listUssClassName = "appui-chat-messages__list"
Field Value
| Type | Description |
|---|---|
| string |
loadingLabelUssClassName
The styling class of the conversation-loading label.
Declaration
public const string loadingLabelUssClassName = "appui-chat-messages__loading-label"
Field Value
| Type | Description |
|---|---|
| string |
loadingSpinnerUssClassName
The styling class of the conversation-loading spinner.
Declaration
public const string loadingSpinnerUssClassName = "appui-chat-messages__loading-spinner"
Field Value
| Type | Description |
|---|---|
| string |
loadingUssClassName
The styling class of the conversation-loading block.
Declaration
public const string loadingUssClassName = "appui-chat-messages__loading"
Field Value
| Type | Description |
|---|---|
| string |
loadingVariantUssClassName
The styling class toggled while the conversation is still loading.
Declaration
public const string loadingVariantUssClassName = "appui-chat-messages--loading"
Field Value
| Type | Description |
|---|---|
| string |
metaUssClassName
The styling class of the meta line above an assistant message's action row.
Declaration
public const string metaUssClassName = "appui-chat-messages__meta"
Field Value
| Type | Description |
|---|---|
| string |
scrollUssClassName
The styling class of the scrolling area.
Declaration
public const string scrollUssClassName = "appui-chat-messages__scroll"
Field Value
| Type | Description |
|---|---|
| string |
textUssClassName
The styling class of an answer text block.
Declaration
public const string textUssClassName = "appui-chat-messages__text"
Field Value
| Type | Description |
|---|---|
| string |
toolContentUssClassName
The styling class of content produced by an IChatToolRenderer.
Declaration
public const string toolContentUssClassName = "appui-chat-messages__tool-content"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The ChatMessages main styling class.
Declaration
public const string ussClassName = "appui-chat-messages"
Field Value
| Type | Description |
|---|---|
| string |
Properties
activityFoldRowsByKind
Folds the rows of every default activity group by kind; see foldRowsByKind.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool activityFoldRowsByKind { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
activityHeaderPlacement
Where every default activity group draws its header; see headerPlacement. A live group with its header at the foot is the turn's status line, so it carries streamingStats and the streaming indicator stands down. A group built by renderActivity is never that line.
Declaration
[CreateProperty]
[UxmlAttribute]
public ChatActivityHeaderPlacement activityHeaderPlacement { get; set; }
Property Value
| Type | Description |
|---|---|
| ChatActivityHeaderPlacement |
activityMaxPinnedShare
The share of the scroll area every default activity group's pinned entries may take; see maxPinnedShare. Clamped to 0..1.
Declaration
[CreateProperty]
[UxmlAttribute]
public float activityMaxPinnedShare { get; set; }
Property Value
| Type | Description |
|---|---|
| float |
activityOpen
Whether the activity group of the turn in progress shows its detail. False by default.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool activityOpen { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
Only the live group follows it: the last group of the streaming message, before any text follows it. A finished group is a record the reader opens to look something up, so it answers to its own header. The list rebuilds as a turn streams, so the reader's own toggle of the live group is written back here, and carries over from one turn to the next.
activityPinEntries
Lays every default activity group out as pinned entries; see pinEntries.
Declaration
[CreateProperty]
[UxmlAttribute]
public ChatActivityPinEntries activityPinEntries { get; set; }
Property Value
| Type | Description |
|---|---|
| ChatActivityPinEntries |
budgetBanner
The notice appended under a populated conversation whose budget is gone.
Declaration
[CreateProperty]
[UxmlAttribute]
public string budgetBanner { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
budgetExhausted
Whether the reader has run out of budget. Changes the empty state's copy, and appends a notice under a populated conversation.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool budgetExhausted { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
contentContainer
Children are managed internally — this element exposes no content container.
Declaration
public override VisualElement contentContainer { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
Overrides
emptyDescription
The optional description under emptyTitle.
Declaration
[CreateProperty]
[UxmlAttribute]
public string emptyDescription { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
emptyTitle
The title shown over an empty conversation.
Declaration
[CreateProperty]
[UxmlAttribute]
public string emptyTitle { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
exhaustedDescription
The description shown under exhaustedTitle.
Declaration
[CreateProperty]
[UxmlAttribute]
public string exhaustedDescription { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
exhaustedTitle
The title replacing emptyTitle when the budget is gone.
Declaration
[CreateProperty]
[UxmlAttribute]
public string exhaustedTitle { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
isLoading
Whether the agent is answering. With no streamingMessageId set, this streams the last message in the conversation.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool isLoading { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
isLoadingConversation
Whether the conversation itself is still being fetched. This wins over every other state: nothing else is rendered while it is true.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool isLoadingConversation { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
loadingLabel
The label shown next to the conversation-loading spinner.
Declaration
[CreateProperty]
[UxmlAttribute]
public string loadingLabel { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
mergeThinking
Whether consecutive thinking parts collapse into one timeline row. True by default; set it false to give each thought its own row.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool mergeThinking { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
messageCount
How many messages are rendered.
Declaration
public int messageCount { get; }
Property Value
| Type | Description |
|---|---|
| int |
messages
The conversation. Setting this replaces what is rendered; it never appends.
Declaration
public IEnumerable<ChatMessage> messages { get; set; }
Property Value
| Type | Description |
|---|---|
| IEnumerable<ChatMessage> |
renderActions
Replaces the default per-message action row. Called for user and assistant messages alike.
Declaration
public Func<ChatMessageActionsContext, VisualElement> renderActions { get; set; }
Property Value
| Type | Description |
|---|---|
| Func<ChatMessageActionsContext, VisualElement> |
renderActivity
Replaces the default ChatActivityTimeline: every activity group of an assistant message is built by this instead, in the timeline's place. Returning null renders nothing for that group. For a host that shows the work in its own structure.
Declaration
public Func<ChatActivityRenderContext, VisualElement> renderActivity { get; set; }
Property Value
| Type | Description |
|---|---|
| Func<ChatActivityRenderContext, VisualElement> |
Remarks
toolRenderer content still follows the group, as it follows the default timeline. A host-built group carries no live figures, so the streaming indicator stays.
renderLoadingConversation
Replaces the default spinner shown while the conversation loads.
Declaration
public Func<VisualElement> renderLoadingConversation { get; set; }
Property Value
| Type | Description |
|---|---|
| Func<VisualElement> |
renderMessageMeta
Builds the always-visible meta line above an assistant message's action row, for instance the elapsed-to-answer figure. Returning null adds nothing.
Declaration
public Func<ChatMessageMetaContext, VisualElement> renderMessageMeta { get; set; }
Property Value
| Type | Description |
|---|---|
| Func<ChatMessageMetaContext, VisualElement> |
renderStandalonePart
Builds the block for a part standalonePart picked. Returning null renders nothing, and the part stays out of the activity group regardless.
Declaration
public Func<ChatStandalonePartContext, VisualElement> renderStandalonePart { get; set; }
Property Value
| Type | Description |
|---|---|
| Func<ChatStandalonePartContext, VisualElement> |
renderSystemMessage
Replaces the default destructive banner used for a System message.
Declaration
public Func<ChatMessage, VisualElement> renderSystemMessage { get; set; }
Property Value
| Type | Description |
|---|---|
| Func<ChatMessage, VisualElement> |
scrollView
The scrolling area holding the conversation. Exposed so a caller can drive it to the bottom as new messages arrive.
Declaration
public ScrollView scrollView { get; }
Property Value
| Type | Description |
|---|---|
| ScrollView |
showCompletedIndicator
Whether the last message reports how long it took once it has finished. True by default. A message with no measured durationMs reports nothing either way.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool showCompletedIndicator { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
showStreamingIndicator
Whether a streaming message shows the streaming indicator under its content. True by default. Turn it off when the host reports a turn's progress somewhere else, so the list does not say it twice. The completed indicator is unaffected.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool showStreamingIndicator { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
standalonePart
Picks the parts rendered as their own block instead of being folded into an activity group.
Declaration
public Func<ChatMessagePart, bool> standalonePart { get; set; }
Property Value
| Type | Description |
|---|---|
| Func<ChatMessagePart, bool> |
Remarks
For a part the host would rather present itself -- a generated image, a diff, a preview -- where the one-line activity row undersells it. A part picked here is excluded from the activity group either way, so the two can never show it twice.
Never consulted for a tool result: results are folded onto their call, so pulling one out on its own would orphan it. Inert without renderStandalonePart.
streamingMessageId
The id of the message currently streaming. When set it decides on its own which message streams, and the isLoading heuristic is not consulted.
Declaration
[CreateProperty]
[UxmlAttribute]
public string streamingMessageId { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
streamingStats
Figures shown next to the streaming indicator, for instance a token count. Only the streaming message displays them.
Declaration
[CreateProperty]
[UxmlAttribute]
public string streamingStats { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
toolRenderer
The application's own tool rendering. See IChatToolRenderer.
Declaration
public IChatToolRenderer toolRenderer { get; set; }
Property Value
| Type | Description |
|---|---|
| IChatToolRenderer |
Events
activityOpenChanged
Raised when the reader toggles the activity group of the turn in progress, with the state they asked for. activityOpen already holds it when this fires.
Declaration
public event Action<bool> activityOpenChanged
Event Type
| Type | Description |
|---|---|
| Action<bool> |
retryRequested
Raised when the reader asks for a message to be sent again.
Declaration
public event Action<ChatMessage> retryRequested
Event Type
| Type | Description |
|---|---|
| Action<ChatMessage> |