ChatReasoning
The model's thinking as a collapsible block. It opens while streaming, closes shortly after, and tells how long it took.
On this page
Examples
Thinking, live and done
Opening and closing run in the browser; toggling it yourself during the stream wins over the automatic close.
The question is about streaming, so an
IAsyncEnumerable fits. I will describe appending tokens, then rendering again.
Nothing yet.
Bound with @bind-Open: .NET hears about every toggle.
Open: false
Razor
@* While Streaming the block opens by itself, its label shimmers, and when the stream ends it closes after a moment and tells how
long it took, unless you opened or closed it in between. Simulating the stream needs interactivity. *@
<div class="flex w-full max-w-xl flex-col gap-6" data-testid="chat-reasoning-example">
<KlyChatReasoning Duration="12" data-testid="chat-reasoning-done">
The question is about streaming, so an <code>IAsyncEnumerable</code> fits. I will describe appending tokens, then rendering again.
</KlyChatReasoning>
<div class="flex flex-col items-start gap-2">
<KlyButton Label="Think out loud" Size="KlySize.Sm" Variant="ButtonVariant.Outline" Color="KlyColor.Neutral" Loading="_thinking" OnClick="Think" data-testid="chat-reasoning-run" />
<KlyChatReasoning Streaming="_thinking" AutoCloseDelay="800" data-testid="chat-reasoning-live">
@_thought
</KlyChatReasoning>
</div>
<div class="flex flex-col items-start gap-2">
<KlyChatReasoning @bind-Open="_open" Duration="5" data-testid="chat-reasoning-bound">
Bound with @@bind-Open: .NET hears about every toggle.
</KlyChatReasoning>
<p class="text-sm text-(--klyroo-text-muted)" data-testid="chat-reasoning-bound-state">Open: @(_open ? "true" : "false")</p>
</div>
</div>
@code {
private bool _open;
private bool _thinking;
private string _thought = "Nothing yet.";
private async Task Think()
{
_thinking = true;
_thought = "";
await foreach (var token in ChatDemo.Tokens("First I look at what was asked and what is already on the page. Then I list two or three ways to answer, pick the simplest one and check it against the constraints: it has to work in every render mode, stay readable for screen readers and keep the text the user typed. That one holds, so I write it down.", 80))
{
_thought += token;
await InvokeAsync(StateHasChanged);
}
_thinking = false;
}
}API
KlyChatReasoning
Collapsible block that shows the thinking of a model. It opens while streaming and closes shortly after.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
AutoCloseDelay |
int |
500 |
Milliseconds after streaming ends before it closes by itself. 0 keeps it open. |
AutoOpen |
bool |
true |
Opens when streaming starts. The user's own toggle in the meantime wins over the automatic close. |
Chevron |
ChatChevron |
ChatChevron. |
Side of the chevron that shows the state: Trailing or Leading . Values: Trailing, Leading. |
Class |
string |
Classes added to the root element, merged last so they win over the theme. | |
Disabled |
bool |
false |
Prevents the user from opening or closing the block. |
Duration |
int? |
Seconds the thinking took, for the finished label. Without it the time between the start and the end of streaming is measured here (interactive rendering). | |
Open (@bind-Open) |
bool |
false |
Open state. Bind it with @bind-Open to hear about changes; unbound, nothing leaves the browser. |
Streaming |
bool |
false |
The block is still receiving its content: it shimmers and, with AutoOpen , opens. |
Text |
string |
Label while it streams. Defaults to the built-in "Thinking...". Afterwards it is the label too, unless a duration is known. | |
Ui |
ChatReasoningUi |
Per-instance class overrides of the slots of the chat reasoning, see ChatReasoningUi . They are merged after the theme and the Class parameter wins on the root slot. |
Slots
| Name | Type | Description |
|---|---|---|
Icon |
RenderFragment |
An icon before the label. |
ChildContent |
RenderFragment |
The reasoning text. Updates as it streams. |
Ui slots
Ui takes a ChatReasoningUi with one class string per slot, merged after the theme.
| Slot | Styles |
|---|---|
Root |
Classes merged into the root slot of KlyChatReasoning , after the theme and the app configuration. |
Trigger |
Classes merged into the trigger slot of KlyChatReasoning , after the theme and the app configuration. |
Leading |
Classes merged into the leading slot of KlyChatReasoning , after the theme and the app configuration. |
LeadingIcon |
Classes merged into the leadingIcon slot of KlyChatReasoning , after the theme and the app configuration. |
ChevronIcon |
Classes merged into the chevronIcon slot of KlyChatReasoning , after the theme and the app configuration. |
Label |
Classes merged into the label slot of KlyChatReasoning , after the theme and the app configuration. |
Content |
Classes merged into the content slot of KlyChatReasoning , after the theme and the app configuration. |
Body |
Classes merged into the body slot of KlyChatReasoning , after the theme and the app configuration. |