AI Question Answering (TSAIQuestionAnswerInterface)
Question Answering is a provider-neutral, single-turn text-in/streaming-text-out task. It is independent from assistant summary and multi-round voice chat.
Prerequisites
TSAIContext *context = [TSAIKit sharedInstance].activeContext;
if (![context supportsAIFeatures:TSAIFeatureQuestionAnswering]) {
return;
}
id<TSAIQuestionAnswerInterface> questionAnswer = context.questionAnswer;
Data models
| Model | Properties | Description |
|---|---|---|
TSAIQuestionAnswerConfig | agentId, audioRouteConfiguration | Optional AI agent and the device-voice audio route |
TSAIQuestionAnswerPartialResult | taskId, questionId | Client and provider question identifiers |
TSAIQuestionAnswerPartialResult | deltaText, fullText, isFinal | Delta and cumulative answer text |
TSAIQuestionAnswerResult | taskId, questionId, answerText | Final answer |
Use [TSAIQuestionAnswerConfig defaultConfig] for default configuration.
Callback types
| Callback | Thread and semantics |
|---|---|
TSAIQuestionAnswerStartBlock | Main-thread notification when answering starts |
TSAIQuestionAnswerPartialBlock | Zero or more main-thread cumulative updates |
TSAIQuestionAnswerCompletionBlock | Exactly one main-thread terminal callback |
Ask a question
- (NSString *)askQuestion:(NSString *)question
config:(TSAIQuestionAnswerConfig *)config
onStartAnswering:(nullable TSAIQuestionAnswerStartBlock)onStartAnswering
onPartialResult:(nullable TSAIQuestionAnswerPartialBlock)onPartialResult
completion:(nullable TSAIQuestionAnswerCompletionBlock)completion;
TSAIQuestionAnswerConfig *config = [TSAIQuestionAnswerConfig defaultConfig];
config.agentId = @"health-assistant";
NSString *taskId = [questionAnswer askQuestion:@"How can I improve my sleep?"
config:config
onStartAnswering:^(NSString *taskId, NSString *questionId) {
TSLog(@"Answer started: %@", questionId);
}
onPartialResult:^(TSAIQuestionAnswerPartialResult *partial) {
TSLog(@"Answer: %@", partial.fullText);
}
completion:^(TSAIQuestionAnswerResult *result, NSError *error) {
if (error) {
TSLog(@"Question failed: %@", error.localizedDescription);
return;
}
TSLog(@"Final answer: %@", result.answerText);
}];
Cancel a question
- (void)cancelQuestionAnswerWithTaskId:(NSString *)taskId;
The current AIBuds service has no physical server-side cancellation. Local logical cancellation completes with an error and drops late callbacks, although server work may continue.
[questionAnswer cancelQuestionAnswerWithTaskId:taskId];
Device-initiated question answering
- (NSString *)startDeviceQuestionAnswerWithConfig:(TSAIQuestionAnswerConfig *)config
completion:(nullable TSAICompletionBlock)completion;
- (void)stopDeviceQuestionAnswerWithTaskId:(NSString *)taskId;
This entry arms one device-voice session and returns a stable task ID. Only this device entry consumes audioRouteConfiguration; text-only askQuestion:config: never activates an audio route. See Device-Initiated AI for orchestration and output sinks.
Important notes
- Question text must not be empty.
- Completion is the authoritative terminal signal.
- Append
deltaText, or assignfullTextdirectly to UI. - Cancel unfinished tasks when leaving a screen and ignore updates for stale task IDs.