mirror of
https://github.com/langgenius/dify.git
synced 2026-07-30 16:59:35 +08:00
fix: allow an empty Agent tools selection (#39695)
This commit is contained in:
parent
832f42a996
commit
89ceba027e
@ -202,7 +202,10 @@ def init_frontend_parameter(rule: PluginParameter, type: StrEnum, value: Any):
|
||||
init frontend parameter by rule
|
||||
"""
|
||||
parameter_value = value
|
||||
if not parameter_value and parameter_value != 0:
|
||||
is_empty_tools_selection = (
|
||||
type == PluginParameterType.TOOLS_SELECTOR and isinstance(parameter_value, list) and not parameter_value
|
||||
)
|
||||
if not is_empty_tools_selection and not parameter_value and parameter_value != 0:
|
||||
# get default value
|
||||
parameter_value = rule.default
|
||||
if not parameter_value and rule.required:
|
||||
|
||||
@ -5,7 +5,9 @@ from unittest.mock import MagicMock
|
||||
import pytest
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from core.agent.plugin_entities import AgentStrategyParameter
|
||||
from core.agent.strategy.plugin import PluginAgentStrategy
|
||||
from core.tools.entities.common_entities import I18nObject
|
||||
|
||||
# ============================================================
|
||||
# Fixtures
|
||||
@ -103,6 +105,17 @@ class TestInitializeParameters:
|
||||
mock_declaration.parameters[0].init_frontend_parameter.assert_called_once_with("value1")
|
||||
mock_declaration.parameters[1].init_frontend_parameter.assert_called_once_with(None)
|
||||
|
||||
def test_initialize_parameters_allows_empty_tools_selection(self, strategy: PluginAgentStrategy) -> None:
|
||||
tools_parameter = AgentStrategyParameter(
|
||||
name="tools",
|
||||
label=I18nObject(en_US="Tools"),
|
||||
required=True,
|
||||
type=AgentStrategyParameter.AgentStrategyParameterType.TOOLS_SELECTOR,
|
||||
)
|
||||
strategy.declaration.parameters = [tools_parameter]
|
||||
|
||||
assert strategy.initialize_parameters({"tools": []}) == {"tools": []}
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"input_params",
|
||||
[
|
||||
|
||||
@ -265,6 +265,11 @@ class TestPluginParameterEntities:
|
||||
with pytest.raises(ValueError, match="not found in tool config"):
|
||||
init_frontend_parameter(required_rule, PluginParameterType.STRING, None)
|
||||
|
||||
tools_rule = PluginParameter(name="tools", label=self._label(), required=True, default=None)
|
||||
assert init_frontend_parameter(tools_rule, PluginParameterType.TOOLS_SELECTOR, []) == []
|
||||
with pytest.raises(ValueError, match="not found in tool config"):
|
||||
init_frontend_parameter(tools_rule, PluginParameterType.TOOLS_SELECTOR, None)
|
||||
|
||||
|
||||
class TestPluginDaemonEntities:
|
||||
def test_credential_type_helpers(self):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user