Android toolkit API
The Android toolkit API for Conversational AI Engine provides the following classes and methods.
IConversationalAIAPI class
API | Description |
---|---|
addHandler | Registers an event handler to receive agent session events. |
removeHandler | Removes a registered event handler. |
subscribeMessage | Subscribes to a channel to receive agent conversation events. |
unsubscribeMessage | Unsubscribes from the channel and stops receiving events. |
interrupt | Interrupts the agent’s speech. |
loadAudioSettings | Sets audio parameters to optimize agent conversation performance. |
destroy | Destroys the API instance and releases resources. |
addHandler
Registers an event handler to receive agent session events.
Parameter | Type | Description |
---|---|---|
handler | IConversationalAIAPIEventHandler | Event handler instance. See IConversationalAIAPIEventHandler . |
removeHandler
Removes a registered event handler.
Parameter | Type | Description |
---|---|---|
handler | IConversationalAIAPIEventHandler | Event handler instance. See IConversationalAIAPIEventHandler . |
subscribeMessage
Subscribes to a channel to receive agent conversation events.
Parameter | Type | Description |
---|---|---|
channelName | String | Channel name. |
completion | (error: ConversationalAIAPIError?) -> Unit | Callback. error is null on success, or non-null if the call fails. See ConversationalAIAPIError . |
unsubscribeMessage
Unsubscribes from the channel and stops receiving events.
Parameter | Type | Description |
---|---|---|
channelName | String | Channel name. |
completion | (error: ConversationalAIAPIError?) -> Unit | Callback for unsubscription result. error is null if successful, or non-null if failed. See ConversationalAIAPIError . |
interrupt
Interrupts the agent’s speech.
Parameter | Type | Description |
---|---|---|
agentUserId | String | Agent user ID. |
completion | (error: ConversationalAIAPIError?) -> Unit | Callback. error is null on success or contains error info if the call fails. See ConversationalAIAPIError . |
loadAudioSettings
Sets audio parameters to optimize the agent’s conversation performance.
You must call this method before each joinChannel
call to ensure optimal audio quality.
Parameter | Type | Description |
---|---|---|
scenario | Int | Audio scene. Default is AUDIO_SCENARIO_AI_CLIENT . Optimized for intelligent agent dialogs. |
destroy
Destroys the API instance and releases resources.
Call this method when the instance is no longer needed. After calling, the instance becomes unusable.
IConversationalAIAPIEventHandler class
API | Description |
---|---|
onAgentStateChanged | Called when the agent’s status changes. |
onAgentInterrupted | Called when an interrupt event occurs. |
onAgentMetrics | Called when performance metrics are available. |
onAgentError | Called when an agent error occurs. |
onTranscriptionUpdated | Called when transcription content is updated. |
onDebugLog | Called for internal debug logging. |
onAgentStateChanged
Triggered when the agent’s state changes.
Parameter | Type | Description |
---|---|---|
agentUserId | String | Agent user ID. |
event | StateChangeEvent | State change event. See StateChangeEvent . |
onAgentInterrupted
Triggered when an interrupt event occurs.
Parameter | Type | Description |
---|---|---|
agentUserId | String | Agent user ID. |
event | InterruptEvent | Interrupt event. See InterruptEvent . |
onAgentMetrics
Triggered when performance metrics are available.
Parameter | Type | Description |
---|---|---|
agentUserId | String | Agent user ID. |
metric | Metric | Performance metric. See Metric . |
onAgentError
Triggered when an agent error occurs.
Parameter | Type | Description |
---|---|---|
agentUserId | String | Agent user ID. |
error | ModuleError | Error details. See ModuleError . |
onTranscriptionUpdated
Triggered when the transcription content is updated.
This callback may trigger frequently. If deduplication is needed, handle it in your business logic.
Parameter | Type | Description |
---|---|---|
agentUserId | String | Agent user ID. |
transcription | Transcription | Transcription data. See Transcription . |
onDebugLog
Triggered for internal debug logs.
Parameter | Type | Description |
---|---|---|
log | String | Debug log information. |
Structures
StateChangeEvent
Represents an agent state change event.
Tracks session flow and updates status indications in the UI, including the event timestamp.
Parameter | Type | Description |
---|---|---|
state | AgentState | Current agent status: silent , listening , thinking , speaking . See AgentState . |
turnId | Long | Conversation turn ID. |
timestamp | Long | Timestamp in milliseconds since Unix epoch (January 1, 1970 UTC). |
InterruptEvent
Indicates an interrupt event.
Triggered when the user or system interrupts the agent. Used for logging and handling.
Parameter | Type | Description |
---|---|---|
turnId | Long | ID of the interrupted conversation turn. |
timestamp | Long | Timestamp in milliseconds since Unix epoch (January 1, 1970 UTC). |
Metric
Used to define system performance indicator data.
Parameter | Type | Description |
---|---|---|
type | ModuleType | Type of indicator. See ModuleType . |
name | String | Descriptive name of the metric. |
value | Double | Metric value (e.g., latency in ms). |
timestamp | Long | Timestamp when metric was recorded in milliseconds since Unix epoch (January 1, 1970 UTC). |
ModuleError
Processes and reports agent-related error information.
Parameter | Type | Description |
---|---|---|
type | ModuleType | Error type (e.g., LLM failure, TTS exception). See ModuleType . |
code | Int | Specific error code. |
message | String | Description of the error. |
timestamp | Long | Timestamp of the error in milliseconds since Unix epoch (January 1, 1970 UTC). |
Transcription
Represents a full transcribed message used to render the UI.
Parameter | Type | Description |
---|---|---|
turnId | Long | Session turn identifier. |
userId | String | User ID linked to the transcript. |
text | String | Transcribed message content. |
status | TranscriptionStatus | Current status of transcription. See TranscriptionStatus . |
type | TranscriptionType | Transcript type (e.g., AGENT , USER ). See TranscriptionType . |
ConversationalAIAPIConfig
Holds configuration parameters for initializing the Conversational AI API.
Parameter | Type | Description |
---|---|---|
rtcEngine | RtcEngine | Audio/video engine instance. See RtcEngine . |
rtmClient | RtmClient | Real-time messaging client. See RtmClient . |
renderMode | TranscriptionRenderMode | Transcription rendering style. Default: word-by-word. See TranscriptionRenderMode . |
enableLog | Boolean | Enables logging if true . Default is false . |
ConversationalAIAPIError
Represents an error type in the Conversational AI API.
Property | Type | Description |
---|---|---|
errorCode | Int | RtmError /RtcError : specific code; UnknownError : returns -100 . |
errorMessage | String | Human-readable description of the error. |
Enum classes
Priority
Controls the priority with which the agent handles incoming messages during an interaction.
Value | Description |
---|---|
INTERRUPT | High priority: Immediately interrupt the current interaction and process the message. Suitable for urgent or time-sensitive content. |
APPEND | Medium priority: The message is queued for processing after the current interaction is completed and is suitable for subsequent questions. |
IGNORE | Low priority: This message is only processed when the agent is idle, and will be discarded during ongoing interactions. Suitable for optional content. |
AgentState
Represents the current state of the agent.
Value | Description |
---|---|
SILENT | Agent is silent. |
LISTENING | Agent is listening. |
THINKING | Agent is processing. |
SPEAKING | Agent is speaking. |
UNKNOWN | Unknown state. |
ModuleType
Performance module type enumeration.
Value | Description |
---|---|
LLM | LLM inference latency measurement. |
MLLM | MLLM inference latency measurement. |
TTS | Text-to-speech synthesis latency measurement. |
UNKNOWN | Unknown type. |
MessageType
Used to distinguish different types of messages in the system.
Value | Description |
---|---|
ASSISTANT | AI assistant message. |
USER | User message. |
ERROR | Error message. |
METRICS | Performance metrics message. |
INTERRUPT | Interrupt message. |
UNKNOWN | Unknown message type. |
TranscriptionRenderMode
Transcript rendering mode.
Value | Description |
---|---|
Word | Word-by-word transcription and rendering. |
Text | Full text transcription and rendering. |
TranscriptionType
Transcription source type.
Value | Description |
---|---|
AGENT | Agent transcription. |
USER | User transcription. |
TranscriptionStatus
Indicates the current status of the transcription.
Value | Description |
---|---|
IN_PROGRESS | The transcription is still being generated or the speech is still in progress. |
END | The transcription completed normally. |
INTERRUPTED | Transcription was interrupted before completion. |
UNKNOWN | Unknown status. |