Pass business parameters to Model Studio or a self-developed model

更新时间:
复制 MD 格式

You can pass business parameters to Alibaba Cloud Model Studio or your self-developed large language model (LLM) to provide additional context for more accurate responses.

Feature introduction

Parameter passthrough lets you send custom business data, such as user context, environment tags, user IDs, or membership information, along with requests in a service call chain. This provides the LLM with additional context to maintain business logic, improve response accuracy, and enhance observability while ensuring data integrity.

Use cases

In AI agent applications, you can pass parameters to applications in Alibaba Cloud Model Studio or your self-developed model. For example, in a customer service scenario, passing the user's issue type, business segment, and inquiry history helps the LLM provide more accurate and relevant answers, improving support efficiency.

Example: In e-commerce support, passing a user's purchased product information allows the LLM to quickly resolve product usage or after-sales issues.

Implementation

Audio/video call agents

Pass to Model Studio

Client-side sample code

Android

// Create and configure an ARTCAICallConfig object.
ARTCAICallEngine.ARTCAICallConfig artcaiCallConfig = new ARTCAICallEngine.ARTCAICallConfig();
 
// Configure the bailianAppParams parameter of agentConfig. This is a JSON string.
artcaiCallConfig.agentConfig.llmConfig.bailianAppParams = "XXX";

// Omit the call initiation process.

iOS

// Configure the bailianAppParams parameter of agentConfig.
let agentConfig = ARTCAICallAgentConfig()         // Create an ARTCAICallAgentConfig object.
agentConfig.llmConfig.bailianAppParams = ["xxx", "xxxx"]
// Omit the call initiation process.
... 

Web

// Configure the aiAgentBailianAppParams parameter of agentConfig.
const agentConfig = new AICallAgentConfig(); // Create an ARTCAICallAgentConfig object.
agentConfig.llmConfig.bailianAppParams = {
  // Configure the bailianAppParams parameter.
};

// Omit the call initiation process.

Pass to a self-developed model

  • Server-side initiation: When you call the GenerateAIAgentCall or StartAIAgentInstance API, configure the userData parameter.

  • Client-side initiation: When you start the agent, set the userData property.

For more information about retrieving the custom userData after the agent starts, see LLM standard interface.

Client-side sample code
Android
ARTCAICallEngine.ARTCAICallConfig artcaiCallConfig = new ARTCAICallEngine.ARTCAICallConfig();  // Create an ARTCAICallConfig object. For more information, see the user guide. 
artcaiCallConfig.userData = "{\"xxx\": \"xxx\"}"  // Set business parameters for the model.
...                                               // Set other parameters as needed.
    
engine.init(artcaiCallConfig);                    // Initialize the engine.
engine.call(token);                               // Initiate a call.
iOS
let callConfig = ARTCAICallConfig()        // Create an ARTCAICallConfig object. For more information, see the user guide.
callConfig.userData = ["xxx": "xxxx"]      // Set business parameters for the model.
...                                        // Set other parameters as needed.
    
self.engine.call(config: callConfig)       // Initiate a call.
Web
const callConfig = {
  // Create an AICallConfig object. For more information, see the user guide.
};

callConfig.userData = JSON.stringify({xxx: 'xxx'})

 // Initiate a call.
engine.callWithConfig(callConfig);

Chatbot agents

Pass to Model Studio

  1. Before you call the APIs provided by the AICallKit SDK to configure business parameters, ensure that the AICallKit SDK library is correctly imported.

  2. ARTCAIChatTemplateConfig is a class used to create a template configuration for messaging conversations. The bailianParam parameter is a JSON string that contains the business parameters to pass to Alibaba Cloud Model Studio.

  3. ARTCAIChatEngine is the engine class for managing messaging conversations. Use the setTemplateConfig method to apply the configured templateConfig to the engine. This ensures that the business parameters are passed during subsequent interactions with Alibaba Cloud Model Studio.

Sample code
Android
// Parameters for the Alibaba Cloud Model Studio application center. This is a JSON string.
String bailianParam = "XXX";
// Create the TemplateConfig parameter for the messaging conversation.
ARTCAIChatEngine.ARTCAIChatTemplateConfig templateConfig= new ARTCAIChatEngine.ARTCAIChatTemplateConfig(bailianParam, "");
// Set the configuration parameters for the messaging conversation. mChatEngine is an ARTCAIChatEngine object.               
mChatEngine.setTemplateConfig(templateConfig);
iOS
// Create the TemplateConfig parameter for the messaging conversation.
let templateConfig = ARTCAIChatTemplateConfig()
// Set parameters for the Alibaba Cloud Model Studio application center.
templateConfig.bailianAppParams = ["xxx":"xxxxx"]

// Set templateConfig for the messaging conversation engine.              
self.engine.templateConfig = templateConfig
Web
const engine = new AIChatEngine();

// Create the TemplateConfig parameter for the messaging conversation.
const templateConfig = new AIChatTemplateConfig();
// Set parameters for the Alibaba Cloud Model Studio application center.
templateConfig.bailianAppParams = {
  xxx: 'xxxxx',
};

// Set templateConfig for the messaging conversation engine.
engine.templateConfig = templateConfig;

Pass to a self-developed large model

  1. To pass business parameters to a self-developed large model, call the setUserData method of the AICallKit SDK. Before you call this method, ensure that the SDK library is correctly imported.

  2. The userData parameter is a JSON string that contains the business parameters to pass to a self-developed model.

  3. Use the mChatEngine.setUserData() method to set the business parameters in the engine.

Sample code
Android
// Custom business parameters (as a JSON string).
String userData = "XXX";
// Set the parameters on the engine (mChatEngine).
mChatEngine.setUserData(userData);
iOS
// Custom business parameters.
let userData = ["xxx":"xxxxx"]

// Set the userData on the chat engine.      
self.engine.userData = userData
Web
// Custom business parameters.
const userData = { xxx: 'xxxxx' };

// Set the userData on the chat engine.
engine.userData = userData;

Model Studio parameter details

Parameter

Type

Description

Example

biz_params

Object

The custom parameters passed to a workflow application or agent orchestration application. For details, see Application parameter pass-through

Note
  • Alibaba Cloud passes the following agent-related parameters. You do not need to configure them.

    • instanceId: the ID of the agent instance.

    • channelId: the ID of the RTC channel.

  • When passing parameters to an Alibaba Cloud Model Studio plugin, use user_defined_params. This parameter is not required for Model Studio workflows.

  • Alibaba Cloud Model Studio plugin

{
 "user_defined_params": {
 "city":"Hangzhou"
 }
}
  • Alibaba Cloud Model Studio workflow

{
 "city":"Hangzhou"
}

memory_id

String

A unique identifier for long-term memory, used to preserve and recall historical information.

YOUR_MEMORY_ID

image_list

Array

The URLs of images that provide visual context for the current operation.

["https://example.com/images/example.jpg"]

rag_options

Object

Retrieval-Augmented Generation (RAG) parameters. These include but are not limited to retrieving specified knowledge bases or documents.

  • pipeline_ids

Array

The knowledge base ID. When specified, all documents in the knowledge base are retrieved.

["KnowledgeBaseID1", "KnowledgeBaseID2"]

  • file_ids

Array

The ID of the unstructured document to process.

["DocumentID1", "DocumentID2"]

  • metadata_filter

Object

The metadata of unstructured documents. When specified, documents containing the specified metadata are retrieved.

{

"name": "Zhang San"

}

  • structured_filter

Object

The column names and values used to filter structured documents.

{

"key1": "value1",

"key2": "value2"

}

  • tags

Array

The tags of unstructured documents. When specified, documents with matching tags are retrieved.

["Tag1", "Tag2"]

For more information, see Workflow and Legacy Agent Application API. Examples:

Pass to an Alibaba Cloud Model Studio plugin
aliyunBailianParamsJson = {
    "biz_params": {
        "user_defined_params": 
        {
            "your_plugin_id":
            {
                "article_index": 2
            }
        }
    },
    "memory_id": "your_memory_id",
    "image_list": [
        "https://your_image_url"  # Example image URL
    ],
    "rag_options": {
        "pipeline_ids": [
            "your_id",  # Replace with the actual knowledge base ID
        ],
        "file_ids": [
            "DocumentID1",  # Replace with the actual document ID
            "DocumentID2"   # Replace with the actual document ID
        ],
        "metadata_filter": {
            "name": "John Doe"  # Replace with the required metadata filter condition
        },
        "structured_filter": {
            "key1": "value1",  # Example filter condition
            "key2": "value2"   # Example filter condition
        },
        "tags": [
            "Tag1",  # Replace with actual tags
            "Tag2"   # Replace with actual tags
        ]
    }
}
bailianParams = json.dumps(aliyunBailianParamsJson)
Pass to an Alibaba Cloud Model Studio workflow

aliyunBailianParamsJson = {
    "biz_params": {
        "key1": "value1"
    },
    "memory_id": "your_memory_id",
    "image_list": [
        "https://your_image_url"  # Example image URL
    ],
    "rag_options": {
        "pipeline_ids": [
            "your_id",  # Replace with the actual knowledge base ID
        ],
        "file_ids": [
            "DocumentID1",  # Replace with the actual document ID
            "DocumentID2"  # Replace with the actual document ID
        ],
        "metadata_filter": {
            "name": "John Doe"  # Replace with the required metadata filter condition
        },
        "structured_filter": {
            "key1": "value1",  # Example filter condition
            "key2": "value2"  # Example filter condition
        },
        "tags": [
            "Tag1",  # Replace with actual tags
            "Tag2"  # Replace with actual tags
        ]
    }
}
bailianParams = json.dumps(aliyunBailianParamsJson)