From 667713f6c04fbc208fb7eefba70f101562070c9e Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 19 Sep 2024 17:31:38 -0300 Subject: [PATCH] fix: add run_id parameter to set run ID in graph and handle exceptions in FlowTool (#3855) * Add run_id setting to FlowTool with warning on failure * feat: Add try-except block to set run_id in FlowTool The try-except block is added to handle any exceptions that may occur when setting the run_id in the FlowTool class. If an exception occurs, a warning is issued and the run_id is set to None. This ensures that the code does not break if there is an error in setting the run_id. --- src/backend/base/langflow/base/tools/flow_tool.py | 7 ++++++- .../base/langflow/components/prototypes/FlowTool.py | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/backend/base/langflow/base/tools/flow_tool.py b/src/backend/base/langflow/base/tools/flow_tool.py index 608c8234d..421d7f728 100644 --- a/src/backend/base/langflow/base/tools/flow_tool.py +++ b/src/backend/base/langflow/base/tools/flow_tool.py @@ -1,3 +1,4 @@ +import warnings from typing import Any, List, Optional, Type from langchain_core.runnables import RunnableConfig @@ -97,7 +98,11 @@ class FlowTool(BaseTool): ) -> str: """Use the tool asynchronously.""" tweaks = self.build_tweaks_dict(args, kwargs) - run_id = self.graph.run_id if self.graph else None + try: + run_id = self.graph.run_id if self.graph else None + except Exception as e: + warnings.warn(f"Failed to set run_id: {e}") + run_id = None run_outputs = await run_flow( tweaks={key: {"input_value": value} for key, value in tweaks.items()}, flow_id=self.flow_id, diff --git a/src/backend/base/langflow/components/prototypes/FlowTool.py b/src/backend/base/langflow/components/prototypes/FlowTool.py index 0498140ae..4a75bf11b 100644 --- a/src/backend/base/langflow/components/prototypes/FlowTool.py +++ b/src/backend/base/langflow/components/prototypes/FlowTool.py @@ -1,3 +1,4 @@ +import warnings from typing import Any, List, Optional from langflow.base.langchain_utilities.model import LCToolComponent @@ -79,6 +80,10 @@ class FlowToolComponent(LCToolComponent): if not flow_data: raise ValueError("Flow not found.") graph = Graph.from_payload(flow_data.data["data"]) + try: + graph.set_run_id(self.graph.run_id) + except Exception as e: + warnings.warn(f"Failed to set run_id: {e}") inputs = get_flow_inputs(graph) tool = FlowTool( name=self.name,