Function calling null param #4882

Closed
opened 2026-02-21 18:08:27 -05:00 by yindo · 2 comments
Owner

Originally created by @Sumkor on GitHub (Aug 4, 2024).

Originally assigned to: @laipz8200 on GitHub.

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

V0.6.15

Cloud or Self Hosted

Self Hosted (Docker), Self Hosted (Source)

Steps to reproduce

I created an Custom Agent Tool to call a third-party API. In this third-party API parameters, default values will be set for some fields which not passed. However, null values are set for this field currently. As a result, an error occurs when the default field value are overwritten.

✔️ Expected Behavior

In the logdetail dialog, it show that LLM only pass one param to the third-party API.

图片

Actual Behavior

When I debug into the soure code, the acture request body contain lot of null param.

图片

Originally created by @Sumkor on GitHub (Aug 4, 2024). Originally assigned to: @laipz8200 on GitHub. ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version V0.6.15 ### Cloud or Self Hosted Self Hosted (Docker), Self Hosted (Source) ### Steps to reproduce I created an Custom Agent Tool to call a third-party API. In this third-party API parameters, default values will be set for some fields which not passed. However, null values are set for this field currently. As a result, an error occurs when the default field value are overwritten. ### ✔️ Expected Behavior In the logdetail dialog, it show that LLM only pass one param to the third-party API. ![图片](https://github.com/user-attachments/assets/b249acf2-4424-4ce1-a835-233f04270b68) ### ❌ Actual Behavior When I debug into the soure code, the acture request body contain lot of null param. ![图片](https://github.com/user-attachments/assets/79b6a865-34a5-4463-bc34-b94513f491b5)
yindo added the 🐞 bug🤖 feat:agent labels 2026-02-21 18:08:27 -05:00
yindo closed this issue 2026-02-21 18:08:27 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Aug 4, 2024):

Hello @Sumkor! I'm a bot that can help you solve bugs, answer questions, and become a contributor. I'm here to assist you while we wait for a human maintainer.

To ensure that default values for fields are used instead of null values when calling a third-party API with your custom agent tool in Dify V0.6.15, you can configure the default values in your DifyConfig class. Here is an example of how you can set default values:

from pydantic import BaseSettings

class DifyConfig(BaseSettings):
    COMMIT_SHA: str = ''
    EDITION: str = 'SELF_HOSTED'
    API_COMPRESSION_ENABLED: bool = False
    SENTRY_TRACES_SAMPLE_RATE: float = 1.0
    LOG_LEVEL: str = 'INFO'
    CONSOLE_API_URL: str = 'https://example.com'
    CONSOLE_WEB_URL: str = 'https://example.com'
    SQLALCHEMY_DATABASE_URI: str = 'postgresql://postgres:@localhost:5432/dify'
    SQLALCHEMY_ENGINE_OPTIONS: dict = {
        'connect_args': {
            'options': '-c timezone=UTC',
        },
        'max_overflow': 10,
        'pool_pre_ping': False,
        'pool_recycle': 3600,
        'pool_size': 30,
    }
    CONSOLE_CORS_ALLOW_ORIGINS: list = ['https://example.com']
    WEB_API_CORS_ALLOW_ORIGINS: list = ['*']

When you load this configuration, the default values will be used if no other values are provided, ensuring that your fields will not be null when calling the third-party API [1].

Additionally, you can specify default values for parameters in the tool's YAML configuration file. For example, in the google_search.yaml file, you can set a default value for the result_type parameter:

parameters: # Parameter list
  - name: query # Parameter name
    type: string # Parameter type
    required: true # Required or not
    label: # Parameter label
      en_US: Query string # English label
      zh_Hans: 查询语句 # Chinese label
    human_description: # Introduction for frontend display, supports multiple languages
      en_US: used for searching
      zh_Hans: 用于搜索网页内容
    llm_description: key words for searching # Introduction passed to LLM, similarly, in order to make LLM better understand this parameter, we suggest to write as detailed information about this parameter as possible here, so that LLM can understand this parameter
    form: llm # Form type, llm means this parameter needs to be inferred by Agent, the frontend will not display this parameter
  - name: result_type
    type: select # Parameter type
    required: true
    options: # Drop-down box options
      - value: text
        label:
          en_US: text
          zh_Hans: 文本
      - value: link
        label:
          en_US: link
          zh_Hans: 链接
    default: link
    label:
      en_US: Result type
      zh_Hans: 结果类型
    human_description:
      en_US: used for selecting the result type, text or link
      zh_Hans: 用于选择结果类型,使用文本还是链接进行展示
    form: form # Form type, form means this parameter needs to be filled in by the user on the frontend before the conversation starts

By setting the default field in the parameter configuration, you ensure that the default value is used if no other value is provided, preventing null values when calling the third-party API [2].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Aug 4, 2024): <!-- Greeting --> Hello @Sumkor! I'm a bot that can help you solve bugs, answer questions, and become a contributor. I'm here to assist you while we wait for a human maintainer. <!-- Answer --> To ensure that default values for fields are used instead of null values when calling a third-party API with your custom agent tool in Dify V0.6.15, you can configure the default values in your `DifyConfig` class. Here is an example of how you can set default values: ```python from pydantic import BaseSettings class DifyConfig(BaseSettings): COMMIT_SHA: str = '' EDITION: str = 'SELF_HOSTED' API_COMPRESSION_ENABLED: bool = False SENTRY_TRACES_SAMPLE_RATE: float = 1.0 LOG_LEVEL: str = 'INFO' CONSOLE_API_URL: str = 'https://example.com' CONSOLE_WEB_URL: str = 'https://example.com' SQLALCHEMY_DATABASE_URI: str = 'postgresql://postgres:@localhost:5432/dify' SQLALCHEMY_ENGINE_OPTIONS: dict = { 'connect_args': { 'options': '-c timezone=UTC', }, 'max_overflow': 10, 'pool_pre_ping': False, 'pool_recycle': 3600, 'pool_size': 30, } CONSOLE_CORS_ALLOW_ORIGINS: list = ['https://example.com'] WEB_API_CORS_ALLOW_ORIGINS: list = ['*'] ``` When you load this configuration, the default values will be used if no other values are provided, ensuring that your fields will not be null when calling the third-party API <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/tests/unit_tests/configs/test_dify_config.py)</sup>. Additionally, you can specify default values for parameters in the tool's YAML configuration file. For example, in the `google_search.yaml` file, you can set a default value for the `result_type` parameter: ```yaml parameters: # Parameter list - name: query # Parameter name type: string # Parameter type required: true # Required or not label: # Parameter label en_US: Query string # English label zh_Hans: 查询语句 # Chinese label human_description: # Introduction for frontend display, supports multiple languages en_US: used for searching zh_Hans: 用于搜索网页内容 llm_description: key words for searching # Introduction passed to LLM, similarly, in order to make LLM better understand this parameter, we suggest to write as detailed information about this parameter as possible here, so that LLM can understand this parameter form: llm # Form type, llm means this parameter needs to be inferred by Agent, the frontend will not display this parameter - name: result_type type: select # Parameter type required: true options: # Drop-down box options - value: text label: en_US: text zh_Hans: 文本 - value: link label: en_US: link zh_Hans: 链接 default: link label: en_US: Result type zh_Hans: 结果类型 human_description: en_US: used for selecting the result type, text or link zh_Hans: 用于选择结果类型,使用文本还是链接进行展示 form: form # Form type, form means this parameter needs to be filled in by the user on the frontend before the conversation starts ``` By setting the `default` field in the parameter configuration, you ensure that the default value is used if no other value is provided, preventing null values when calling the third-party API <sup>[[2]](https://github.com/langgenius/dify-docs/blob/main/en/guides/tools/quick-tool-integration.md)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@Sumkor commented on GitHub (Aug 7, 2024):

After all, the LLM decide to pass one param as my expected, but you guys insist to pass all params filled by null. LOL

@Sumkor commented on GitHub (Aug 7, 2024): After all, the LLM decide to pass one param as my expected, but you guys insist to pass all params filled by null. LOL
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#4882