Skip to main content

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​

ModelPropertiesDescription
TSAIQuestionAnswerConfigagentId, audioRouteConfigurationOptional AI agent and the device-voice audio route
TSAIQuestionAnswerPartialResulttaskId, questionIdClient and provider question identifiers
TSAIQuestionAnswerPartialResultdeltaText, fullText, isFinalDelta and cumulative answer text
TSAIQuestionAnswerResulttaskId, questionId, answerTextFinal answer

Use [TSAIQuestionAnswerConfig defaultConfig] for default configuration.

Callback types​

CallbackThread and semantics
TSAIQuestionAnswerStartBlockMain-thread notification when answering starts
TSAIQuestionAnswerPartialBlockZero or more main-thread cumulative updates
TSAIQuestionAnswerCompletionBlockExactly 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​

  1. Question text must not be empty.
  2. Completion is the authoritative terminal signal.
  3. Append deltaText, or assign fullText directly to UI.
  4. Cancel unfinished tasks when leaving a screen and ignore updates for stale task IDs.