Skip to main content
{
  "component": "CometChatAIAssistantChat",
  "package": "@cometchat/chat-uikit-react",
  "import": "import { CometChatAIAssistantChat } from \"@cometchat/chat-uikit-react\";",
  "description": "Composite AI agent chat with streaming responses, quick suggestions, new-chat reset, and chat history sidebar.",
  "cssRootClass": ".cometchat-ai-assistant-chat",
  "requiredProps": {
    "user": "CometChat.User — the AI agent user object"
  },
  "optionalProps": {
    "streamingSpeed": "number",
    "suggestedMessages": "string[]",
    "hideSuggestedMessages": "boolean",
    "hideNewChat": "boolean",
    "hideChatHistory": "boolean",
    "showBackButton": "boolean",
    "showCloseButton": "boolean",
    "loadLastAgentConversation": "boolean",
    "parentMessageId": "number",
    "aiAssistantTools": "CometChatAIAssistantTools",
    "templates": "CometChatMessageTemplate[]",
    "headerItemView": "JSX.Element",
    "headerTitleView": "JSX.Element",
    "headerSubtitleView": "JSX.Element",
    "headerLeadingView": "JSX.Element",
    "headerTrailingView": "JSX.Element",
    "headerAuxiliaryButtonView": "JSX.Element",
    "emptyChatImageView": "JSX.Element",
    "emptyChatGreetingView": "JSX.Element",
    "emptyChatIntroMessageView": "JSX.Element",
    "emptyView": "JSX.Element",
    "loadingView": "JSX.Element",
    "errorView": "JSX.Element"
  },
  "callbacks": {
    "onBackButtonClicked": "() => void",
    "onCloseButtonClicked": "() => void",
    "onSendButtonClick": "(message: CometChat.BaseMessage, previewMessageMode?: PreviewMessageMode) => void",
    "onError": "(e: CometChat.CometChatException) => void"
  },
  "events": null,
  "minimalExample": "<CometChatAIAssistantChat user={agentUser} />"
}

Where It Fits

CometChatAIAssistantChat is a standalone AI chat panel. It composes an internal message header, message list, and message composer into a self-contained AI conversation experience. It requires a CometChat.User representing the AI agent.
import { useState, useEffect } from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatAIAssistantChat } from "@cometchat/chat-uikit-react";

function AIAssistantPanel() {
  const [agent, setAgent] = useState<CometChat.User>();

  useEffect(() => {
    CometChat.getUser("assistant_uid").then((u) => setAgent(u));
  }, []);

  if (!agent) return null;

  return (
    <div style={{ height: "100vh", width: 480 }}>
      <CometChatAIAssistantChat user={agent} />
    </div>
  );
}

Minimal Render

import { useState, useEffect } from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatAIAssistantChat } from "@cometchat/chat-uikit-react";

function AIAssistantDemo() {
  const [agent, setAgent] = useState<CometChat.User>();

  useEffect(() => {
    CometChat.getUser("assistant_uid").then((u) => setAgent(u));
  }, []);

  if (!agent) return null;

  return <CometChatAIAssistantChat user={agent} />;
}
Root CSS class: .cometchat-ai-assistant-chat

Actions and Events

Callback Props

onBackButtonClicked

Fires when the header back button is clicked. Requires showBackButton={true}.
DetailValue
When it firesUser clicks the back button
Payload type() => void
import { useState, useEffect } from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatAIAssistantChat } from "@cometchat/chat-uikit-react";

function AIAssistantWithBack() {
  const [agent, setAgent] = useState<CometChat.User>();

  useEffect(() => {
    CometChat.getUser("assistant_uid").then((u) => setAgent(u));
  }, []);

  if (!agent) return null;

  return (
    <CometChatAIAssistantChat
      user={agent}
      showBackButton={true}
      onBackButtonClicked={() => console.log("Back clicked")}
    />
  );
}

onCloseButtonClicked

Fires when the header close button is clicked. Requires showCloseButton={true}.
DetailValue
When it firesUser clicks the close button
Payload type() => void
import { useState, useEffect } from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatAIAssistantChat } from "@cometchat/chat-uikit-react";

function AIAssistantWithClose() {
  const [agent, setAgent] = useState<CometChat.User>();

  useEffect(() => {
    CometChat.getUser("assistant_uid").then((u) => setAgent(u));
  }, []);

  if (!agent) return null;

  return (
    <CometChatAIAssistantChat
      user={agent}
      showCloseButton={true}
      onCloseButtonClicked={() => console.log("Close clicked")}
    />
  );
}

onSendButtonClick

Fires when the composer send button is clicked.
DetailValue
When it firesUser clicks the send button
Payload type(message: CometChat.BaseMessage, previewMessageMode?: PreviewMessageMode) => void
import { useState, useEffect } from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatAIAssistantChat } from "@cometchat/chat-uikit-react";

function AIAssistantWithSend() {
  const [agent, setAgent] = useState<CometChat.User>();

  useEffect(() => {
    CometChat.getUser("assistant_uid").then((u) => setAgent(u));
  }, []);

  if (!agent) return null;

  return (
    <CometChatAIAssistantChat
      user={agent}
      onSendButtonClick={(message) => console.log("Sent:", message)}
    />
  );
}

onError

Fires when the component encounters an internal error.
DetailValue
When it firesAny internal error during rendering or data fetching
Payload type(error: CometChat.CometChatException) => void
import { useState, useEffect } from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatAIAssistantChat } from "@cometchat/chat-uikit-react";

function AIAssistantWithError() {
  const [agent, setAgent] = useState<CometChat.User>();

  useEffect(() => {
    CometChat.getUser("assistant_uid").then((u) => setAgent(u));
  }, []);

  if (!agent) return null;

  return (
    <CometChatAIAssistantChat
      user={agent}
      onError={(error) => console.error("AI chat error:", error)}
    />
  );
}

Global UI Events

The AI Assistant Chat component does not emit global UI events. Interaction handling uses the callback props above.

SDK Events (Real-Time, Automatic)

The component internally manages SDK communication for AI streaming. No manual listener attachment needed.

Custom View Slots

SlotTypeReplaces
headerItemViewJSX.ElementEntire header list item
headerTitleViewJSX.ElementHeader title text
headerSubtitleViewJSX.ElementHeader subtitle text
headerLeadingViewJSX.ElementHeader avatar / left section
headerTrailingViewJSX.ElementHeader right section
headerAuxiliaryButtonViewJSX.ElementHeader auxiliary buttons (New Chat, History)
emptyChatImageViewJSX.ElementEmpty state image
emptyChatGreetingViewJSX.ElementEmpty state greeting title
emptyChatIntroMessageViewJSX.ElementEmpty state intro subtitle
emptyViewJSX.ElementMessage list empty state
loadingViewJSX.ElementLoading state
errorViewJSX.ElementError state
aiAssistantToolsCometChatAIAssistantToolsTool/function call handlers
templatesCometChatMessageTemplate[]Message bubble templates

emptyChatImageView

import { useState, useEffect } from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatAIAssistantChat } from "@cometchat/chat-uikit-react";

function AIAssistantCustomImage() {
  const [agent, setAgent] = useState<CometChat.User>();

  useEffect(() => {
    CometChat.getUser("assistant_uid").then((u) => setAgent(u));
  }, []);

  if (!agent) return null;

  return (
    <CometChatAIAssistantChat
      user={agent}
      emptyChatImageView={<img src={"ICON_URL"} height={60} width={60} alt="" />}
    />
  );
}

emptyChatGreetingView

import { useState, useEffect } from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatAIAssistantChat } from "@cometchat/chat-uikit-react";

function AIAssistantCustomGreeting() {
  const [agent, setAgent] = useState<CometChat.User>();

  useEffect(() => {
    CometChat.getUser("assistant_uid").then((u) => setAgent(u));
  }, []);

  if (!agent) return null;

  return (
    <CometChatAIAssistantChat
      user={agent}
      emptyChatGreetingView={
        <div className="cometchat-ai-assistant-chat__empty-chat-greeting">
          <span className="plan-name">Free Plan</span> .
          <span className="upgrade-button">Upgrade</span>
        </div>
      }
    />
  );
}

emptyChatIntroMessageView

import { useState, useEffect } from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatAIAssistantChat } from "@cometchat/chat-uikit-react";

function AIAssistantCustomIntro() {
  const [agent, setAgent] = useState<CometChat.User>();

  useEffect(() => {
    CometChat.getUser("assistant_uid").then((u) => setAgent(u));
  }, []);

  if (!agent) return null;

  return (
    <CometChatAIAssistantChat
      user={agent}
      emptyChatIntroMessageView={
        <div className="cometchat-ai-assistant-chat__empty-chat-intro">
          Hey, nice to see you What's new?
        </div>
      }
    />
  );
}

aiAssistantTools

Pass a CometChatAIAssistantTools instance to enable tool/function calls during assistant replies.
import { useState, useEffect } from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import {
  CometChatAIAssistantChat,
  CometChatAIAssistantTools,
} from "@cometchat/chat-uikit-react";

function AIAssistantWithTools() {
  const [agent, setAgent] = useState<CometChat.User>();

  useEffect(() => {
    CometChat.getUser("assistant_uid").then((u) => setAgent(u));
  }, []);

  const tools = new CometChatAIAssistantTools({
    getCurrentWeather: ({ location }: { location: string }) => {
      console.log("Fetching weather for", location);
    },
    createTicket: ({ title }: { title: string }) => {
      console.log("Create ticket:", title);
    },
  });

  if (!agent) return null;

  return <CometChatAIAssistantChat user={agent} aiAssistantTools={tools} />;
}

templates

Custom message templates to control message bubble rendering. See CometChatMessageTemplate.
import { useState, useEffect } from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import {
  CometChatAIAssistantChat,
  ChatConfigurator,
} from "@cometchat/chat-uikit-react";

function AIAssistantWithTemplates() {
  const [agent, setAgent] = useState<CometChat.User>();

  useEffect(() => {
    CometChat.getUser("assistant_uid").then((u) => setAgent(u));
  }, []);

  const getTemplates = () => {
    const templates = ChatConfigurator.getDataSource().getAllMessageTemplates();
    templates.map((data) => {
      data.footerView = (message) => null;
    });
    return templates;
  };

  if (!agent) return null;

  return <CometChatAIAssistantChat user={agent} templates={getTemplates()} />;
}

Common Patterns

AI assistant with suggestions and history

import { useState, useEffect } from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatAIAssistantChat } from "@cometchat/chat-uikit-react";

function FullFeaturedAssistant() {
  const [agent, setAgent] = useState<CometChat.User>();

  useEffect(() => {
    CometChat.getUser("assistant_uid").then((u) => setAgent(u));
  }, []);

  if (!agent) return null;

  return (
    <CometChatAIAssistantChat
      user={agent}
      suggestedMessages={["What can you help with?", "Summarize my tasks", "Draft an email"]}
      loadLastAgentConversation={true}
      showBackButton={true}
      onBackButtonClicked={() => console.log("Navigate back")}
    />
  );
}

Minimal assistant — no chrome

import { useState, useEffect } from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatAIAssistantChat } from "@cometchat/chat-uikit-react";

function MinimalAssistant() {
  const [agent, setAgent] = useState<CometChat.User>();

  useEffect(() => {
    CometChat.getUser("assistant_uid").then((u) => setAgent(u));
  }, []);

  if (!agent) return null;

  return (
    <CometChatAIAssistantChat
      user={agent}
      hideNewChat={true}
      hideChatHistory={true}
      hideSuggestedMessages={true}
    />
  );
}

CSS Architecture

The component uses CSS custom properties (design tokens) defined in @cometchat/chat-uikit-react/css-variables.css. The cascade:
  1. Global tokens (e.g., --cometchat-primary-color, --cometchat-background-color-01) set on the .cometchat root wrapper.
  2. Component CSS (.cometchat-ai-assistant-chat) consumes these tokens via var().
  3. Overrides target .cometchat-ai-assistant-chat descendant selectors.

Key Selectors

TargetSelector
Root.cometchat-ai-assistant-chat
Wrapper.cometchat-ai-assistant-chat__wrapper
Header wrapper.cometchat-ai-assistant-chat__header-wrapper
Header auxiliary view.cometchat-ai-assistant-chat__header-auxiliary-view
Message list wrapper.cometchat-ai-assistant-chat__message-list-wrapper
Composer wrapper.cometchat-ai-assistant-chat__composer-wrapper
Send button.cometchat-ai-assistant-chat__send-button-view
Send button (active).cometchat-ai-assistant-chat__send-button-view--active
Send button (streaming).cometchat-ai-assistant-chat__send-button-view--streaming
Empty state.cometchat-ai-assistant-chat__empty-state
Empty state content.cometchat-ai-assistant-chat__empty-state-content
Empty state icon.cometchat-ai-assistant-chat__empty-state-icon
Greeting message.cometchat-ai-assistant-chat__empty-state-greeting-message
Intro message.cometchat-ai-assistant-chat__empty-state-intro-message
Suggested messages.cometchat-ai-assistant-chat__empty-state-suggested-messages
Suggestion pill.cometchat-ai-assistant-chat__suggested-message-pill
Suggestion icon.cometchat-ai-assistant-chat__suggested-message-icon
Chat history sidebar.cometchat-ai-assistant-chat__sidebar
Sidebar open.cometchat-ai-assistant-chat__sidebar--open
Sidebar overlay.cometchat-ai-assistant-chat__sidebar-overlay
Copy button.cometchat-ai-assistant-message-bubble__copy

Example: Brand-themed AI assistant

.cometchat-ai-assistant-chat
  .cometchat-ai-assistant-chat__suggested-message-pill {
  background: #30a46c;
  color: #ffffff;
  font-size: 9px;
}

.cometchat-ai-assistant-chat
  .cometchat-ai-assistant-chat__suggested-message-pill
  .cometchat-ai-assistant-chat__suggested-message-icon {
  background: #ffffff;
  width: 9.55px;
  height: 9.55px;
}

.cometchat-ai-assistant-chat
  .cometchat-ai-assistant-chat__header-auxiliary-view
  .cometchat-button
  .cometchat-button__icon-default {
  background: #30a46c;
}

Customization Matrix

What to changeWhereProperty/APIExample
Override behavior on user interactionComponent propson<Event> callbacksonBackButtonClicked={() => navigate(-1)}
Toggle visibility of UI elementsComponent propshide<Feature> / show<Feature> boolean propshideNewChat={true}
Replace a section of the UIComponent propsView slot propsemptyChatGreetingView={<div>Hello</div>}
Change colors, fonts, spacingGlobal CSSTarget .cometchat-ai-assistant-chat class.cometchat-ai-assistant-chat .cometchat-ai-assistant-chat__suggested-message-pill { background: #30a46c; }

Accessibility

The component composes CometChatMessageHeader, CometChatMessageList, and CometChatMessageComposer internally. Keyboard navigation, focus management, and ARIA attributes are inherited from those components. Suggested message pills are keyboard-focusable and activate on Enter/Space. The chat history sidebar uses a backdrop overlay and traps focus when open.

Props

aiAssistantTools

KeyValue
TypeCometChatAIAssistantTools
Defaultundefined
Tool/function call handlers for the AI assistant.

emptyView

KeyValue
TypeReact.JSX.Element
Defaultundefined
Custom empty state for the message list.

emptyChatGreetingView

KeyValue
TypeReact.JSX.Element
Defaultundefined
Custom greeting title in the empty chat state. Default uses agent metadata greetingMessage or user name.

emptyChatImageView

KeyValue
TypeReact.JSX.Element
Defaultundefined
Custom image in the empty chat state.

emptyChatIntroMessageView

KeyValue
TypeReact.JSX.Element
Defaultundefined
Custom intro subtitle in the empty chat state. Default uses agent metadata introductoryMessage.

errorView

KeyValue
TypeReact.JSX.Element
Defaultundefined
Custom error state view.

headerAuxiliaryButtonView

KeyValue
TypeReact.JSX.Element
Defaultundefined
Replaces the header auxiliary buttons (New Chat, History).

headerItemView

KeyValue
TypeReact.JSX.Element
Defaultundefined
Replaces the entire header list item.

headerLeadingView

KeyValue
TypeReact.JSX.Element
Defaultundefined
Replaces the header avatar / left section.

headerSubtitleView

KeyValue
TypeReact.JSX.Element
Defaultundefined
Replaces the header subtitle text.

headerTitleView

KeyValue
TypeReact.JSX.Element
Defaultundefined
Replaces the header title text.

headerTrailingView

KeyValue
TypeReact.JSX.Element
Defaultundefined
Replaces the header right section.

hideChatHistory

KeyValue
Typeboolean
Defaultundefined
Hides the History button/sidebar.

hideNewChat

KeyValue
Typeboolean
Defaultundefined
Hides the New Chat button in header.

hideSuggestedMessages

KeyValue
Typeboolean
Defaultundefined
Hides the suggested messages section in the empty state.

loadLastAgentConversation

KeyValue
Typeboolean
Defaultfalse
Loads the most recent existing agent conversation on mount.

loadingView

KeyValue
TypeReact.JSX.Element
Defaultundefined
Custom loading state view.

onBackButtonClicked

KeyValue
Type() => void
Defaultundefined
Fires when the header back button is clicked. Requires showBackButton={true}.

onCloseButtonClicked

KeyValue
Type() => void
Defaultundefined
Fires when the header close button is clicked. Requires showCloseButton={true}.

onError

KeyValue
Type(e: CometChat.CometChatException) => void
Defaultundefined
Fires on internal errors.

onSendButtonClick

KeyValue
Type(message: CometChat.BaseMessage, previewMessageMode?: PreviewMessageMode) => void
Defaultundefined
Fires when the composer send button is clicked.

parentMessageId

KeyValue
Typenumber
Defaultundefined
Loads a specific agent conversation. Takes priority over loadLastAgentConversation.

showBackButton

KeyValue
Typeboolean
Defaultundefined
Shows back button in header.

showCloseButton

KeyValue
Typeboolean
Defaultundefined
Shows close button in header.

streamingSpeed

KeyValue
Typenumber
Defaultundefined
Characters-per-second speed for streaming replies.

suggestedMessages

KeyValue
Typestring[]
Defaultundefined
Quick prompt suggestions displayed in the empty state.

templates

KeyValue
TypeCometChatMessageTemplate[]
Defaultundefined
Custom message bubble templates. See CometChatMessageTemplate.

user

KeyValue
TypeCometChat.User
Default— (required)
The AI agent user object. Must be fetched via CometChat.getUser() before passing.

CSS Selectors

TargetSelector
Root.cometchat-ai-assistant-chat
Wrapper.cometchat-ai-assistant-chat__wrapper
Header wrapper.cometchat-ai-assistant-chat__header-wrapper
Header auxiliary view.cometchat-ai-assistant-chat__header-auxiliary-view
Message list wrapper.cometchat-ai-assistant-chat__message-list-wrapper
Composer wrapper.cometchat-ai-assistant-chat__composer-wrapper
Send button.cometchat-ai-assistant-chat__send-button-view
Send button (active).cometchat-ai-assistant-chat__send-button-view--active
Send button (streaming).cometchat-ai-assistant-chat__send-button-view--streaming
Empty state.cometchat-ai-assistant-chat__empty-state
Empty state content.cometchat-ai-assistant-chat__empty-state-content
Empty state icon.cometchat-ai-assistant-chat__empty-state-icon
Greeting message.cometchat-ai-assistant-chat__empty-state-greeting-message
Intro message.cometchat-ai-assistant-chat__empty-state-intro-message
Suggested messages.cometchat-ai-assistant-chat__empty-state-suggested-messages
Suggestion pill.cometchat-ai-assistant-chat__suggested-message-pill
Suggestion icon.cometchat-ai-assistant-chat__suggested-message-icon
Chat history sidebar.cometchat-ai-assistant-chat__sidebar
Sidebar open.cometchat-ai-assistant-chat__sidebar--open
Sidebar overlay.cometchat-ai-assistant-chat__sidebar-overlay
Copy button.cometchat-ai-assistant-message-bubble__copy