• 製品
  • 料金
  • リソース
  • サポート
このページは現在英語版のみで提供されており、日本語版も近日中に提供される予定です。ご利用いただきありがとうございます。

AI ボットのステータスとコンテキストを取得

Feature Overview

During task execution, the backend can access the AI chatbot's status and conversation data through two main methods:
Acquisition Method
Channel
Available Data
Real-Time
Query API (Active Pull)
The Query Task API, one of five standard task lifecycle operations.
Task running status, conversation context history.
On-demand query, returns a snapshot at the time of request.
Server Callback (Passive Push)
AI status transition callback.
Real-time updates on the chatbot's conversation status.
Real-time push, no polling latency.
Note:
The client SDK also provides a corresponding channel for status acquisition (status events), using the same status code definitions as the server callback. For client integration details, see Client: Receiving AI Chatbot Status.

Obtaining Data via Query API

The Query Task API provides two types of queries, controlled by the DescribeType parameter:
DescribeType
Query Content
Returned Fields
0 (default)
Task running status
Status / StartTime
1
Conversation context history
HistoryContents (list of user-AI conversation history)

Query Task Running Status (DescribeType = 0)

Input Parameters:
Parameter
Required
Type
Description
SdkAppId
Yes
Integer
TRTC Application ID.
TaskId
Yes
String
Task ID.
DescribeType
No
Integer
0: Query task status (default).
Output Parameters:
Parameter
Type
Description
Status
String
Task status. See the status table below.
StartTime
Integer
Task start time (UTC milliseconds).
RequestId
String
Request ID.
Task Status (Status) Values:
Status
Meaning
InProgress
Task is running.
Idle
Idle (after task creation, before the task officially starts).
Exited
Exited (task has ended).
Request Example:
{
"SdkAppId": 1400704311,
"TaskId": "-m9jX35U7sY4p8GEKc0d4EnvzOlwCUTb...",
"DescribeType": 0
}
Response Example:
{
"Response": {
"Status": "InProgress",
"StartTime": 1751196050000,
"TaskId": "-m9jX35U7sY4p8GEKc0d4EnvzOlwCUTb...",
"RequestId": "req-xxx"
}
}

Query Conversation Context History (DescribeType = 1)

Returns the conversation history between the user and AI for the current task. This is useful for scenarios such as customer service QA, audit logging, and restoring context after a user reconnects.
Output Parameters:
Parameter
Type
Description
HistoryContents
Array of Object
Conversation history list. Each item includes Role (user=User / assistant=AI) and Content (dialogue text).
Status
String
Task status.
StartTime
Integer
Task start time (UTC milliseconds).
Request Example:
{
"SdkAppId": 1400704311,
"TaskId": "-m9jX35U7sY4p8GEKc0d4EnvzOlwCUTb...",
"DescribeType": 1
}
Response Example:
{
"Response": {
"StartTime": 1790542649581,
"Status": "InProgress",
"TaskId": "-nE5D7FU7k85T+dH1Mf-xdCO5s+...",
"HistoryContents": [
{"Role": "user", "Content": "What's the weather today? Please check Beijing's temperature."},
{"Role": "assistant", "Content": "I can't retrieve real-time weather. Please use a weather app to check Beijing's temperature."},
{"Role": "user", "Content": "Please read the following phrase verbatim: Priority Insert"},
{"Role": "assistant", "Content": "Priority Insert"},
{"Role": "user", "Content": "What's the weather today? Please check Beijing's temperature."},
{"Role": "assistant", "Content": "Unable to retrieve real-time weather. Please use a weather app to check Beijing's temperature."}
],
"RequestId": "req-xxx"
}
}
Note:
S2S (End-to-End) mode does not support conversation history queries. When DescribeType=1, the result will be empty.

Obtaining Chatbot Status via Server Callback

AI Status Transition Callback

During task execution, each time the chatbot's conversation status changes, the TRTC backend pushes an AI status transition event to your business callback URL in real time. This removes the need for backend polling.
Key Fields in Callback Payload:
Field
Type
Description
State.Code
Integer
Chatbot conversation status code. See the table below.
State.Desc
String
Status description.
Timestamp
Integer
Status transition timestamp (milliseconds).
Callback Example (EventInfo.Payload section):
{
"Payload": {
"State": { "Code": 2, "Desc": "AI Thinking (LLM Reasoning)" },
"Timestamp": 1751196060800
}
}
Note:
For the full callback message structure (event groups, event type enums, callback URL configuration, and Sign signature verification), see AI Conversation Callback Events.

Chatbot Conversation Status Codes (State.Code)

State.Code represents the chatbot's real-time status within a single conversation turn. The client SDK's status events and server status transition callbacks use the same definitions:
State.Code
Meaning
Corresponding Stage
0
AI Idle
Waiting for user input.
1
AI Listening
ASR Recognition (user speaking), start of a conversation turn.
2
AI Thinking
LLM Reasoning.
3
AI Speaking
TTS Playback.
4
AI Interrupted
Turn was terminated early.
5
AI Finished Speaking
Turn ended normally.
Typical Conversation Turn Status Flow:



Normal flow: User speaks (1) → LLM reasoning (2) → TTS playback (3) → Playback complete (5) → Returns to idle (0) to await the next turn.
Interrupt flow: During playback (3), if interrupted by the user or an interrupt command, transitions directly to interrupted (4) → Returns to idle (0). For details on interrupt triggers, see Client: Interrupt Command.

Distinguishing Between Task Status and Conversation Status

The Status (task status) returned by the query API and the State.Code (conversation status) pushed via callback represent two distinct status levels. See the comparison below:
Comparison Item
Task Status (Status)
Conversation Status (State.Code)
Description Level
Task lifecycle.
Single conversation turn lifecycle.
Acquisition Method
Query API (DescribeType=0) / Task end callback.
AI status transition callback / Client status event.
Type & Values
String:
InProgress Running;
Idle Idle;
Exited Exited.|Integer:
String:
0 Idle;
1 Listening;
2 Thinking;
3 Speaking;
4 Interrupted;
5 Finished Speaking.|AI status transition callback / Client status event.
Typical Use Cases
Task-level monitoring, liveness checks, fault alerts.
Conversation process display, interruption detection, turn statistics.
Note:
Task-level status changes (start, end, and exit reasons) are pushed via task start/end callbacks. For details, see AI Conversation Callback Events.

Typical Application Scenarios

Scenario
Implementation
Description
Conversation QA & Audit
Query API DescribeType=1
Retrieve the complete conversation context after a session ends for QA, auditing, and compliance logging.
Task Monitoring & Alerts
Query API DescribeType=0 polling / task end callback
Trigger alerts promptly when a task Exited, and use exit codes to identify abnormal exits.
Real-Time Status Dashboard
Subscribe to AI status transition callback
Drive real-time display of chatbot status (Listening / Thinking / Speaking) via callback, with no polling required.
Turn Statistics Analysis
Aggregate status transition callbacks
Count turns based on complete 1→5 transitions, and calculate interruption rate based on 4.
Context Restoration After Reconnection
Query API DescribeType=1
When a user reconnects or switches devices, retrieve conversation history to restore context and continue the service.

Notes

1. S2S mode does not support conversation history queries: In end-to-end mode, DescribeType=1 returns empty. To log conversation records, use the subtitle callback or status callback.
2. Query returns a snapshot: The query API provides the status at the time of the request. To monitor real-time status changes, subscribe to status transition callbacks. Avoid using polling, as it introduces latency and consumes your API QPS quota.
3. Callback signature verification is mandatory: When receiving a callback, the backend must verify the Sign to prevent forgery. For configuration details, see AI Conversation Callback Events.
4. Task exit troubleshooting: When Status is Exited, use the exit code from the task end callback and ASR/LLM callbacks to determine the exit reason (differentiate between normal completion and abnormal failure).
5. Status callbacks may be duplicated: Due to network retransmissions, callbacks may be sent multiple times. Ensure your backend implements idempotency using the combination of TaskId and Timestamp.