Skip to main content
Prerequisites: CometChat.init() + CometChat.login() completed, AI features enabled in Dashboard Event flow: Run Start -> Tool Call(s) -> Text Message Stream -> Run Finished
AI Agents enable intelligent, automated interactions within your application. They process user messages, trigger tools, and respond with contextually relevant information. For a broader introduction, see the AI Agents section.
Agents only respond to text messages.

Sending a Message to an AI Agent

Send a text message to an agent’s UID like any other user:

Agent Run Lifecycle and Message Flow

When a user sends a text message to an Agent:
  1. The platform starts a run and streams real-time events via AIAssistantEventsDelegate
  2. After the run completes, persisted Agentic Messages arrive via CometChatMessageDelegate

Real-time Events

Events are received via onAIAssistantEventReceived as AIAssistantBaseEvent objects, in this order:
Run Start and Run Finished are always emitted. Tool Call events only appear when tools are invoked. Card events (Card StartCardCard End) appear only when the agent produces a card, and repeat for each card. Text Message events are always emitted and carry the assistant’s reply incrementally.

Card Streaming Events

When an agent produces a card, it is delivered through three streaming events on onAIAssistantEventReceived. Each event is a subclass of AIAssistantBaseEvent — check the concrete type to handle it.

Agentic Messages

After the run completes, these messages arrive via CometChatMessageDelegate:
Always remove listeners when they’re no longer needed (e.g., on view dismissal). Failing to remove listeners can cause memory leaks and duplicate event handling.

AIAssistantMessage Elements

Once a run completes, the assistant’s reply is persisted as an AIAssistantMessage. Its content is exposed as an ordered list of blocks via getElements(), letting you render text and cards in the exact order the agent produced them. When getElements() is nil or empty, fall back to the plain text body. Each AIAssistantElement exposes:

Next Steps

AI Chatbots

Set up AI-powered chatbots for automated conversations

AI Moderation

Automatically moderate messages with AI

AI User Copilot

AI-powered features like smart replies and conversation summaries

Send Messages

Send text messages that trigger AI Agent responses