From ff318aba7a9f6a7b7eec5f47747b1cf51b3095b9 Mon Sep 17 00:00:00 2001 From: Ricardo-M-L <69202550+Ricardo-M-L@users.noreply.github.com> Date: Mon, 18 May 2026 09:58:45 +0800 Subject: [PATCH] fix: correct literal_eval dispatch and bool isinstance ordering in agent components (#13988) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary This PR fixes 3 bugs in agent components: ### Bug 1: `DataOperations._invoke()` dispatches `"literal_eval"` to wrong handler **File:** `agent/component/data_operations.py`, line 76 The `_invoke()` method compares `self._param.operations` against `"recursive_eval"` (line 76), but the valid value defined in `DataOperationsParam.__init__()` (line 29) and validated in `check()` (line 43) is `"literal_eval"`. This means selecting the `literal_eval` operation from the frontend would never match, and the method `_literal_eval()` would never be called. **Fix:** Change `"recursive_eval"` to `"literal_eval"` in the dispatch condition. ### Bug 2: `VariableAssigner._clear()` — `bool` branch unreachable **File:** `agent/component/variable_assigner.py`, lines 95–100 In Python, `bool` is a subclass of `int` (`True` is `isinstance(True, int) == True`). The `isinstance(variable, int)` check on line 95 catches boolean values before the `isinstance(variable, bool)` check on line 99, making the bool branch unreachable. A boolean variable would be cleared to `0` instead of `False`. **Fix:** Move the `isinstance(variable, bool)` check before `isinstance(variable, int)`. ### Bug 3: `LoopItem.evaluate_condition()` — `bool` branch unreachable **File:** `agent/component/loopitem.py`, lines 67–93 Same issue as Bug 2: `isinstance(var, (int, float))` on line 67 catches boolean values before `isinstance(var, bool)` on line 85. Boolean variables would be evaluated with numeric operators (`=`, `≠`, `>`, etc.) instead of boolean operators (`is`, `is not`). **Fix:** Move the `isinstance(var, bool)` check before `isinstance(var, (int, float))`. ## Test plan - [ ] Verify `DataOperations` with `literal_eval` operation correctly invokes `_literal_eval()` - [ ] Verify `VariableAssigner._clear()` returns `False` for boolean variables (not `0`) - [ ] Verify `LoopItem.evaluate_condition()` uses boolean operators for `True`/`False` values 🤖 Generated with [Claude Code](https://claude.com/claude-code) ## Summary by CodeRabbit * **Bug Fixes** * Fixed operation routing logic to correctly dispatch the "literal_eval" operation to its handler. * **Refactor** * Reorganized conditional branch ordering in agent components to improve code structure and maintainability without affecting functional behavior. Co-authored-by: Claude Opus 4.6 (1M context) --- agent/component/data_operations.py | 2 +- agent/component/loopitem.py | 20 ++++++++++---------- agent/component/variable_assigner.py | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/agent/component/data_operations.py b/agent/component/data_operations.py index 60e65f8812..9cf5c55335 100644 --- a/agent/component/data_operations.py +++ b/agent/component/data_operations.py @@ -73,7 +73,7 @@ class DataOperations(ComponentBase,ABC): continue if self._param.operations == "select_keys": self._select_keys() - elif self._param.operations == "recursive_eval": + elif self._param.operations == "literal_eval": self._literal_eval() elif self._param.operations == "combine": self._combine() diff --git a/agent/component/loopitem.py b/agent/component/loopitem.py index b656ea7894..0cfb500850 100644 --- a/agent/component/loopitem.py +++ b/agent/component/loopitem.py @@ -64,6 +64,16 @@ class LoopItem(ComponentBase, ABC): elif operator == "not empty": return var != "" + elif isinstance(var, bool): + if operator == "is": + return var is value + elif operator == "is not": + return var is not value + elif operator == "empty": + return var is None + elif operator == "not empty": + return var is not None + elif isinstance(var, (int, float)): if operator == "=": return var == value @@ -82,16 +92,6 @@ class LoopItem(ComponentBase, ABC): elif operator == "not empty": return var is not None - elif isinstance(var, bool): - if operator == "is": - return var is value - elif operator == "is not": - return var is not value - elif operator == "empty": - return var is None - elif operator == "not empty": - return var is not None - elif isinstance(var, dict): if operator == "empty": return len(var) == 0 diff --git a/agent/component/variable_assigner.py b/agent/component/variable_assigner.py index 0f78213684..5b5e39a825 100644 --- a/agent/component/variable_assigner.py +++ b/agent/component/variable_assigner.py @@ -92,12 +92,12 @@ class VariableAssigner(ComponentBase,ABC): return "" elif isinstance(variable,dict): return {} + elif isinstance(variable,bool): + return False elif isinstance(variable,int): return 0 elif isinstance(variable,float): return 0.0 - elif isinstance(variable,bool): - return False else: return None