Feedback

Cascade

Feature Overview

This guide outlines the fastest integration workflow for the three-stage Cascade mode (ASR → LLM → TTS), enabling a complete voice conversation in just five steps:
Issue UserSig → Integrate SDK on Client and Join Room → Create AI Conversation Task on Server → Listen for Event Webhook → End Task
Once the task is created, the AI Bot joins the TRTC room as a virtual user and subscribes to the designated user's audio stream. As soon as the user begins speaking, a real-time Recognition → Reasoning → Playback conversation starts, which can be interrupted at any moment.

Prerequisites and Quotas

Item
Requirement
TRTC Service
Service activated and real-name verification completed.
SdkAppId
TRTC Application ID, required for all server-side API calls.
Room ID
Supports both numeric (RoomIdType=0) and string (RoomIdType=1, recommended) room IDs.
API Rate Limit
20 requests/second.
Concurrent Tasks per App
Maximum 100 tasks.
Idle Timeout
Default 30 seconds (AgentConfig.MaxIdleTime configurable, range: 5–86400 seconds).
Note:
If you exceed the rate or concurrency limits, the API returns FailedOperation.RestrictedConcurrency or FailedOperation.RequestLimitExceeded. Implement exponential backoff for retries.

Integration Steps

Step 1: Issue UserSig

Your backend must issue a UserSig for both the App user and the AI Bot:
Bot's UserSig: Set as AgentConfig.UserSig when creating the task; managed by your backend.
App user's UserSig: Generated by the backend and provided to the client for room entry.
For details on generating UserSig, refer to TRTC UserSig Generation.

Step 2: Client Integration with TRTC SDK and Room Entry

For the TRTC SDK quick integration guide, after integrating the SDK, the client only needs the following calls (using Android as an example):
Note:
To use Conversational AI, the client must download a specific version of the SDK (iOS, Android)
1. Create a TRTC instance:
TRTCCloud trtc = TRTCCloud.sharedInstance(context.getApplicationContext());
2. Start audio capture. Be sure to call setSystemVolumeType before startLocalAudio to join the room with speech quality:
trtc.getDeviceManager().setSystemVolumeType(
TXDeviceManager.TXSystemVolumeType.TXSystemVolumeTypeMedia);
trtc.startLocalAudio(TRTCCloudDef.TRTC_AUDIO_QUALITY_SPEECH);
3. Modify the following members of the TRTCParams struct:
TRTCCloudDef.TRTCParams trtcParams = new TRTCCloudDef.TRTCParams();
trtcParams.sdkAppId = 1400000123; // Obtain after creating an application in the console
trtcParams.userId = "denny"; // User ID
trtcParams.userSig = "xxx"; // Generated by the backend and delivered to the client
trtcParams.strRoomId = "123abc"; // String room ID
4. Call enterRoom with trtcParams to enter the room:
trtc.enterRoom(trtcParams, TRTCCloudDef.TRTC_APP_SCENE_VIDEOCALL);
Room entry is successful when: TRTCCloudListener.onEnterRoom returns a result greater than 0.

Step 3: Create AI Conversation Task on Server

The backend invokes the Create Task API (for the full definition, see Create AI Conversation Task) to start a Cascade mode task:
{
"SdkAppId": 14000000,
"RoomId": "12345",
"RoomIdType": 0,
"ConversationMode": "Cascade",
"AgentConfig": {
"UserId": "test2",
"UserSig": "eJyrVgrxCdYrzkxXslJQyvEs...",
"TargetUserId": ["Trtc_User_0"],
"MaxIdleTime": 60,
"SubtitleMode": 0,
"TurnDetectionMode": "Auto",
"TTSPushRoomParams": { "UserId": "tts-bot-001" }
},
"STTConfig": {
"Provider": "trtc",
"Params": "{\"engine_model_type\":\"bigmodel\",\"language\":\"en\",\"vad_silence_time\":\"1000\"}"
},
"LLMConfig": {
"LLMType": "openai",
"Model": "gpt-4o-mini",
"APIKey": "<YOUR_API_KEY>",
"APIUrl": "https://api.openai.com/v1/chat/completions",
"SystemPrompt": "You are a concise conversation assistant.",
"Timeout": 20000,
"Temperature": 0.7
},
"TTSConfig": {
"Provider": "trtc",
"Params": "{\"model\":\"flow_02_turbo\",\"voice_id\":\"v-female-R2s4N9qJ\",\"speed\":1.0,\"volume\":1.0,\"pitch\":0}"
}
,
"DialogConfig": {
"InterruptMode": 0,
"InterruptSpeechDuration": 200,
"WelcomeMessage": "Hello, I am an AI assistant. How can I help you?"
}
}
Key Field Overview:
Field
Description
AgentConfig.UserId / UserSig
AI Bot's room identity and credentials for joining.
AgentConfig.TargetUserId
The user(s) whose audio stream the Bot subscribes to (currently supports one).
AgentConfig.MaxIdleTime
Idle timeout, task ends if no one speaks within this period.
STTConfig / LLMConfig / TTSConfig
Configuration for ASR, LLM, and TTS. Providers are interchangeable.
DialogConfig.WelcomeMessage
Welcome message played by the Bot after joining (used for link verification).
DialogConfig.InterruptMode
Interrupt mode: 0=Auto, 1=Manual, 2=Keyword.
A successful response with TaskId confirms the task is created, the Bot has joined the room, and subscribed to the target user's audio. If WelcomeMessage is set, the Bot automatically plays it on entry, allowing you to test the TTS pipeline immediately. Speak to the Bot to begin a full conversation cycle.
Note:
For detailed configuration options (supported providers, parameter conventions, hot updates), see ASR Configuration, LLM Configuration, and TTS Configuration.
TTSPushRoomParams.UserId specifies a unique user ID for the TTS playback stream. When omitted, playback defaults to AgentConfig.UserId. Using a separate ID helps distinguish between the Bot's main logic identity and its playback identity on the client side.

Step 4: Configure Event Webhook and Verify Signature

In the console (or via support request), configure your backend callback URL and callback SecretKey, then implement Sign verification. This allows you to persist ASR/LLM results, monitor AI state changes, and manage task start/end events.
For details on payload structure, event types, and signature verification, see AI Conversation Event Webhook.

Step 5: End Task

When the host leaves or the conversation concludes, your backend invokes the Delete Task API, prompting the Bot to exit the room and release resources.
Note:
You may also rely on idle timeout: if no valid audio is detected for MaxIdleTime, the task will automatically terminate.

Verifying the Conversation Pipeline

To confirm the pipeline is working, speak to the Bot and verify results using these three channels:
Verification Channel
Phenomenon
Reference
Client Audio Experience
Bot plays the welcome message automatically, then responds smoothly; you can interrupt while speaking.
Client Subtitles
Receive ASR-generated subtitles for user speech and LLM-generated subtitles for Bot replies.
Server Event Webhook
Receive ASR recognition results, LLM reply results, and AI state transition events in sequence.
During each conversation round, the Bot transitions through these states (see Get AI Bot Status and Context for full details):