Skip to main content
FieldValue
Packagecometchat_chat_uikit
Key componentsCometChatAIAssistantChatHistory, CometChatMessageList, CometChatMessageComposer, CometChatMessageHeader
InitCometChatUIKit.init(uiKitSettings) then CometChatUIKit.login(uid)
Entry pointAI agent user → AIAssistantChatScreen with AI-specific styling
Sample appGitHub
RelatedAll Guides
AI Agent Integration enables intelligent conversational AI capabilities with chat history, contextual responses, and seamless handoffs. Before starting, complete the Getting Started guide.

Components

Component / ClassRole
CometChatMessageHeaderManages message interactions with AI-specific buttons
CometChatMessageListDisplays messages with AI-specific styling
CometChatMessageComposerComposes messages with AI placeholders
CometChatAIAssistantChatHistoryDisplays previous AI conversation history
CometChatAiAssistantBubbleStyleCustom styling for AI chat bubbles
AIConstants.aiRoleConstant to detect AI agent users

Integration Steps

1. Detect AI Agent

Check if the user is an AI agent by their role.
bool isUserAgentic() {
  return widget.user?.role == AIConstants.aiRole;
}

2. AI Chat Screen Setup

Create a screen for AI Assistant chat using standard message components with AI-specific styling.
class AIAssistantChatScreen extends StatefulWidget {
  final User? user;
  final Group? group;
  final BaseMessage? parentMessage;
  final bool? isHistory;

  const AIAssistantChatScreen({
    Key? key,
    this.user,
    this.group,
    this.parentMessage,
    this.isHistory,
  }) : super(key: key);

  @override
  State<AIAssistantChatScreen> createState() => _AIAssistantChatScreenState();
}

3. Message Header with AI Actions

Configure the message header with chat history and new chat buttons.
CometChatMessageHeader(
  user: widget.user,
  group: widget.group,
  chatHistoryButtonClick: () {
    Navigator.push(
      context,
      MaterialPageRoute(
        builder: (context) => CometChatAIAssistantChatHistory(
          user: widget.user,
          group: widget.group,
          onNewChatButtonClicked: () => onNewChatClicked(true),
          onMessageClicked: (message) => navigateToThread(message),
          onClose: () => Navigator.of(context).pop(),
        ),
      ),
    );
  },
  newChatButtonClick: () => onNewChatClicked(false),
)

4. AI Message List

Configure the message list with AI-specific styling and options.
CometChatMessageList(
  user: user,
  group: group,
  hideReplyInThreadOption: isUserAgentic() ? true : false,
  hideThreadView: true,
  messagesRequestBuilder: requestBuilder,
  style: CometChatMessageListStyle(
    backgroundColor: isUserAgentic() ? colorPalette.background3 : null,
    outgoingMessageBubbleStyle: CometChatOutgoingMessageBubbleStyle(
      textBubbleStyle: CometChatTextBubbleStyle(
        backgroundColor: isUserAgentic() ? colorPalette.background4 : null,
        textColor: isUserAgentic() ? colorPalette.textPrimary : null,
      ),
    ),
  ),
)

5. AI Composer

Configure the composer with AI-specific placeholder text.
CometChatMessageComposer(
  user: widget.user,
  group: widget.group,
  disableMentions: isUserAgentic() ? true : false,
  placeholderText: isUserAgentic() 
    ? "${Translations.of(context).askAnything}..." 
    : null,
  parentMessageId: widget.parentMessage?.id ?? 0,
)

6. Custom AI Bubble Styling

Apply custom styles for AI chat bubbles using ThemeExtension.
MaterialApp(
  theme: ThemeData(
    extensions: [
      CometChatAiAssistantBubbleStyle(
        backgroundColor: Colors.transparent,
        border: Border.all(color: Colors.blueAccent, width: 1),
        textColor: const Color(0xFF141414),
      ),
    ],
  ),
)

Feature Matrix

FeatureComponent / MethodDescription
AI detectionAIConstants.aiRoleCheck if user is AI agent
AI chat screenAIAssistantChatScreenFull AI chat interface
Chat historyCometChatAIAssistantChatHistoryBrowse previous AI sessions
AI stylingCometChatAiAssistantBubbleStyleCustom AI bubble appearance
New chatonNewChatClicked()Start fresh AI conversation

Next Steps