Skip to main content

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).

You must first obtain and configure an API key and configure the API key as an environment variable. If you call through an SDK, you must also install the DashScope SDK.

Custom plugin parameter pass-through

This article uses the dormitory convention content query tool as an example to show you how to call the custom plugin parameter pass-through feature of an application through an API.
Parameters for custom plugins are passed through an associated Agent Application or a plugin node in a Workflow Application.
The following example shows how to pass custom plugin parameters in an Agent Application.

Usage

Step 1: Create a custom plugin tool

If you have already created a plugin tool or imported a plugin, skip this step.
  1. Create Custom Plug-in: In the left-side navigation pane, select Tool > Plug-in Management to go to the Plug-in Management page. Click Create Plug-in and fill in the plug-in information. If authentication is required, turn on the Enable Authentication switch and fill in the authentication configuration information.
    Example plugin description: Dormitory convention query tool, which can query a specific entry based on the entered numeric index.
    Example plugin URL: https://domitorgreement-plugin-example-icohrkdjxy.cn-beijing.fcapp.run
    Example authentication configuration: select User-level Authentication as the authentication type, Header as the location, and basic as Type. Note: The plugin description briefly explains the purpose of the plugin. It helps the large model determine whether the current task requires calling the current plugin. 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. Describe it in natural language and provide usage examples where possible.
    2. A parameter name should be as meaningful as possible to help the large model understand what the parameter information to be identified is.
    3. A parameter description describes the function of the input parameter. Keep it concise and accurate to help the large model further understand how to obtain the parameter.
    4. You must select Business Pass-through as the passing method of the input parameter.
    In this example, the dormitory convention content index article_index is set as a business pass-through parameter. Enter Dormitory convention query tool as the tool name, select POST as the request method, and select application/json as the submission method. Set the type of the input parameter article_index to Number, the passing method to Body, and make it required. Enter article as the output parameter name, "Dormitory convention content" as the parameter description, and set the type to String.
  3. Click Test Tool. After the test runs successfully, publish the plugin.

Step 2: Associate the agent application with the specified plugin

Plugin tools can only be associated with Agent Applications in the same workspace.
  1. On the card of a published plugin, click Add to Agent and select the agent application to associate;
  2. Alternatively, click + Plugin in an application to associate the specified custom plugin;
  3. Then, publish the application directly.

Step 3: API call

  • When authentication is not required: To call a custom plugin through an API, use user_defined_params 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.
    The plugin ID can be obtained from the plugin card.
    In this example, the value 2 is passed to the dormitory convention index article_index parameter to query the content of the second dormitory convention, and the correct result is returned.
    • Python
    • Java
    • HTTP
    Sample request
    import os
    import dashscope
    # 需要 dashscope 2.0.1 及以上版本
    from dashscope import DashScopeError
    client = dashscope.Client(
            # 若没有配置环境变量,可用百炼API Key将下行替换为:api_key="sk-xxx"。但不建议在生产环境中直接将API Key硬编码到代码中,以减少API Key泄露风险。
            api_key=os.getenv("DASHSCOPE_API_KEY"))
    biz_params = {
        # 智能体应用的自定义插件输入参数传递,自定义的插件ID替换your_plugin_code
        "user_defined_params": {
            "your_plugin_code": {
                "article_index": 2}}}
    try:
        response = client.apps.completions.create(
                app_id='YOUR_APP_ID',
                prompt='寝室公约内容',
                biz_params=biz_params)
        print('%s\n' % (response.text))  # 处理只输出文本text
        # print('%s\n' % (response.usage))
    except DashScopeError as e:
        print(f'request_id={e.request_id}')
        print(f'code={e.code}')
        print(f'message={e.message}')
        print(f'请参考文档:https://help.aliyun.com/zh/model-studio/developer-reference/error-code')
    
    Sample response
    寝室公约的第二条规定如下:
    "寝室成员应当互帮互助、互相关心、互相学习、共同提高;宽容谦让、相互尊重、以诚相待。"
    这表明在寝室内,成员之间应该培养一种积极正面的生活和学习氛围,彼此帮助和支持,同时也要学会理解和尊重他人。如果您需要了解公约的其他条款,请告诉我!
    
  • When authentication is required: To call a custom plugin through an API, the Authentication switch is turned on in the plugin and User-level Authentication is configured.
    The plugin ID is obtained from the plugin card.
    • Use user_defined_params 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.
    • Use user_defined_tokens of biz_params to pass the related information, replace your_plugin_code with the actual plugin ID, and fill in the authentication information as the value of user_token, such as the actual DASHSCOPE_API_KEY value.
    • After the authentication succeeds, the specific entry is queried based on the passed index parameter and the correct result is returned.
    In this example, the value 2 is passed to the dormitory convention index article_index parameter, and the value of user_token, YOUR_TOKEN, is replaced with the actual DASHSCOPE_API_KEY value. After the authentication succeeds, the content of the second dormitory convention is queried, and the correct result is returned.
    • Python
    • Java
    • HTTP
    Sample request
    import os
    import dashscope
    # 需要 dashscope 2.0.1 及以上版本
    from dashscope import DashScopeError
    client = dashscope.Client(
                # 若没有配置环境变量,可用百炼API Key将下行替换为:api_key="sk-xxx"。但不建议在生产环境中直接将API Key硬编码到代码中,以减少API Key泄露风险。
                api_key=os.getenv("DASHSCOPE_API_KEY"))
    biz_params = {
        # 智能体应用的自定义插件鉴权传递,自定义的插件ID替换your_plugin_code,鉴权信息替换YOUR_TOKEN,如API key
        "user_defined_params": {
            "your_plugin_code": {
                "article_index": 2}},
        "user_defined_tokens": {
            "your_plugin_code": {
                "user_token": "YOUR_TOKEN"}}}
    try:
        response = client.apps.completions.create(
                    app_id='YOUR_APP_ID',
                    prompt='寝室公约内容',
                    biz_params=biz_params)
        print('%s\n' % (response.text))  # 处理只输出文本text
        # print('%s\n' % (response.usage))
    except DashScopeError as e:
        print(f'request_id={e.request_id}')
        print(f'code={e.code}')
        print(f'message={e.message}')
        print(f'请参考文档:https://help.aliyun.com/zh/model-studio/developer-reference/error-code')
    
    Sample response
    寝室公约的第二条规定如下:
    寝室成员应当互帮互助、互相关心、互相学习、共同提高;宽容谦让、相互尊重、以诚相待。
    如果您需要了解更多的规定内容,请告诉我。
    

Custom node parameter pass-through

This article uses the querying the administrative divisions of a city by city name example to show you how to call the custom node parameter pass-through feature of an application through an API.
Custom node parameters of an application are passed through the start node of a Workflow Application.
The following example shows how to pass the custom parameters of the start node in a Workflow Application.

Usage

Step 1: Configure custom node parameters

Open the target application in the workflow list. In the Start node, add a String variable named city. Insert city and query into the prompt, then publish the application.

Step 2: API call

When calling, pass city through the biz_params field and query through the prompt field.
  • Python
  • Java
  • HTTP
Sample request
import os
import dashscope
from dashscope import DashScopeError

client = dashscope.Client(
    # 若没有配置环境变量,可用百炼API Key将下行替换为:api_key="sk-xxx"。但不建议在生产环境中直接将API Key硬编码到代码中,以减少API Key泄露风险。
    api_key=os.getenv("DASHSCOPE_API_KEY"))
# 工作流应用自定义参数传递
biz_params = {"city": "杭州"}
try:
    response = client.apps.completions.create(
        app_id='YOUR_APP_ID',  # 替换为实际的应用 ID
        prompt='查询这个城市的行政区域划分',
        biz_params=biz_params  # 传递业务参数
    )
    print(f'{response.text}')  # 处理只输出文本text
except DashScopeError as e:
    print(f'request_id={e.request_id}')
    print(f'code={e.code}')
    print(f'message={e.message}')
    print(f'请参考文档:https://help.aliyun.com/zh/model-studio/developer-reference/error-code')
Sample response
杭州市,作为浙江省的省会城市,其行政区域划分包括10个市辖区:上城区、拱墅区、西湖区、滨江区、萧山区、余杭区、临平区、钱塘区、富阳区、临安区。每个区都有其独特的特色和发展重点。
- 上城区:位于杭州市中心地带,是杭州的政治、经济、文化中心之一。
- 拱墅区:以运河文化为特色,拥有众多历史文化遗产。
- 西湖区:著名的西湖风景区就位于此区,是旅游观光的重要目的地。
- 滨江区:高新技术产业聚集地,阿里巴巴等知名企业坐落于此。
- 萧山区:东南部的一个行政区,经济发展迅速,特别是制造业方面。
- 余杭区:近年来发展快速,尤其是互联网经济领域,阿里巴巴总部也设在这里(注:阿里巴巴总部实际位于滨江区)。
- 临平区:新成立的行政区,旨在促进该地区经济社会全面发展。
- 钱塘区:同样是一个较新的行政区划调整结果,强调创新发展和生态保护相结合。
- 富阳区:位于杭州西南方向,以其丰富的自然景观和悠久的历史文化著称。
- 临安区:地处杭州西部,以生态优美闻名,并且有着深厚的文化底蕴。
请注意,随着时间推移,具体的城市规划可能会有所变化,请参考最新的官方信息。
Custom plugins: Steps for creating a custom plugin. Invoke an agent application, Invoke a workflow application: How to invoke applications and more usage. Application invocation API: The complete parameter list and invocation examples.