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.

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 AIAssistantListener
  2. After the run completes, persisted Agentic Messages arrive via MessageListener

Real-time Events

Events are received via the onAIAssistantEventReceived method of the AIAssistantListener class as AIAssistantBaseEvent objects, in this general order: Events arrive via onAIAssistantEventReceived in this order:
Run Start and Run Finished are always emitted. Tool Call events only appear when tools are invoked — there can be multiple tool call cycles in a single run. Card events (Card StartCardCard End) only appear when the agent produces a card, and may repeat for each card. Text Message events are always emitted and carry the assistant’s reply incrementally.

Event Object Properties

Every event is an AIAssistantBaseEvent with these common properties: Some events carry additional data:
Always remove AI Assistant listeners when the component unmounts to prevent memory leaks.

Event descriptions

  • Run Start: A new run has begun for the user’s message.
  • Tool Call Start: The agent decided to invoke a tool.
  • Tool Call Arguments: Arguments being passed to the tool.
  • Tool Call End: Tool execution completed.
  • Tool Call Result: Tool’s output is available.
  • Card Start: The agent started generating a card. Carries cardId and executionText (a human-readable status like “Building your product card…”).
  • Card: The full card payload is available. Use getCard() to retrieve the raw card JSON and pass it to the renderer.
  • Card End: The card generation flow is finalized.
  • Text Message Start: The agent started composing a reply.
  • Text Message Content: Streaming content chunks for progressive rendering.
  • Text Message End: The agent reply is complete.
  • Run Finished: The run is finalized; persisted messages will follow.

Card Streaming Events

When the agent generates a card, the run emits a card cycle (Card StartCardCard End). All three are AIAssistantBaseEvent subclasses delivered through the same onAIAssistantEventReceived callback — no separate listener is required.

Agentic Messages

After the run completes, these messages arrive via MessageListener: Each message type extends BaseMessage and has a typed data accessor: The getToolCalls() method on AIToolArgumentMessage returns an array of AIToolCall objects, each with:
Always remove listeners when they’re no longer needed (e.g., on component unmount or page navigation). Failing to remove listeners can cause memory leaks and duplicate event handling.

AIAssistantMessage Elements

Starting from React Native SDK 4.0.26, a persisted AIAssistantMessage carries its content as an ordered list of blocks via getElements(). This is the preferred render source — when present, walk the list in order and render each block. If the agent response contains only a card (no accompanying text), the text returned by getAssistantMessageData().getText() will be empty, so always prefer getElements(). getElements() returns an array of AIAssistantElement (or null for older messages without elements). Each element exposes:

Next Steps

AI Agents Overview

Explore the full AI Agents platform documentation

AI Moderation

Automatically moderate messages using AI

Send Messages

Send text messages that trigger AI Agent responses