docs/content/docs/reference/v2/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";
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"
/>
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).
import { CopilotChatToolCallsView } from "@copilotkit/react-core/v2";
import { CopilotChatAssistantMessage } from "@copilotkit/react-core/v2";
function AssistantBubble({ message }) {
return (
<CopilotChatAssistantMessage
message={message}
onThumbsUp={(msg) => console.log("Thumbs up:", msg.id)}
onThumbsDown={(msg) => console.log("Thumbs down:", msg.id)}
/>
);
}
import { CopilotChatAssistantMessage } from "@copilotkit/react-core/v2";
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"
/>
);
}
import { CopilotChatAssistantMessage } from "@copilotkit/react-core/v2";
function MinimalMessage({ message }) {
return (
<CopilotChatAssistantMessage
message={message}
toolbarVisible={false}
/>
);
}
import { CopilotChatAssistantMessage } from "@copilotkit/react-core/v2";
import ReactMarkdown from "react-markdown";
function CustomRendererMessage({ message }) {
return (
<CopilotChatAssistantMessage
message={message}
markdownRenderer={({ content }) => (
<ReactMarkdown>{content}</ReactMarkdown>
)}
/>
);
}
import { CopilotChatToolCallsView } from "@copilotkit/react-core/v2";
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