Skip to main content
CometChatAIAssistantChatHistory displays the conversation history between users and an AI assistant, providing a structured view of past interactions for easy review.

When to use this

  • You need to display a list of past conversations between a user and an AI assistant.
  • You want users to review previous messages and context from AI assistant interactions.
  • You need tap and long-press actions on chat history items (open a chat, perform additional actions).
  • You want to provide a “new chat” button to start a new conversation with the AI assistant.
  • You need to customize the appearance of the chat history list with styles.

Prerequisites

  • CometChat SDK initialized with CometChatUIKit.init() and a user logged in.
  • The cometchat-chat-uikit-android dependency added to your project.
  • A valid layout XML or Activity/Fragment where you will place the component.
  • The user’s role must be set to @agentic to use AI Assistant features.

Quick start

  1. Open your layout XML file.
  2. Add the CometChatAIAssistantChatHistory XML element:
<com.cometchat.chatuikit.aiassistantchathistory.CometChatAIAssistantChatHistory
    android:id="@+id/cometchat_ai_assistant_chat_history"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>
What this does: Adds the CometChatAIAssistantChatHistory component to your layout. It fills the available width and height and renders the AI assistant chat history list.
  1. In your Activity or Fragment, create a User object with the role set to @agentic and pass it to the component:
User user = new User();
user.setUid("userId");
user.setName("User Name");
user.setRole("@agentic"); // User role must be @agentic to use AI Assistant features

binding.cometChatAiAssistantChatHistory.setUser(user);
What this does: Creates a User object with the @agentic role and sets it on the CometChatAIAssistantChatHistory component. This is required for the component to fetch and display the AI assistant chat histories for that user.
  1. Build and run your app.
  2. Verify that the AI assistant chat history list appears with past conversation items.

Core concepts

  • CometChatAIAssistantChatHistory: The main component class that renders the AI assistant chat history list. It is a Composite Component that can be launched via button clicks or any user-triggered action.
  • Actions: Callbacks such as setOnItemClickListener, setOnItemLongClickListener, setOnNewChatClickListener, and setOnCloseClickListener that let you respond to user interactions.
  • Style: XML theme styles applied via setStyle() to customize colors, fonts, and visual appearance of the chat history.
  • Functionality: Methods like setUser, setErrorStateVisibility, and setEmptyStateVisibility that configure the component’s behavior and state visibility.

Implementation

Actions

What you’re changing: How the component responds to user interactions such as taps, long-presses, new chat clicks, and close clicks.
  • Where: Activity or Fragment where you hold a reference to CometChatAIAssistantChatHistory.
  • Applies to: CometChatAIAssistantChatHistory.
  • Default behavior: Predefined actions execute automatically when the user interacts with the component.
  • Override: Call the corresponding setter method to replace the default behavior with your own logic.

setOnItemClickListener

Function invoked when a chat history item is clicked, used to open an AI assistant chat screen.
YourActivity.java
binding.cometchatAiAssistantChatHistory.setOnItemClickListener((view, position, message) -> {

        });
What this does: Replaces the default item-click behavior. When a user taps a chat history item, your custom lambda executes instead of the built-in navigation.

setOnItemLongClickListener

Function executed when a chat history item is long-pressed, allowing additional actions like delete or block.
YourActivity.java
binding.cometchatAiAssistantChatHistory.setOnItemLongClickListener((view, position, message) -> {

        });
What this does: Replaces the default long-press behavior. When a user long-presses a chat history item, your custom lambda executes.

setOnNewChatClickListener

Function triggered when the new chat button is clicked, used to start a new conversation with the AI assistant.
YourActivity.java
binding.cometchatAiAssistantChatHistory.setOnNewChatClickListener(() -> {

        });
What this does: Replaces the default new-chat-click behavior. When the user taps the new chat button, your custom logic runs instead of the built-in action.

setOnCloseClickListener

Function activated when the close button is clicked, used to exit the chat history view.
YourActivity.java
binding.cometchatAiAssistantChatHistory.setOnCloseClickListener(() -> {

        });
What this does: Replaces the default close-click behavior. When the user taps the close button, your custom logic runs instead of the built-in exit action.
  • Verify: After setting an action callback, trigger the corresponding user interaction (tap, long-press, new chat, close) and confirm your custom logic executes instead of the default behavior.

Style

What you’re changing: The visual appearance of the AI Assistant Chat History component using XML theme styles.
  • Where: themes.xml for style definitions, and your Activity/Fragment for applying the style.
  • Applies to: CometChatAIAssistantChatHistory.
  • Default behavior: The component uses its default style.
  • Override: Define a custom style in themes.xml, then call setStyle() on the component.
  • Code:
themes.xml
<style name="CustomAIAssistantChatHistoryStyle">
    <item name="cometChatAIAssistantChatHistoryBackgroundColor">#FFFAF6</item>
    <item name="cometChatAIAssistantChatHistoryHeaderBackgroundColor">#FFFAF6</item>
    <item name="cometChatAIAssistantChatHistoryHeaderTextColor">?attr/cometchatTextColorPrimary</item>
    <item name="cometChatAIAssistantChatHistoryHeaderTextAppearance">@style/textStyleTimesNewRoman</item>
    <item name="cometChatAIAssistantChatHistoryNewChatBackgroundColor">#FFFAF6</item>
    <item name="cometChatAIAssistantChatHistoryNewChatTextColor">?attr/cometchatTextColorPrimary</item>
    <item name="cometChatAIAssistantChatHistoryNewChatTextAppearance">@style/textStyleTimesNewRoman</item>
    <item name="cometChatAIAssistantChatHistoryDateSeparatorTextAppearance">@style/textStyleTimesNewRoman</item>
    <item name="cometChatAIAssistantChatHistoryDateSeparatorTextColor">?attr/cometchatTextColorTertiary</item>
    <item name="cometChatAIAssistantChatHistoryDateSeparatorBackgroundColor">#FFFAF6</item>
    <item name="cometChatAIAssistantChatHistoryItemBackgroundColor">#FFFAF6</item>
    <item name="cometChatAIAssistantChatHistoryItemTextAppearance">@style/textStyleTimesNewRoman</item>
    <item name="cometChatAIAssistantChatHistoryItemTextColor">?attr/cometchatTextColorPrimary</item>
</style>

<style name="textStyleTimesNewRoman">
    <item name="android:fontFamily">@font/times_new_roman_regular</item>
</style>
What this does: Defines a custom style CustomAIAssistantChatHistoryStyle that sets the background color to #FFFAF6 for the component, header, new chat area, date separator, and items. It applies a Times New Roman font to the header, new chat text, date separator, and item text. A helper style textStyleTimesNewRoman defines the font family.
binding.cometchatAiAssistantChatHistory.setStyle(R.style.CustomAIAssistantChatHistoryStyle);
What this does: Applies the CustomAIAssistantChatHistoryStyle theme to the CometChatAIAssistantChatHistory component, changing the background colors and fonts.
To know more such attributes, visit the attributes file.
  • Verify: The chat history component displays with the #FFFAF6 background color and Times New Roman font for header text, new chat text, date separator text, and item text.

Functionality

What you’re changing: Small functional customizations such as setting the user and toggling visibility of UI states.
  • Where: Activity or Fragment where you hold a reference to CometChatAIAssistantChatHistory.
  • Applies to: CometChatAIAssistantChatHistory.
  • Default behavior: All UI states are visible with default settings.
  • Override: Call the corresponding method on the component instance.
MethodsDescriptionCode
setUserSets the user whose chat histories with the AI assistant need to be fetched. This is a required property for the component to function. The user’s role must be @agentic..setUser(user);
setErrorStateVisibilityToggles the visibility of the error state of the component.setErrorStateVisibility(View.GONE);
setEmptyStateVisibilityToggles the visibility of the empty state of the component.setEmptyStateVisibility(View.GONE);
  • Verify: After calling setUser(user), confirm the component fetches and displays the AI assistant chat histories for that user. After calling a visibility method, confirm the corresponding UI state is shown or hidden.

Customization matrix

What you want to changeWhereProperty/APIExample
Component background colorthemes.xmlcometChatAIAssistantChatHistoryBackgroundColor<item name="cometChatAIAssistantChatHistoryBackgroundColor">#FFFAF6</item>
Header background colorthemes.xmlcometChatAIAssistantChatHistoryHeaderBackgroundColor<item name="cometChatAIAssistantChatHistoryHeaderBackgroundColor">#FFFAF6</item>
Header text colorthemes.xmlcometChatAIAssistantChatHistoryHeaderTextColor<item name="cometChatAIAssistantChatHistoryHeaderTextColor">?attr/cometchatTextColorPrimary</item>
Header text appearancethemes.xmlcometChatAIAssistantChatHistoryHeaderTextAppearance<item name="cometChatAIAssistantChatHistoryHeaderTextAppearance">@style/textStyleTimesNewRoman</item>
New chat background colorthemes.xmlcometChatAIAssistantChatHistoryNewChatBackgroundColor<item name="cometChatAIAssistantChatHistoryNewChatBackgroundColor">#FFFAF6</item>
New chat text colorthemes.xmlcometChatAIAssistantChatHistoryNewChatTextColor<item name="cometChatAIAssistantChatHistoryNewChatTextColor">?attr/cometchatTextColorPrimary</item>
New chat text appearancethemes.xmlcometChatAIAssistantChatHistoryNewChatTextAppearance<item name="cometChatAIAssistantChatHistoryNewChatTextAppearance">@style/textStyleTimesNewRoman</item>
Date separator text appearancethemes.xmlcometChatAIAssistantChatHistoryDateSeparatorTextAppearance<item name="cometChatAIAssistantChatHistoryDateSeparatorTextAppearance">@style/textStyleTimesNewRoman</item>
Date separator text colorthemes.xmlcometChatAIAssistantChatHistoryDateSeparatorTextColor<item name="cometChatAIAssistantChatHistoryDateSeparatorTextColor">?attr/cometchatTextColorTertiary</item>
Date separator background colorthemes.xmlcometChatAIAssistantChatHistoryDateSeparatorBackgroundColor<item name="cometChatAIAssistantChatHistoryDateSeparatorBackgroundColor">#FFFAF6</item>
Item background colorthemes.xmlcometChatAIAssistantChatHistoryItemBackgroundColor<item name="cometChatAIAssistantChatHistoryItemBackgroundColor">#FFFAF6</item>
Item text appearancethemes.xmlcometChatAIAssistantChatHistoryItemTextAppearance<item name="cometChatAIAssistantChatHistoryItemTextAppearance">@style/textStyleTimesNewRoman</item>
Item text colorthemes.xmlcometChatAIAssistantChatHistoryItemTextColor<item name="cometChatAIAssistantChatHistoryItemTextColor">?attr/cometchatTextColorPrimary</item>
Apply a custom styleActivity/FragmentsetStyle(int styleRes)binding.cometchatAiAssistantChatHistory.setStyle(R.style.CustomAIAssistantChatHistoryStyle);
Set the user for fetching historyActivity/FragmentsetUser(User).setUser(user);
Error state visibilityActivity/FragmentsetErrorStateVisibility(int).setErrorStateVisibility(View.GONE);
Empty state visibilityActivity/FragmentsetEmptyStateVisibility(int).setEmptyStateVisibility(View.GONE);

Common pitfalls & fixes

PitfallFix
Component does not renderEnsure CometChatUIKit.init() is called and awaited before using any UI Kit component. If init() has not completed, the component will not load data.
Chat history list is emptyVerify that setUser(user) is called with a valid User object before the component attempts to fetch data. The user is a required property.
AI Assistant features not workingEnsure the user’s role is set to @agentic using user.setRole("@agentic") (Java) or user.role = "@agentic" (Kotlin). If the role is not @agentic, AI Assistant features will not be available.
Custom style not visibleVerify that you call setStyle(R.style.YourStyle) on the component instance and that the style attributes use the correct cometChatAIAssistantChatHistory* prefix.
setOnItemClickListener not firingEnsure you are calling setOnItemClickListener on the correct CometChatAIAssistantChatHistory instance referenced by your binding or findViewById.
Error state or empty state still visible after hidingEnsure you call setErrorStateVisibility(View.GONE) or setEmptyStateVisibility(View.GONE) on the correct component instance before the component loads data.

FAQ

Q: What is the @agentic role and why is it required? A: The @agentic role is set on the User object via user.setRole("@agentic"). It must be set to use AI Assistant features. If the role is not @agentic, the component will not function for AI assistant chat history. Q: How do I start a new AI assistant conversation from the chat history? A: Use setOnNewChatClickListener to define custom logic that runs when the user taps the new chat button. Implement your navigation or conversation creation logic inside the callback. Q: Can I customize the fonts and colors of the chat history? A: Yes. Define a custom style in themes.xml using the cometChatAIAssistantChatHistory* attributes (e.g., cometChatAIAssistantChatHistoryHeaderTextAppearance, cometChatAIAssistantChatHistoryItemTextColor) and apply it with setStyle(). Q: How do I handle the close button action? A: Use setOnCloseClickListener to provide custom logic that runs when the user taps the close button. Implement your navigation or dismissal logic inside the callback.

Next steps