Implement query-based agent activation

更新时间:
复制 MD 格式

You can activate an AI agent to directly answer the user's question instead of displaying a welcome message first.

Introduction

By default, an AI agent displays a welcome message when activated. In some scenarios, users may prefer the agent to respond to their question immediately without showing a welcome message. Query-based activation provides this capability.

Implementation

The following example uses the offline wake-up scenario.

Offline wake-up allows a device or system to be activated by a specific command without an Internet connection. Two methods are available:

  • Regular activation: The agent is activated by the wake word, such as "Tmall Genie" or "Siri."

  • Query-based activation: The agent recognizes the wake word along with a query, for example, "Tmall Genie, what's the weather like in Singapore today?" The question is passed as the initial command and the welcome message is disabled, so the agent responds immediately.

Prerequisites

Wake-up word recognition is implemented on the client side.

Procedure

  1. When the client side recognizes the wake word and a specific query, convert the query as the new wake word.

  2. Call StartAIAgentInstance.

    • Set WakeUpQuery in the AIAgentConfig parameter to the converted query.

    • Set Greeting in the AIAgentConfig parameter to an empty string to disable the welcome message.

Sample code

Android

//Create ARTCAICallConfig and configure ARTCAICallConfig.
ARTCAICallEngine.ARTCAICallConfig artcaiCallConfig = new ARTCAICallEngine.ARTCAICallConfig(); 
 
// Configure parameters of agentConfig.
artcaiCallConfig.agentConfig.wakeUpQuery = "What's the weather like today?";

// Continue with the rest of the call initiation process.

iOS

// Create an ARTCAICallAgentConfig object and set the wakeUpQuery parameter.
let agentConfig = ARTCAICallAgentConfig()
agentConfig.wakeUpQuery = "What's the weather like today?"

// If you use the integration solution with UI, set config.agentConfig when you initiate a call.
let controller = AUIAICallStandardController(userId: userId)
controller.config.agentConfig = agentConfig
...

// If you use the integration solution without UI, convert agentConfig into a JSON string and use it as a request parameter for calling StartAIAgentInstance or GenerateAIAgentCall.
let jsonString = agentConfig.getJsonString(agentType)
...

Web

// Create an AICallAgentConfig object and set the wakeUpQuery parameter.
const agentConfig = new AICallAgentConfig();
agentConfig.wakeUpQuery = 'What\'s the weather like today?';

// If you use the integration solution with UI, modify src/runConfig.ts.
const runConfig: AICallRunConfig = { 
  // ...
  callAgentConfig: agentConfig,
  // ...
};

// If you use the integration solution without UI, convert agentConfig into a JSON string and use it as a request parameter for calling StartAIAgentInstance or GenerateAIAgentCall.
const jsonString = agentConfig.getJsonString(agentType)
...