Skip to main content
Application Calling

Custom application parameter pass-through

Pass custom parameters, primarily to custom plugins and custom nodes, when calling Alibaba Cloud Model Studio's Agent Application and Workflow Application (which replace agent orchestration applications).

Obtain an API key and export the API key as an environment variable. If you use an SDK to make calls, install the DashScope SDK.

Custom plugin parameters

This article uses the dormitory convention query tool to demonstrate how to pass parameters to a custom plugin using an API.
Parameters for custom plugins are passed via an associated Agent Application or a Workflow Application's plugin node.
The following example shows how to pass custom plugin parameters for an Agent Application.

Usage

Step 1: Create a custom plugin

If you have already created a plugin tool or imported a plugin, skip this step.
  1. Create a custom plugin: Go to the Plugins page in the Model Studio console and click Add Custom Plug-in. Enter the plugin information. If authentication is required, turn on the Enable Authentication switch and configure the settings.
    Example Plugin Description: Queries dormitory conventions and looks up specific entries by numeric index.
    Example Plugin URL: https://domitorgreement-plugin-example-icohrkdjxy.cn-beijing.fcapp.run
    image
    Note: The Plug-in Description briefly summarizes the plugin's purpose. This helps the large model decide whether to call the plugin for a given task. Describe it in natural language.
  2. Create a tool: Fill in the tool information and configure the input and output parameters. Note:
    1. The Tool Description helps the large model better understand the tool's functions and use cases. Use natural language and provide examples if possible.
    2. A descriptive Parameter Name helps the large model understand the information it represents.
    3. The Parameter Description explains the function of the input parameter. It should be concise and accurate to help the large model determine the correct value to use.
    4. You must select Business Pass-through for the input parameter's Passing Method.
    In this example, the dormitory convention content index, article_index, is set as a passthrough parameter.
    image
  3. Click Test Tool. After the test passes, Publish the plugin.

Step 2: Associate a plugin with an agent

You can only associate plugins with Agent Application that are in the same workspace.
  1. On a published plugin's card, click Add to Agent and select an agent application.
  2. Alternatively, click + Plugin within an application to associate a custom plugin.
  3. Finally, Publish the application.

Step 3: API call

  • When authentication is not required: To call a custom plugin via an API, use the user_defined_params parameter of biz_params to pass the custom plugin information, replace your_plugin_code with the actual plugin ID, and pass the key-value pairs of the input parameters configured in the plugin.
    You can find the plugin ID on the plugin card.
    In this example, passing a value of 2 to the article_index parameter queries the content of the second dormitory convention and returns the correct result.
    • Python
    • Java
    • HTTP
    Sample request
    import os
    from http import HTTPStatus
    # We recommend using DashScope SDK v1.14.0 or later.
    import dashscope
    from dashscope import Application
    
    dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
    biz_params = {
        # Pass the input parameters for the agent application's custom plugin. Replace `your_plugin_code` with your plugin ID.
        "user_defined_params": {
            "your_plugin_code": {
                "article_index": 2}}}
    response = Application.call(
            # If the environment variable is not set, you can use your Model Studio API key by replacing the following line with api_key="sk-xxx". We recommend using an environment variable in production to avoid leaking your API key.
            api_key=os.getenv("DASHSCOPE_API_KEY"),
            app_id='YOUR_APP_ID',
            prompt='Dormitory convention content',
            biz_params=biz_params)
    
    if response.status_code != HTTPStatus.OK:
        print(f'request_id={response.request_id}')
        print(f'code={response.status_code}')
        print(f'message={response.message}')
        print(f'For more information, see: https://www.alibabacloud.com/help/en/model-studio/developer-reference/error-code')
    else:
        print('%s\n' % (response.output.text))  # Process and output only the text.
        # print('%s\n' % (response.usage))
    
    Sample response
    The second article of the dormitory convention is as follows:
    
    "Roommates must help, care for, and learn from each other to achieve mutual improvement. They must be tolerant, forgiving, respectful, and sincere."
    
    This suggests that roommates should foster a positive living and learning environment by supporting and helping each other, while also learning to understand and respect others. If you want to learn about other articles of the convention, just ask!
    
  • When authentication is required: This scenario describes how to call a custom plugin that has Authentication enabled and is configured with User-level Authentication.
    You can find the plugin ID on the plugin card.
    • Use user_defined_params in the biz_params field to pass custom plugin information. Replace your_plugin_code with your plugin ID, and provide the input parameters as key-value pairs.
    • Use user_defined_tokens in the biz_params field to pass authentication credentials. Replace your_plugin_code with your plugin ID, and set the user_token value to your authentication token, such as a DashScope API key.
    • After successful authentication, the service queries the specified item based on the provided index parameter and returns the correct result.
    In this example, the article_index parameter is set to 2, and the value of user_token, YOUR_TOKEN, is replaced with the actual DASHSCOPE_API_KEY. After authentication succeeds, the content of the second dormitory rule is queried, and the correct result is returned.
    • Python
    • Java
    • HTTP
    Request sample
    from http import HTTPStatus
    import os
    # We recommend using DashScope SDK v1.14.0 or later.
    import dashscope
    from dashscope import Application
    
    dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
    biz_params = {
        # Pass authentication credentials for the agent application's custom plugin.
        # Replace your_plugin_code with your plugin ID and YOUR_TOKEN with your authentication token, such as an API key.
        "user_defined_params": {
            "your_plugin_code": {
                "article_index": 2}},
        "user_defined_tokens": {
            "your_plugin_code": {
                "user_token": "YOUR_TOKEN"}}}
    response = Application.call(
                # If the environment variable is not configured, you can use a DashScope API key by replacing the next line with: api_key="sk-xxx".
                # However, we do not recommend hardcoding the API key in a production environment to reduce the risk of key leakage.
                api_key=os.getenv("DASHSCOPE_API_KEY"),
                app_id='YOUR_APP_ID',
                prompt='Dormitory convention content',
                biz_params=biz_params)
    
    if response.status_code != HTTPStatus.OK:
        print(f'request_id={response.request_id}')
        print(f'code={response.status_code}')
        print(f'message={response.message}')
        print(f'For more information, refer to: https://www.alibabacloud.com/help/en/model-studio/developer-reference/error-code')
    else:
        print('%s\n' % (response.output.text))  # Process and output only the text.
        # print('%s\n' % (response.usage))
    
    Response sample
    The second article of the dormitory convention is as follows:
    
    Roommates must help, care for, and learn from each other to achieve mutual improvement. They must be tolerant, forgiving, respectful, and sincere.
    
    If you need to know about other articles of the convention, please let me know.
    

Pass custom node parameters

This topic uses the Querying administrative divisions by city name example to demonstrate how to pass custom node parameters to an application through an API call.
Custom node parameters for an application are passed through the start node of a Workflow Application.
The following example shows how to pass custom parameters to the start node in a Workflow Application.

Usage

Step 1: Configure custom node parameters

Go to the My Applications page in the Model Studio console. Select a Workflow Application and define custom parameters for its start node. For this example, create a String variable named city. Then, insert the city and query variables into the prompt and Publish the application.

Step 2: Make an API call

When you make the API call, pass the city value in the biz_params field and the query value in the prompt field.
  • Python
  • Java
  • HTTP
sample request
import os
from http import HTTPStatus
import dashscope
from dashscope import Application
# Pass custom parameters for a workflow application.

dashscope.base_http_api_url = 'https://dashscope-intl.aliyuncs.com/api/v1'
biz_params = {"city": "Hangzhou"}
response = Application.call(
    # If you have not configured an environment variable, you can use your Model Studio API key by replacing the following line with: api_key="sk-xxx".
    # We recommend that you do not hardcode the API key in your code in a production environment to reduce the risk of API key leaks.
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    app_id='YOUR_APP_ID',  # Replace with your actual application ID.
    prompt='Query the administrative divisions of this city',
    biz_params=biz_params  # Pass business parameters.
)

if response.status_code != HTTPStatus.OK:
    print(f'request_id={response.request_id}')
    print(f'code={response.status_code}')
    print(f'message={response.message}')
    print(f'For more information, see: https://www.alibabacloud.com/help/en/model-studio/developer-reference/error-code')
else:
    print(f'{response.output.text}')  # Process and output only the text.
sample response
Hangzhou, the capital city of Zhejiang Province, is divided into 10 municipal districts: Shangcheng, Gongshu, Xihu, Binjiang, Xiaoshan, Yuhang, Linping, Qiantang, Fuyang, and Lin'an. Each district has its own unique features and development priorities.

- Shangcheng District: Located in the center of Hangzhou, it is one of the city's political, economic, and cultural hubs.
- Gongshu District: Known for its canal culture and numerous historical and cultural heritage sites.
- Xihu District: Home to the famous West Lake scenic area, a major tourist destination.
- Binjiang District: A hub for high-tech industries, where well-known companies such as Alibaba are located.
- Xiaoshan District: An administrative district in the southeast known for its rapid economic development, especially in manufacturing.
- Yuhang District: Has developed rapidly in recent years, especially in the internet economy. Alibaba's headquarters is also located here (Note: Alibaba's headquarters is actually in Binjiang District).
- Linping District: A newly established administrative district aimed at promoting comprehensive economic and social development in the area.
- Qiantang District: Also a result of recent administrative division adjustments, it emphasizes both innovative development and ecological protection.
- Fuyang District: Located to the southwest of Hangzhou, it is known for its rich natural landscapes and long history and culture.
- Lin'an District: Situated in the western part of Hangzhou, it is famous for its beautiful ecology and profound cultural heritage.

Note that specific urban planning may change over time. Refer to the latest official information.
Custom plugin: Learn how to create a custom plugin. Application invocation: Learn how to invoke applications and explore more use cases. Application invocation API: Reference the complete parameter list and invocation examples.