AI Integration Quick Reference
AI Integration Quick Reference
Currently, an Agent only responds to Text Messages.
Agent Run Lifecycle and Message Flow
This section explains how a user’s text message to an Agent becomes a structured “run” which emits real-time events and then produces agentic messages for historical retrieval.- A user sends a text message to an Agent.
- The platform starts a run and streams real-time events via the
AIAssistantListener. - After the run completes, persisted Agentic Messages arrive via the
MessageListener.
Real-time Events
Events are received via theonAIAssistantEventReceived method of the AIAssistantListener class as AIAssistantBaseEvent objects in this general order:
- Run Start
- Zero or more tool call cycles (repeats for each tool invocation):
- Tool Call Start
- Tool Call Arguments
- Tool Call End
- Tool Call Result
- One or more assistant reply streams:
- Text Message Start
- Text Message Content (multiple times; token/char streaming)
- Text Message End
- Run Finished
Run StartandRun Finishedare always emitted.Tool Callevents appear only when a backend or frontend tool is invoked. There can be multiple tool calls in a single run.Text Messageevents are always emitted and carry the assistant’s reply incrementally.
- Java
- Kotlin
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.
- 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.
Agentic Messages
These events are received via theMessageListener after the run completes.
AIAssistantMessage: The full assistant reply.AIToolResultMessage: The final output of a tool call.AIToolArgumentMessage: The arguments that were passed to a tool.
- Java
- Kotlin
Agentic Message Payload Structures
AIAssistantMessage Object
AIAssistantMessage Object
The
Sample AIAssistantMessage Object:
AIAssistantMessage object contains the AI assistant’s response:| Parameter | Type | Description |
|---|---|---|
id | long | Unique message identifier |
muid | String | Developer-defined message ID |
sender | User | User who sent the message |
receiver | AppEntity | Message receiver (User or Group) |
receiverUid | String | Receiver’s unique identifier |
type | String | Message type. Value: "assistant" |
receiverType | String | Type of receiver. Values: "user", "group" |
category | String | Message category. Value: "agentic" |
sentAt | long | Unix timestamp when sent |
deliveredAt | long | Unix timestamp when delivered |
readAt | long | Unix timestamp when read |
metadata | JSONObject | Custom message metadata |
readByMeAt | long | When logged-in user read message |
deliveredToMeAt | long | When delivered to logged-in user |
deletedAt | long | Unix timestamp when deleted (0 if not deleted) |
editedAt | long | Unix timestamp when edited (0 if not edited) |
deletedBy | String | UID of user who deleted (null if not deleted) |
editedBy | String | UID of user who edited (null if not edited) |
updatedAt | long | Unix timestamp of last update |
conversationId | String | Associated conversation ID |
runId | long | AI run identifier |
threadId | String | AI thread identifier |
text | String | AI response text |
tags | Array<String> | Message tags |
AIToolArgumentMessage Object
AIToolArgumentMessage Object
The
Sample AIToolArgumentMessage Object:
AIToolArgumentMessage object contains the arguments passed to a tool:| Parameter | Type | Description |
|---|---|---|
id | long | Unique message identifier |
muid | String | Developer-defined message ID |
sender | User | User who sent the message |
receiver | AppEntity | Message receiver (User or Group) |
receiverUid | String | Receiver’s unique identifier |
type | String | Message type. Value: "tool_arguments" |
receiverType | String | Type of receiver. Values: "user", "group" |
category | String | Message category. Value: "agentic" |
sentAt | long | Unix timestamp when sent |
deliveredAt | long | Unix timestamp when delivered |
readAt | long | Unix timestamp when read |
metadata | JSONObject | Custom message metadata |
readByMeAt | long | When logged-in user read message |
deliveredToMeAt | long | When delivered to logged-in user |
deletedAt | long | Unix timestamp when deleted (0 if not deleted) |
editedAt | long | Unix timestamp when edited (0 if not edited) |
deletedBy | String | UID of user who deleted (null if not deleted) |
editedBy | String | UID of user who edited (null if not edited) |
updatedAt | long | Unix timestamp of last update |
conversationId | String | Associated conversation ID |
runId | long | AI run identifier |
threadId | String | AI thread identifier |
toolCalls | Array<AIToolCall> | List of tool calls |
tags | Array<String> | Message tags |
AIToolResultMessage Object
AIToolResultMessage Object
The
Sample AIToolResultMessage Object:
AIToolResultMessage object contains the result from a tool execution:| Parameter | Type | Description |
|---|---|---|
id | long | Unique message identifier |
muid | String | Developer-defined message ID |
sender | User | User who sent the message |
receiver | AppEntity | Message receiver (User or Group) |
receiverUid | String | Receiver’s unique identifier |
type | String | Message type. Value: "tool_result" |
receiverType | String | Type of receiver. Values: "user", "group" |
category | String | Message category. Value: "agentic" |
sentAt | long | Unix timestamp when sent |
deliveredAt | long | Unix timestamp when delivered |
readAt | long | Unix timestamp when read |
metadata | JSONObject | Custom message metadata |
readByMeAt | long | When logged-in user read message |
deliveredToMeAt | long | When delivered to logged-in user |
deletedAt | long | Unix timestamp when deleted (0 if not deleted) |
editedAt | long | Unix timestamp when edited (0 if not edited) |
deletedBy | String | UID of user who deleted (null if not deleted) |
editedBy | String | UID of user who edited (null if not edited) |
updatedAt | long | Unix timestamp of last update |
conversationId | String | Associated conversation ID |
runId | long | AI run identifier |
threadId | String | AI thread identifier |
text | String | Tool result text |
toolCallId | String | ID of the tool call that produced this result |
tags | Array<String> | Message tags |
AIToolCall Object
AIToolCall Object
The
Sample AIToolCall Object:
AIToolCall object represents a single tool invocation:| Parameter | Type | Description |
|---|---|---|
id | String | Unique identifier for the tool call |
name | String | Name of the tool being called |
arguments | JSONObject | Arguments passed to the tool |
User Object (AI)
User Object (AI)
The nested
Sample User Object:
User object in sender contains:| Parameter | Type | Description |
|---|---|---|
uid | String | Unique identifier of the user |
name | String | Display name of the user |
avatar | String | URL to user’s profile picture |
link | String | URL to user’s profile page |
role | String | User role for access control |
metadata | JSONObject | Custom data set by developer |
status | String | User online status. Values: "online", "offline" |
statusMessage | String | Custom status message |
lastActiveAt | long | Unix timestamp of last activity |
hasBlockedMe | boolean | Whether this user has blocked the logged-in user |
blockedByMe | boolean | Whether the logged-in user has blocked this user |
tags | Array<String> | List of tags for user identification |
deactivatedAt | long | Unix timestamp when user was deactivated (0 if active) |
Next Steps
AI Agents Overview
Learn about AI agent capabilities and configuration
Send Message
Send text messages to AI agents to trigger runs
Receive Messages
Handle incoming messages including AI responses
Dashboard
Configure and manage AI agents in the CometChat Dashboard