From cd55f6c1b822d84e23a2199ae5f71eac5671d736 Mon Sep 17 00:00:00 2001 From: buua436 <66937541+buua436@users.noreply.github.com> Date: Fri, 14 Nov 2025 19:50:29 +0800 Subject: [PATCH] Fix:ListOperations does not support sorting arrays of objects. (#11278) ### What problem does this PR solve? pr: #11276 change: ListOperations does not support sorting arrays of objects. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- agent/component/list_operations.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/agent/component/list_operations.py b/agent/component/list_operations.py index c29d79ea6..9ae8c2e04 100644 --- a/agent/component/list_operations.py +++ b/agent/component/list_operations.py @@ -121,10 +121,26 @@ class ListOperations(ComponentBase,ABC): return False def _sort(self): - if self._param.sort_method == "asc": - self._set_outputs(sorted(self.inputs)) - elif self._param.sort_method == "desc": - self._set_outputs(sorted(self.inputs, reverse=True)) + items = self.inputs or [] + method = getattr(self._param, "sort_method", "asc") or "asc" + reverse = method == "desc" + + if not items: + self._set_outputs([]) + return + + first = items[0] + + if isinstance(first, dict): + outputs = sorted( + items, + key=lambda x: self._hashable(x), + reverse=reverse, + ) + else: + outputs = sorted(items, reverse=reverse) + + self._set_outputs(outputs) def _drop_duplicates(self): seen = set() @@ -145,5 +161,6 @@ class ListOperations(ComponentBase,ABC): if isinstance(x, set): return tuple(sorted(self._hashable(v) for v in x)) return x + def thoughts(self) -> str: return "ListOperation in progress"