From 93bc185ca95efe7edffbec0448e638c9ffa410a9 Mon Sep 17 00:00:00 2001 From: Edwin Jose Date: Tue, 11 Feb 2025 12:41:17 -0500 Subject: [PATCH] fix: run flow component tool mode issues, causing tool result to be empty (#6121) * update * [autofix.ci] apply automated fixes * updates * [autofix.ci] apply automated fixes * Update run_flow.py * review suggestions * Update src/backend/base/langflow/components/logic/run_flow.py Co-authored-by: Madhavan --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Madhavan Co-authored-by: anovazzi1 --- src/backend/base/langflow/base/tools/run_flow.py | 7 +++++-- src/backend/base/langflow/components/logic/run_flow.py | 6 ++++-- .../base/langflow/custom/custom_component/component.py | 5 ++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/backend/base/langflow/base/tools/run_flow.py b/src/backend/base/langflow/base/tools/run_flow.py index 5360eedab..d13aa4520 100644 --- a/src/backend/base/langflow/base/tools/run_flow.py +++ b/src/backend/base/langflow/base/tools/run_flow.py @@ -1,4 +1,5 @@ from abc import abstractmethod +from typing import TYPE_CHECKING from loguru import logger @@ -19,6 +20,9 @@ from langflow.schema.dataframe import DataFrame from langflow.schema.message import Message from langflow.template import Output +if TYPE_CHECKING: + from langflow.base.tools.component_tool import ComponentToolkit + class RunFlowBaseComponent(Component): def __init__(self, *args, **kwargs): @@ -198,7 +202,7 @@ class RunFlowBaseComponent(Component): return fields async def to_toolkit(self) -> list[Tool]: - component_toolkit = _get_component_toolkit() + component_toolkit: type[ComponentToolkit] = _get_component_toolkit() flow_description, tool_mode_inputs = await self.get_required_data(self.flow_name_selected) # # convert list of dicts to list of dotdicts tool_mode_inputs = [dotdict(field) for field in tool_mode_inputs] @@ -212,5 +216,4 @@ class RunFlowBaseComponent(Component): ) if hasattr(self, TOOLS_METADATA_INPUT_NAME): tools = component_toolkit(component=self, metadata=self.tools_metadata).update_tools_metadata(tools=tools) - # self.status = tools return tools diff --git a/src/backend/base/langflow/components/logic/run_flow.py b/src/backend/base/langflow/components/logic/run_flow.py index bc296aa41..d96a4fc5a 100644 --- a/src/backend/base/langflow/components/logic/run_flow.py +++ b/src/backend/base/langflow/components/logic/run_flow.py @@ -9,7 +9,10 @@ from langflow.schema import dotdict class RunFlowComponent(RunFlowBaseComponent): display_name = "Run Flow" - description = "Creates a tool component from a Flow that takes all its inputs and runs it." + description = ( + "Creates a tool component from a Flow that takes all its inputs and runs it. " + " \n **Select a Flow to use the tool mode**" + ) beta = True name = "RunFlow" icon = "Workflow" @@ -64,6 +67,5 @@ class RunFlowComponent(RunFlowBaseComponent): flow_name=flow_name_selected, tweaks=tweaks, user_id=str(self.user_id), - # run_id=self.graph.run_id, session_id=self.graph.session_id or self.session_id, ) diff --git a/src/backend/base/langflow/custom/custom_component/component.py b/src/backend/base/langflow/custom/custom_component/component.py index 44984c86b..b43bef9f0 100644 --- a/src/backend/base/langflow/custom/custom_component/component.py +++ b/src/backend/base/langflow/custom/custom_component/component.py @@ -448,6 +448,7 @@ class Component(CustomComponent): frontend_node["tool_mode"] = True tools_metadata_input = await self._build_tools_metadata_input() frontend_node["template"][TOOLS_METADATA_INPUT_NAME] = tools_metadata_input.to_dict() + self._append_tool_to_outputs_map() elif "template" in frontend_node: frontend_node["template"].pop(TOOLS_METADATA_INPUT_NAME, None) self.tools_metadata = frontend_node.get("template", {}).get(TOOLS_METADATA_INPUT_NAME, {}).get("value") @@ -928,7 +929,9 @@ class Component(CustomComponent): self._pre_run_setup() def _handle_tool_mode(self): - if hasattr(self, "outputs") and any(getattr(_input, "tool_mode", False) for _input in self.inputs): + if ( + hasattr(self, "outputs") and any(getattr(_input, "tool_mode", False) for _input in self.inputs) + ) or self.add_tool_output: self._append_tool_to_outputs_map() def _should_process_output(self, output):