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 <msmygit@users.noreply.github.com>

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Madhavan <msmygit@users.noreply.github.com>
Co-authored-by: anovazzi1 <otavio2204@gmail.com>
This commit is contained in:
Edwin Jose 2025-02-11 12:41:17 -05:00 committed by GitHub
commit 93bc185ca9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 5 deletions

View file

@ -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

View file

@ -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,
)

View file

@ -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):