Skip to main content
Implement agentic message flows in your Flutter app using CometChat V6 UIKit. This guide covers how to integrate AI-powered message handling with the chat interface.

Overview

The Message Agentic Flow feature enables AI-driven interactions within your chat application. In V6, AI features are handled through MessageTemplateUtils rather than explicit extension registration.

Integration

Enable AI Features

Ensure AI features are enabled on your CometChat Dashboard. V6 handles AI integration internally.

Custom AI Message Handling

CometChatMessageList(
  user: user,
  templates: [
    CometChatMessageTemplate(
      type: "ai_response",
      category: MessageCategoryConstants.custom,
      contentView: (baseMessage, context, alignment, {additionalConfigurations}) {
        // Custom rendering for AI agent messages
        return Container(
          padding: const EdgeInsets.all(12),
          decoration: BoxDecoration(
            color: Color(0xFFEDEAFA),
            borderRadius: BorderRadius.circular(12),
          ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Row(
                children: [
                  Icon(Icons.smart_toy, color: Color(0xFF6852D6), size: 16),
                  SizedBox(width: 4),
                  Text("AI Assistant", style: TextStyle(
                    color: Color(0xFF6852D6),
                    fontWeight: FontWeight.bold,
                    fontSize: 12,
                  )),
                ],
              ),
              SizedBox(height: 8),
              Text((baseMessage as TextMessage).text),
            ],
          ),
        );
      },
    ),
  ],
)

AI Assistant Chat History

Use the CometChatAIAssistantChatHistory widget to display past AI interactions:
CometChatAIAssistantChatHistory(
  user: user,
  style: CometChatAIAssistantChatHistoryStyle(
    backgroundColor: const Color(0xFFFFFAF6),
  ),
)

Key V6 Differences

AspectV5V6
AI extension registrationExplicit via UIKitSettings.aiFeatureHandled internally via MessageTemplateUtils
Custom AI templatesVia CometChatUIKit.getDataSource()Via MessageTemplateUtils and direct template injection
AI Assistant widgetCometChatAIAssistantChatHistorySame widget, same API