diff --git a/api/core/workflow/nodes/tool/entities.py b/api/core/workflow/nodes/tool/entities.py index ebaa7a56bd..aec8f34bb9 100644 --- a/api/core/workflow/nodes/tool/entities.py +++ b/api/core/workflow/nodes/tool/entities.py @@ -16,8 +16,8 @@ class ToolEntity(BaseModel): class ToolNodeData(BaseNodeData, ToolEntity): class ToolInput(BaseModel): - type: Literal['mixed', 'variable', 'constant'] value: Union[ToolParameterValue, list[str]] + type: Literal['mixed', 'variable', 'constant'] @validator('type', pre=True, always=True) def check_type(cls, value, values): @@ -29,7 +29,7 @@ class ToolNodeData(BaseNodeData, ToolEntity): raise ValueError('value must be a list') elif typ == 'constant' and not isinstance(value, ToolParameterValue): raise ValueError('value must be a string, int, float, or bool') - return value + return typ """ Tool Node Schema diff --git a/api/tests/integration_tests/workflow/nodes/test_tool.py b/api/tests/integration_tests/workflow/nodes/test_tool.py index 43a0185844..e2bc68b767 100644 --- a/api/tests/integration_tests/workflow/nodes/test_tool.py +++ b/api/tests/integration_tests/workflow/nodes/test_tool.py @@ -4,7 +4,7 @@ from core.workflow.entities.variable_pool import VariablePool from core.workflow.nodes.tool.tool_node import ToolNode from models.workflow import WorkflowNodeExecutionStatus -def test_tool_invoke(): +def test_tool_variable_invoke(): pool = VariablePool(system_variables={}, user_inputs={}) pool.append_variable(node_id='1', variable_key_list=['123', 'args1'], value='1+1') @@ -25,14 +25,50 @@ def test_tool_invoke(): 'tool_name': 'eval_expression', 'tool_label': 'eval_expression', 'tool_configurations': {}, - 'tool_parameters': [ - { - 'value_type': 'variable', - 'static_value': None, - 'variable_value': ['1', '123', 'args1'], - 'parameter_name': 'expression', - }, - ] + 'tool_parameters': { + 'expression': { + 'type': 'variable', + 'value': ['1', '123', 'args1'], + } + } + } + } + ) + + # execute node + result = node.run(pool) + + assert result.status == WorkflowNodeExecutionStatus.SUCCEEDED + assert '2' in result.outputs['text'] + assert result.outputs['files'] == [] + +def test_tool_mixed_invoke(): + pool = VariablePool(system_variables={}, user_inputs={}) + pool.append_variable(node_id='1', variable_key_list=['args1'], value='1+1') + + node = ToolNode( + tenant_id='1', + app_id='1', + workflow_id='1', + user_id='1', + user_from=InvokeFrom.WEB_APP, + config={ + 'id': '1', + 'data': { + 'title': 'a', + 'desc': 'a', + 'provider_id': 'maths', + 'provider_type': 'builtin', + 'provider_name': 'maths', + 'tool_name': 'eval_expression', + 'tool_label': 'eval_expression', + 'tool_configurations': {}, + 'tool_parameters': { + 'expression': { + 'type': 'mixed', + 'value': '{{#1.args1#}}', + } + } } } )