Skip to content
Chat ChatTool

ChatTool

A tool call of the assistant: its name, whether it runs or failed, and optionally its input and output in a collapsible part.

On this page

Examples

States and approval

Running, failed and done calls, and a card with allow and deny actions.

Reading a filenotes.txt(running)

Waiting for your answer

Razor
@* The default content makes the block collapsible. Actions sit under the name, outside the collapsible part. *@
<div class="flex w-full max-w-xl flex-col gap-4" data-testid="chat-tool-example">
    <KlyChatTool Text="Searched the documentation" Suffix='"chat prompt"' Icon="@KlyIcons.Named("search", "size-4")" data-testid="chat-tool-done">
        <p>Input: {"query": "chat prompt"}</p>
        <p>Output: 3 results</p>
    </KlyChatTool>
    <KlyChatTool Text="Reading a file" Suffix="notes.txt" Loading Streaming data-testid="chat-tool-running" />
    <KlyChatTool Text="Calling the weather API" Error Variant="ChatToolVariant.Card" data-testid="chat-tool-failed">
        <p>Error: the service did not answer in time.</p>
    </KlyChatTool>
    <KlyChatTool Text="Delete the draft" Suffix="draft.md" Variant="ChatToolVariant.Card" Icon="@KlyIcons.Named("trash", "size-4")" data-testid="chat-tool-approval">
        <Actions>
            <KlyButton Label="Allow" Size="KlySize.Xs" OnClick="Allow" data-testid="chat-tool-allow" />
            <KlyButton Label="Deny" Size="KlySize.Xs" Variant="ButtonVariant.Outline" Color="KlyColor.Neutral" OnClick="Deny" data-testid="chat-tool-deny" />
        </Actions>
        <ChildContent><p>Arguments: {"path": "draft.md"}</p></ChildContent>
    </KlyChatTool>
    <p class="text-sm text-(--klyroo-text-muted)" role="status" data-testid="chat-tool-answer">@(_answer ?? "Waiting for your answer")</p>
</div>

@code {
    private string? _answer;

    private void Allow() => _answer = "Allowed";

    private void Deny() => _answer = "Denied";
}

API

KlyChatTool

Tool call of an assistant: its name, running or failed state and, optionally, its input and output in a collapsible area.

Parameters

Name Type Default Description
Chevron ChatChevron ChatChevron.Trailing 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 details.
Error bool false The call failed: error colors, and "failed" is read out after the name.
Loading bool false The call is running: a spinner replaces the icon.
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 name shimmers, as the arguments or the output still stream in.
Suffix string Quieter text after the name: the query, the file.
Text string The name of the tool call: "Searching the web".
Ui ChatToolUi Per-instance class overrides of the slots of the chat tool, see ChatToolUi . They are merged after the theme and the Class parameter wins on the root slot.
Variant ChatToolVariant ChatToolVariant.Inline Look of the tool call: Inline or Card . Values: Inline, Card.

Slots

Name Type Description
Actions RenderFragment Below the name, outside the collapsible part: approve and deny buttons.
Icon RenderFragment An icon before the name, replaced by a spinner while loading and by an alert on error.
ChildContent RenderFragment What the tool was given and returned. Setting it makes the block collapsible.

Ui slots

Ui takes a ChatToolUi with one class string per slot, merged after the theme.

Slot Styles
Root Classes merged into the root slot of KlyChatTool , after the theme and the app configuration.
Trigger Classes merged into the trigger slot of KlyChatTool , after the theme and the app configuration.
Leading Classes merged into the leading slot of KlyChatTool , after the theme and the app configuration.
LeadingIcon Classes merged into the leadingIcon slot of KlyChatTool , after the theme and the app configuration.
ChevronIcon Classes merged into the chevronIcon slot of KlyChatTool , after the theme and the app configuration.
Label Classes merged into the label slot of KlyChatTool , after the theme and the app configuration.
Suffix Classes merged into the suffix slot of KlyChatTool , after the theme and the app configuration.
Content Classes merged into the content slot of KlyChatTool , after the theme and the app configuration.
Body Classes merged into the body slot of KlyChatTool , after the theme and the app configuration.
Actions Classes merged into the actions slot of KlyChatTool , after the theme and the app configuration.