showcase/shell-docs/src/content/reference/components/CopilotChatAssistantMessage.mdx
CopilotChatAssistantMessage displays assistant messages with Markdown support, tool call rendering, and an action toolbar. The Markdown renderer uses remark-gfm, remark-math, syntax highlighting via rehype-pretty-code, and KaTeX support for mathematical expressions. The toolbar provides copy, rating (thumbs up/down), read aloud, and regenerate buttons with localized tooltips sourced from CopilotChatConfigurationProvider.
import { CopilotChatAssistantMessage } from "@copilotkit/react-core/v2";
import "@copilotkit/react-core/v2/styles.css";
<PropertyReference name="onThumbsDown" type="(message: AssistantMessage) => void"
Callback invoked when the user clicks the thumbs-down button. When not provided, the thumbs-down button is hidden from the toolbar. </PropertyReference>
<PropertyReference name="onReadAloud" type="(message: AssistantMessage) => void"
Callback invoked when the user clicks the read-aloud button. When not provided, the read-aloud button is hidden from the toolbar. </PropertyReference>
<PropertyReference name="onRegenerate" type="(message: AssistantMessage) => void"
Callback invoked when the user clicks the regenerate button. When not provided, the regenerate button is hidden from the toolbar. </PropertyReference>
<PropertyReference name="additionalToolbarItems" type="React.ReactNode"> Additional React elements appended to the toolbar alongside the default action buttons. </PropertyReference> <PropertyReference name="toolbarVisible" type="boolean"> Controls whether the action toolbar is visible. When set to `false`, the toolbar is hidden entirely regardless of which callback props are provided. </PropertyReference>All slot props follow the CopilotKit slot system: each accepts a replacement React component, a className string that is merged into the default component's classes, or a partial props object that extends the default component.
As a replacement component:
<CopilotChatAssistantMessage
message={msg}
markdownRenderer={({ content }) => (
<div dangerouslySetInnerHTML={{ __html: content }} />
)}
/>
As a className:
<CopilotChatAssistantMessage message={msg} toolbar="border-t pt-2 mt-2" />
<PropertyReference name="copyButton" type="SlotProp<typeof CopilotChatAssistantMessage.CopyButton>"
Slot for the copy-to-clipboard button in the toolbar. Defaults to
CopilotChatAssistantMessage.CopyButton. The tooltip label is sourced from
CopilotChatLabels.assistantMessageToolbarCopyMessageLabel.
</PropertyReference>
<PropertyReference name="thumbsUpButton" type="SlotProp<typeof CopilotChatAssistantMessage.ThumbsUpButton>"
Slot for the thumbs-up rating button. Defaults to
CopilotChatAssistantMessage.ThumbsUpButton. Only rendered when onThumbsUp
is provided. The tooltip label is sourced from
CopilotChatLabels.assistantMessageToolbarThumbsUpLabel.
</PropertyReference>
<PropertyReference name="thumbsDownButton" type="SlotProp<typeof CopilotChatAssistantMessage.ThumbsDownButton>"
Slot for the thumbs-down rating button. Defaults to
CopilotChatAssistantMessage.ThumbsDownButton. Only rendered when
onThumbsDown is provided. The tooltip label is sourced from
CopilotChatLabels.assistantMessageToolbarThumbsDownLabel.
</PropertyReference>
<PropertyReference name="readAloudButton" type="SlotProp<typeof CopilotChatAssistantMessage.ReadAloudButton>"
Slot for the read-aloud button. Defaults to
CopilotChatAssistantMessage.ReadAloudButton. Only rendered when
onReadAloud is provided. The tooltip label is sourced from
CopilotChatLabels.assistantMessageToolbarReadAloudLabel.
</PropertyReference>
<PropertyReference name="regenerateButton" type="SlotProp<typeof CopilotChatAssistantMessage.RegenerateButton>"
Slot for the regenerate button. Defaults to
CopilotChatAssistantMessage.RegenerateButton. Only rendered when
onRegenerate is provided. The tooltip label is sourced from
CopilotChatLabels.assistantMessageToolbarRegenerateLabel.
</PropertyReference>
<PropertyReference name="toolCallsView" type="SlotProp<typeof CopilotChatToolCallsView>"
Slot for rendering tool calls embedded in the assistant message. Defaults to
CopilotChatToolCallsView, which iterates over
the message's tool calls and renders each using the closest registered tool
renderer.
</PropertyReference>
A companion component that renders the tool calls contained in an assistant message. Given an assistant message, it iterates over each tool call and renders it using the closest registered tool renderer (registered via useFrontendTool, useHumanInTheLoop, or renderToolCalls on the provider).
function AssistantBubble({ message }) {
return (
<CopilotChatAssistantMessage
message={message}
onThumbsUp={(msg) => console.log("Thumbs up:", msg.id)}
onThumbsDown={(msg) => console.log("Thumbs down:", msg.id)}
/>
);
}
function CustomToolbarMessage({ message }) {
return (
<CopilotChatAssistantMessage
message={message}
onRegenerate={(msg) => handleRegenerate(msg)}
onReadAloud={(msg) => speak(msg.content)}
additionalToolbarItems={
<button onClick={() => shareMessage(message)}>Share</button>
}
toolbar="border-t border-gray-200 pt-2"
/>
);
}
function MinimalMessage({ message }) {
return (
<CopilotChatAssistantMessage message={message} toolbarVisible={false} />
);
}
function CustomRendererMessage({ message }) {
return (
<CopilotChatAssistantMessage
message={message}
markdownRenderer={({ content }) => (
<ReactMarkdown>{content}</ReactMarkdown>
)}
/>
);
}
function ToolCallsList({ message, allMessages }) {
return (
<div className="tool-calls">
<CopilotChatToolCallsView message={message} messages={allMessages} />
</div>
);
}
rehype-pretty-code.onThumbsUp, onThumbsDown, onReadAloud, onRegenerate) is provided. The copy button is always visible when the toolbar is shown.CopilotChatConfigurationProvider. See useCopilotChatConfiguration for the full list of label keys.toolCallsView slot. Each tool call is resolved using the useRenderToolCall hook, which looks up registered renderers by tool name.CopilotChatMessageView -- Parent component that uses this as the default assistant message slotCopilotChatUserMessage -- Companion component for user messagesuseRenderToolCall -- Hook used internally for resolving tool call renderersuseCopilotChatConfiguration -- Provider for localized toolbar labels