Overview

CometChatAIAssistantChat is a composite component that assembles the message header, message list, and message composer to provide an AI agent chat experience. It supports streaming responses, quick starter suggestions, “New Chat” to reset context, and a chat history sidebar.
import React from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatAIAssistantChat } from "@cometchat/chat-uikit-react";

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

    React.useEffect(() => {
        // Replace with your assistant UID
        CometChat.getUser("assistant_uid").then((u) => setAgent(u));
    }, []);

    if (!agent) return null;

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

A CometChat.User (the AI agent) is required to start the assistant chat.

Actions

Actions control how a component behaves. You can hook into the following callbacks:
1. onBackButtonClicked
Called when the header back button is clicked (visible when showBackButton is true).
import React from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatAIAssistantChat } from "@cometchat/chat-uikit-react";

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

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

    const handleBack = () => {
        // your custom action
    };

    if (!agent) return null;

    return (
        <CometChatAIAssistantChat
            user={agent}
            showBackButton
            onBackButtonClicked={handleBack}
        />
    ); 
}

2. onCloseButtonClicked
Called when the header close button is clicked (visible when showCloseButton is true).
import React from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatAIAssistantChat } from "@cometchat/chat-uikit-react";

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

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

    const handleClose = () => {
        // your custom action
    };

    if (!agent) return null;

    return (
        <CometChatAIAssistantChat 
            user={agent} 
            showCloseButton 
            onCloseButtonClicked={handleClose} 
        />
    );
}
3. onError
Listen to errors from the underlying header, list, or composer.
import React from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatAIAssistantChat } from "@cometchat/chat-uikit-react";
export function AIAssistantChatDemo() {
    const [agent, setAgent] = React.useState<CometChat.User>();

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

    const handleError = (error: CometChat.CometChatException) => {
        // your error handling
    };

    if (!agent) return null;

    return (
        <CometChatAIAssistantChat 
            user={agent} 
            onError={handleError} 
        />
    );
}

Customization

To fit your app’s design requirements, you can customize the appearance of the Assistant Chat component. We provide exposed properties that allow you to modify the experience and behavior according to your specific needs.

Style

You can set the css of the Assistant Chat Component to customize the styling.
import React from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatAIAssistantChat } from "@cometchat/chat-uikit-react";

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

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

    if (!agent) return null;

    return (
        <div className="cometchat-assistant-chat__wrapper">
            <CometChatAIAssistantChat user={agent} />
        </div>
    );
}

Functionality

These props tailor the experience. Most message options (copy/edit/delete/react, receipts, date separators, etc.) are disabled by default for assistant chats.
import React from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatAIAssistantChat } from "@cometchat/chat-uikit-react";

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

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

    if (!agent) return null;

    // Example: Set streaming speed to 30 characters per second
    // and show close button
    // You can also customize suggestions, empty state, etc.
    return (
        <CometChatAIAssistantChat
            user={agent}
            showCloseButton={true}
            setStreamingSpeed={30}
        />
    )
}

PropertyDescriptionExample
userRequired CometChat.User representing the AI agent.user={agent}
streamingSpeedCharacters-per-second speed for streaming replies. Default 30.streamingSpeed={50}
suggestedMessagesArray of quick prompts for the empty state.suggestedMessages=["Help", "Summarize"]
hideSuggestedMessagesHide the suggestions section.hideSuggestedMessages={true}
hideNewChatHide the New Chat button in header.hideNewChat={true}
hideChatHistoryHide the History button/sidebar.hideChatHistory={true}
showBackButtonShow back button in header.showBackButton
showCloseButtonShow close button in header.showCloseButton
onBackButtonClickedBack button handler.onBackButtonClicked={() => {}}
onCloseButtonClickedClose button handler.onCloseButtonClicked={() => {}}
onErrorError handler.onError={handleError}
emptyViewCustom empty state for the list.emptyView={<Empty/>}
loadingViewCustom loading view.loadingView={<Loading/>}
errorViewCustom error view.errorView={<Error/>}
emptyChatGreetingViewCustom empty title (default uses metadata.greetingMessage or user name).emptyChatGreetingView={<h3/>}
emptyChatIntroMessageViewCustom empty subtitle (default uses metadata.introductoryMessage).emptyChatIntroMessageView={<p/>}
emptyChatImageViewCustom empty image.emptyChatImageView={<img/>}
aiAssistantToolsProvide tool/function handlers for the assistant.aiAssistantTools={tools}

Advanced

Header Views

Customize header sections using the following props: headerItemView, headerTitleView, headerSubtitleView, headerLeadingView, headerTrailingView, and headerAuxiliaryButtonView. These customizations are done in the similar way as the Message Header component.
The header’s “New Chat” and “History” buttons are built-in. You can override them by providing a custom headerAuxiliaryButtonView.

Assistant Tools

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

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

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

    const tools = new CometChatAIAssistantTools({
        getCurrentWeather: ({ location }: { location: string }) => {
            // call your backend or a public API
            console.log("Fetching weather for", location);
        },
        createTicket: ({ title }: { title: string }) => {
            // open your internal ticketing flow
            console.log("Create ticket:", title);
        },
    });

    if (!agent) return null;

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

Empty Chat Image View

Provide a custom image for the empty state using emptyChatImageView.
import React from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatAIAssistantChat } from "@cometchat/chat-uikit-react";

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

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

Empty Chat Greeting View

Override the empty state greeting message view using the emptyChatGreetingView prop.
import React from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatAIAssistantChat } from "@cometchat/chat-uikit-react";

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

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

Empty Chat Intro Message View

You can override the empty chat intro message view using the emptyChatIntroMessageView prop.
import React from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatAIAssistantChat } from "@cometchat/chat-uikit-react";

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

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