From 6784e0dfee49803bce36e2662997a46564404092 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=91=E5=B9=BB=E5=A4=A7=E8=84=91?= <47254718+Sci-fiBrain@users.noreply.github.com> Date: Thu, 20 Mar 2025 15:06:18 +0800 Subject: [PATCH] Fix: Resolved a bug where sibling components in Canvas were not restricted to fetching data from the upstream when parallel components were present. (#6315) ### What problem does this PR solve? Fix: Resolved a bug where sibling components in Canvas were not restricted to fetching data from the upstream when parallel components were present. Issue: When parallel components existed in Canvas, sibling components incorrectly fetched data without being limited to the upstream scope, causing data retrieval issues. Solution: Adjusted the data fetching logic to ensure sibling components only retrieve data from the upstream scope. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- agent/component/base.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/agent/component/base.py b/agent/component/base.py index 4e9122dae..4138ba9b4 100644 --- a/agent/component/base.py +++ b/agent/component/base.py @@ -463,6 +463,8 @@ class ComponentBase(ABC): if len(self._canvas.path) > 1: reversed_cpnts.extend(self._canvas.path[-2]) reversed_cpnts.extend(self._canvas.path[-1]) + up_cpns = self.get_upstream() + reversed_up_cpnts = [cpn for cpn in reversed_cpnts if cpn in up_cpns] if self._param.query: self._param.inputs = [] @@ -505,7 +507,7 @@ class ComponentBase(ABC): upstream_outs = [] - for u in reversed_cpnts[::-1]: + for u in reversed_up_cpnts[::-1]: if self.get_component_name(u) in ["switch", "concentrator"]: continue if self.component_name.lower() == "generate" and self.get_component_name(u) == "retrieval": @@ -565,8 +567,10 @@ class ComponentBase(ABC): if len(self._canvas.path) > 1: reversed_cpnts.extend(self._canvas.path[-2]) reversed_cpnts.extend(self._canvas.path[-1]) + up_cpns = self.get_upstream() + reversed_up_cpnts = [cpn for cpn in reversed_cpnts if cpn in up_cpns] - for u in reversed_cpnts[::-1]: + for u in reversed_up_cpnts[::-1]: if self.get_component_name(u) in ["switch", "answer"]: continue return self._canvas.get_component(u)["obj"].output()[1] @@ -584,3 +588,7 @@ class ComponentBase(ABC): def get_parent(self): pid = self._canvas.get_component(self._id)["parent_id"] return self._canvas.get_component(pid)["obj"] + + def get_upstream(self): + cpn_nms = self._canvas.get_component(self._id)['upstream'] + return cpn_nms