From 50defedfe6d52a0431be3186f0536328818037d8 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 19 Nov 2024 10:54:47 -0300 Subject: [PATCH] fix: add a check in ComponentToolkit to avoid building a tool that builds tools (#4678) * Enhance tool filtering logic by adding TOOL_TYPES set for output type checking * Rename TOOL_TYPES to TOOL_TYPES_SET for clarity --- src/backend/base/langflow/base/tools/component_tool.py | 5 ++++- src/backend/base/langflow/components/tools/calculator.py | 1 - 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/backend/base/langflow/base/tools/component_tool.py b/src/backend/base/langflow/base/tools/component_tool.py index 6e3855637..f97df9ad9 100644 --- a/src/backend/base/langflow/base/tools/component_tool.py +++ b/src/backend/base/langflow/base/tools/component_tool.py @@ -27,6 +27,9 @@ if TYPE_CHECKING: from langflow.schema.content_block import ContentBlock +TOOL_TYPES_SET = {"Tool", "BaseTool", "StructuredTool"} + + def _get_input_type(_input: InputTypes): if _input.input_types: if len(_input.input_types) == 1: @@ -165,7 +168,7 @@ class ComponentToolkit: ) -> list[BaseTool]: tools = [] for output in self.component.outputs: - if output.name == TOOL_OUTPUT_NAME: + if output.name == TOOL_OUTPUT_NAME or any(tool_type in output.types for tool_type in TOOL_TYPES_SET): continue if not output.method: diff --git a/src/backend/base/langflow/components/tools/calculator.py b/src/backend/base/langflow/components/tools/calculator.py index ffe0ea00b..c1c8e26ec 100644 --- a/src/backend/base/langflow/components/tools/calculator.py +++ b/src/backend/base/langflow/components/tools/calculator.py @@ -23,7 +23,6 @@ class CalculatorToolComponent(LCToolComponent): name="expression", display_name="Expression", info="The arithmetic expression to evaluate (e.g., '4*4*(33/22)+12-20').", - tool_mode=True, ), ]