# CopilotChatAssistantMessage

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

## Overview [#overview]

`CopilotChatAssistantMessage` displays assistant messages with Markdown support, tool call rendering, and an action toolbar. The default Markdown renderer is Streamdown. It renders GitHub Flavored Markdown, KaTeX math, and code blocks highlighted with Shiki. The toolbar provides copy, rating (thumbs up/down), read aloud, and regenerate buttons with localized tooltips sourced from `CopilotChatConfigurationProvider`. For user messages, see [`CopilotChatUserMessage`](/reference/components/CopilotChatUserMessage).

## Import [#import]

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

## Props [#props]

<PropertyReference name="message" type="AssistantMessage" required>
  The assistant message object to render. Contains the message `content`, `id`,
  `role`, and any associated tool calls.
</PropertyReference>

<PropertyReference name="messages" type="Message[]">
  The full array of conversation messages. Passed through to the `toolCallsView`
  slot for context-aware tool call rendering.
</PropertyReference>

<PropertyReference name="isRunning" type="boolean" default="false">
  Whether the agent is currently executing. Can be used by slot components to
  adjust their behavior during streaming.
</PropertyReference>

<PropertyReference name="isLatest" type="boolean">
  Whether this is the last message the chat renders. While `isRunning` is
  `true`, the latest message hides its toolbar.
  [`CopilotChatMessageView`](/reference/components/CopilotChatMessageView) passes
  it, because its rendered list can differ from `messages` when
  `transformMessages` drops, replaces or reorders messages. When omitted, the
  component compares `message.id` with the last entry of `messages`.
</PropertyReference>

<PropertyReference name="onThumbsUp" type="(message: AssistantMessage) => void">
  Callback invoked when the user clicks the thumbs-up button. While Automatic
  Learning records ratings, it runs only when the click gives a rating. The
  thumbs-up button shows when one of these is true:

  - `onThumbsUp` is set.
  - `thumbsUpButton` is set.
  - The message is in `CopilotChatMessageView` and Automatic Learning records
    ratings (see [Reply ratings](#reply-ratings)).

  Inside `CopilotChatMessageView`, the message that the callback receives can
  also carry a `rawEvent` field. It holds the `rawEvent` value of the AG-UI
  `TEXT_MESSAGE_START` event that started the message in the live stream.
  Direct use of this component receives the canonical assistant message.
</PropertyReference>

<PropertyReference
  name="onThumbsDown"
  type="(message: AssistantMessage) => void"
>
  Callback invoked when the user clicks the thumbs-down button. While
  Automatic Learning records ratings, it runs only when the click gives a
  rating. The thumbs-down button shows when one of these is true:

  - `onThumbsDown` is set.
  - `thumbsDownButton` is set.
  - The message is in `CopilotChatMessageView` and Automatic Learning records
    ratings.

  The `rawEvent` field described under `onThumbsUp` applies here too.
</PropertyReference>

<PropertyReference
  name="onReadAloud"
  type="(message: AssistantMessage) => void"
>
  Callback invoked when the user clicks the read-aloud button. When neither
  this prop nor the `readAloudButton` slot is set, 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 neither
  this prop nor the `regenerateButton` slot is set, 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>

## Slots [#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.

<PropertyReference name="markdownRenderer" type="SlotValue<typeof CopilotChatAssistantMessage.MarkdownRenderer>">
  Slot for the Markdown rendering engine. Defaults to `CopilotChatAssistantMessage.MarkdownRenderer`, which uses Streamdown and supports GFM tables, math expressions via KaTeX, and code blocks highlighted with Shiki.

**As a replacement component:**

```tsx
<CopilotChatAssistantMessage
  message={msg}
  markdownRenderer={({ content }) => (
    <div className="whitespace-pre-wrap">{content}</div>
  )}
/>
```

</PropertyReference>

<PropertyReference name="toolbar" type="SlotValue<typeof CopilotChatAssistantMessage.Toolbar>">
  Slot for the action toolbar container. Defaults to `CopilotChatAssistantMessage.Toolbar`, which renders a horizontal row of action buttons below the message content.

**As a className:**

```tsx
<CopilotChatAssistantMessage message={msg} toolbar="border-t pt-2 mt-2" />
```

</PropertyReference>

<PropertyReference
  name="copyButton"
  type="SlotValue<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="SlotValue<typeof CopilotChatAssistantMessage.ThumbsUpButton>"
>
  Slot for the thumbs-up rating button. Defaults to
  `CopilotChatAssistantMessage.ThumbsUpButton`. Rendered when this slot or
  `onThumbsUp` is set, or inside `CopilotChatMessageView` while Automatic
  Learning records ratings. While Automatic Learning records ratings, a
  replacement receives:

  - Every thumb: `aria-pressed`, `data-copilotkit-rating`, and `onClick`.
  - The chosen thumb also: `aria-haspopup`, `aria-expanded`, `onPointerEnter`,
    `onPointerLeave`, `onFocus`, `onBlur`, and `onKeyDown`.

  Spread the props it receives onto its button and pass the click event to
  `onClick`, so a keyboard rating moves focus into the comment. The tooltip
  label is sourced from `CopilotChatLabels.assistantMessageToolbarThumbsUpLabel`.
</PropertyReference>

<PropertyReference
  name="thumbsDownButton"
  type="SlotValue<typeof CopilotChatAssistantMessage.ThumbsDownButton>"
>
  Slot for the thumbs-down rating button. Defaults to
  `CopilotChatAssistantMessage.ThumbsDownButton`. Rendered when this slot or
  `onThumbsDown` is set, or inside `CopilotChatMessageView` while Automatic
  Learning records ratings. A replacement receives the same props as a
  `thumbsUpButton` replacement. The tooltip label is sourced from
  `CopilotChatLabels.assistantMessageToolbarThumbsDownLabel`.
</PropertyReference>

<PropertyReference
  name="readAloudButton"
  type="SlotValue<typeof CopilotChatAssistantMessage.ReadAloudButton>"
>
  Slot for the read-aloud button. Defaults to
  `CopilotChatAssistantMessage.ReadAloudButton`. Rendered when `onReadAloud`
  or this slot is set. The tooltip label is sourced from
  `CopilotChatLabels.assistantMessageToolbarReadAloudLabel`.
</PropertyReference>

<PropertyReference
  name="regenerateButton"
  type="SlotValue<typeof CopilotChatAssistantMessage.RegenerateButton>"
>
  Slot for the regenerate button. Defaults to
  `CopilotChatAssistantMessage.RegenerateButton`. Rendered when `onRegenerate`
  or this slot is set. The tooltip label is sourced from
  `CopilotChatLabels.assistantMessageToolbarRegenerateLabel`.
</PropertyReference>

<PropertyReference
  name="toolCallsView"
  type="SlotValue<typeof CopilotChatToolCallsView>"
>
  Slot for rendering tool calls embedded in the assistant message. Defaults to
  [`CopilotChatToolCallsView`](#copilotchattoolcallsview), which renders each
  call with the closest registered tool renderer and groups calls made in a row.
</PropertyReference>

<PropertyReference
  name="feedbackComment"
  type="SlotValue<typeof CopilotChatAssistantMessage.FeedbackComment>"
>
  Slot for the comment field of a [reply rating](#reply-ratings), shown in a
  popover next to the chosen thumb. Defaults to
  `CopilotChatAssistantMessage.FeedbackComment`. A replacement receives
  `value`, `savedComment`, `inputRef`, `onChange`, `onSubmit`,
  `onEditingChange`, and `onLeave`. It renders after `children`, so a
  `children` layout does not need to place it.
</PropertyReference>

## CopilotChatToolCallsView [#copilotchattoolcallsview]

A companion component that renders the tool calls contained in an assistant message. Each call is drawn by the closest registered tool renderer (registered via `useFrontendTool`, `useHumanInTheLoop`, `useRenderTool` or `renderToolCalls` on the provider).

Calls the agent makes in a row are collapsed into one group, drawn by the `group` slot, when their renderer opts into grouping. The built-in card from `useDefaultRenderTool()` does; a custom renderer opts in with `group: true`. Any other call always shows on its own. Inside a [`CopilotChatMessageView`](/reference/components/CopilotChatMessageView), groups span messages and follow the view's `toolCallDisplay`; used on its own, this component groups the calls of `message`.

### Import [#import-1]

```tsx
import { CopilotChatToolCallsView } from "@copilotkit/react-core/v2";
```

### Props [#props-1]

<PropertyReference name="message" type="AssistantMessage" required>
  The assistant message whose tool calls should be rendered.
</PropertyReference>

<PropertyReference name="messages" type="Message[]">
  The full conversation message array. Provides context for tool call renderers
  that need to reference other messages (e.g., to find the corresponding tool
  result message).
</PropertyReference>

<PropertyReference
  name="display"
  type='"grouped" | "line" | "stacked" | "turn" | "separate"'
>
  How to show the calls. Inside a message view it defaults to the view's
  [`toolCallDisplay`](/reference/components/CopilotChatMessageView#toolcalldisplay);
  on its own it defaults to `"grouped"`. `"separate"` renders every call on its
  own, without a group.
</PropertyReference>

### Slots [#slots-1]

<PropertyReference name="group" type="SlotValue<typeof CopilotChatToolCallGroup>">
  Draws a group of calls made in a row in the `"grouped"`, `"line"` and
  `"stacked"` displays. The `"turn"` display draws its calls as rows inside the
  reply and doesn't use it. Defaults to
  [`CopilotChatToolCallGroup`](/reference/components/CopilotChatToolCallGroup).
  Like every slot, it accepts a className, props for the default, or a
  replacement component, which receives the group's `calls` and a
  `renderCall` function.

**Through `CopilotChat`:**

```tsx
<CopilotChat
  messageView={{
    assistantMessage: {
      toolCallsView: { group: "rounded-2xl shadow-sm" },
    },
  }}
/>
```

**As props for the default group:**

```tsx
<CopilotChatToolCallsView
  message={message}
  messages={messages}
  group={{ appearance: "line" }}
/>
```

**As a replacement component:**

```tsx
<CopilotChatToolCallsView
  message={message}
  messages={messages}
  group={({ calls, renderCall }) => (
    <details>
      <summary>Ran {calls.length} tools</summary>
      {calls.map((call) => (
        <div key={call.toolCall.id}>{renderCall(call)}</div>
      ))}
    </details>
  )}
/>
```

</PropertyReference>

## Usage [#usage]

### Basic Assistant Message [#basic-assistant-message]

```tsx
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 [#customizing-the-toolbar]

```tsx
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 [#hiding-the-toolbar]

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

### Custom Markdown Renderer [#custom-markdown-renderer]

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

### Standalone Tool Calls View [#standalone-tool-calls-view]

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

## Behavior [#behavior]

- **Markdown Support**: The default Markdown renderer is Streamdown. It supports GitHub Flavored Markdown (tables, strikethrough, task lists), math expressions rendered with KaTeX, and code blocks highlighted with Shiki.
- **Toolbar Visibility**: The toolbar shows below every assistant message that has text, except the latest message while `isRunning` is `true`. Each of these buttons renders when its callback prop (`onThumbsUp`, `onThumbsDown`, `onReadAloud`, `onRegenerate`) or its slot is set. The thumbs also render inside `CopilotChatMessageView` while Automatic Learning records ratings. 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`](/reference/hooks/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`](/reference/hooks/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.

## Reply ratings [#reply-ratings]

Automatic Learning records ratings when this component renders inside `CopilotChatMessageView` under a `CopilotChatConfigurationProvider` and Automatic Learning capture has started. It keeps recording ratings while capture reconnects or is stopped. While Automatic Learning records ratings:

- A click rates the reply and opens a field for an optional comment next to the thumb.
- Pointing at or keyboard-focusing the chosen thumb opens its comment again. On a touch screen, tapping the chosen thumb removes the rating instead.
- Clicking the chosen thumb again removes the rating.
- The rating shows while the page is open and is sent to the active Trajectory as a `message.feedback` event. Like any Trajectory event, a rating given while no Trajectory captures is not sent.

`onThumbsUp` and `onThumbsDown` run when a rating is given, not when it is removed. The comment field is the `feedbackComment` slot, `CopilotChatAssistantMessage.FeedbackComment` by default; its placeholder and send button use the `assistantMessageFeedbackCommentPlaceholder` and `assistantMessageFeedbackCommentSubmitLabel` labels. See [Collect reply ratings](/intelligence/capture-interactions#collect-reply-ratings) for the event and how ratings reach Intelligence.
