Skip to content

Commit 6ca1aef

Browse files
authored
Fix: catch non-begin component output (#7827)
### What problem does this PR solve? Catch non-begin component output ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
1 parent d285a12 commit 6ca1aef

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

agent/component/code.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,23 @@ class Code(ComponentBase, ABC):
7979
def _run(self, history, **kwargs):
8080
arguments = {}
8181
for input in self._param.arguments:
82-
assert "@" in input["component_id"], "Each code argument should bind to a specific compontent"
83-
component_id = input["component_id"].split("@")[0]
84-
refered_component_key = input["component_id"].split("@")[1]
85-
refered_component = self._canvas.get_component(component_id)["obj"]
86-
87-
for param in refered_component._param.query:
88-
if param["key"] == refered_component_key:
89-
if "value" in param:
90-
arguments[input["name"]] = param["value"]
82+
if "@" in input["component_id"]:
83+
component_id = input["component_id"].split("@")[0]
84+
refered_component_key = input["component_id"].split("@")[1]
85+
refered_component = self._canvas.get_component(component_id)["obj"]
86+
87+
for param in refered_component._param.query:
88+
if param["key"] == refered_component_key:
89+
if "value" in param:
90+
arguments[input["name"]] = param["value"]
91+
else:
92+
cpn = self._canvas.get_component(input["component_id"])["obj"]
93+
if cpn.component_name.lower() == "answer":
94+
arguments[input["name"]] = self._canvas.get_history(1)[0]["content"]
95+
continue
96+
_, out = cpn.output(allow_partial=False)
97+
if not out.empty:
98+
arguments[input["name"]] = "\n".join(out["content"])
9199

92100
return self._execute_code(
93101
language=self._param.lang,

0 commit comments

Comments
 (0)