diff --git a/api/core/workflow/nodes/agent/agent_node.py b/api/core/workflow/nodes/agent/agent_node.py index 3aebd64160..5882ff7bcb 100644 --- a/api/core/workflow/nodes/agent/agent_node.py +++ b/api/core/workflow/nodes/agent/agent_node.py @@ -31,7 +31,7 @@ from core.tools.entities.tool_entities import ( ToolProviderType, ) from core.tools.tool_manager import ToolManager -from core.variables.segments import ArrayFileSegment, FileSegment, StringSegment +from core.variables.segments import ArrayFileSegment, FileSegment, StringSegment, ArrayAnySegment from core.workflow.entities.node_entities import NodeRunResult from core.workflow.entities.variable_pool import VariablePool from core.workflow.entities.workflow_node_execution import WorkflowNodeExecutionStatus @@ -190,6 +190,27 @@ class AgentNode(ToolNode): """ agent_parameters_dictionary = {parameter.name: parameter for parameter in agent_parameters} + # Determine once whether this node references sys.files anywhere and whether that variable is empty. + def _input_uses_sys_files(_agent_input): + if _agent_input.type == "variable": + return _agent_input.value == ["sys", SystemVariableKey.FILES.value] + if _agent_input.type in {"mixed", "constant"}: + return "sys.files" in str(_agent_input.value) + return False + + uses_sys_files_for_node: bool = any( + _input_uses_sys_files(inp) for inp in node_data.agent_parameters.values() + ) + + sys_files_segment = variable_pool.get(["sys", SystemVariableKey.FILES.value]) + sys_files_empty: bool = ( + sys_files_segment is None + or ( + isinstance(sys_files_segment, (ArrayFileSegment, ArrayAnySegment)) + and len(sys_files_segment.value) == 0 + ) + ) + result: dict[str, Any] = {} for parameter_name in node_data.agent_parameters: parameter = agent_parameters_dictionary.get(parameter_name) @@ -402,6 +423,10 @@ class AgentNode(ToolNode): pass value["history_prompt_messages"] = history_prompt_messages + # If sys.files is empty, strip any leftover "[]" placeholder from strings (both log and runtime params). + if sys_files_empty and isinstance(value, str): + value = value.replace("[]", "").rstrip() + result[parameter_name] = value return result