CopilotChatAssistantMessage

Component for displaying assistant messages with Markdown, tool calls, and an action toolbar


Overview

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

import { CopilotChatAssistantMessage } from "@copilotkit/react-core/v2";
import "@copilotkit/react-core/v2/styles.css";

Props

Prop

Type

Prop

Type

Prop

Type

Prop

Type

Prop

Type

Prop

Type

Prop

Type

Prop

Type

Prop

Type

Slots

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.

Prop

Type

Prop

Type

Prop

Type

Prop

Type

Prop

Type

Prop

Type

Prop

Type

Prop

Type

CopilotChatToolCallsView

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

Props

Prop

Type

Prop

Type

Usage

Basic Assistant Message

function AssistantBubble({ message }) {
  return (
    <CopilotChatAssistantMessage
      message={message}
      onThumbsUp={(msg) => console.log("Thumbs up:", msg.id)}
      onThumbsDown={(msg) => console.log("Thumbs down:", msg.id)}
    />
  );
}

Customizing the Toolbar

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"
    />
  );
}

Hiding the Toolbar

function MinimalMessage({ message }) {
  return (
    <CopilotChatAssistantMessage message={message} toolbarVisible={false} />
  );
}

Custom Markdown Renderer

function CustomRendererMessage({ message }) {
  return (
    <CopilotChatAssistantMessage
      message={message}
      markdownRenderer={({ content }) => (
        <ReactMarkdown>{content}</ReactMarkdown>
      )}
    />
  );
}

Standalone Tool Calls View

function ToolCallsList({ message, allMessages }) {
  return (
    <div className="tool-calls">
      <CopilotChatToolCallsView message={message} messages={allMessages} />
    </div>
  );
}

Behavior

  • Markdown Support: The default Markdown renderer supports GitHub Flavored Markdown (tables, strikethrough, task lists), math expressions rendered with KaTeX, and syntax-highlighted code blocks via rehype-pretty-code.
  • Toolbar Visibility: The toolbar appears on hover or focus by default. Individual buttons are only rendered when their corresponding callback prop (onThumbsUp, onThumbsDown, onReadAloud, onRegenerate) is provided. The copy button is always visible when the toolbar is shown.
  • Localized Labels: All toolbar button tooltips are sourced from the nearest CopilotChatConfigurationProvider. See useCopilotChatConfiguration for the full list of label keys.
  • Tool Call Rendering: Tool calls embedded in the assistant message are rendered by the toolCallsView slot. Each tool call is resolved using the useRenderToolCall hook, which looks up registered renderers by tool name.
  • Slot System: Each slot prop accepts three forms -- a replacement component, a className string merged into the default, or a partial props object that extends the default component's props.

Related