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
This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-11-19 10:54:47 -03:00 • committed by GitHub
commit 50defedfe6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 2 deletions

View file

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

View file

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