From 0bf7dda0099f6563f495a7831f0c2cb55c3e6676 Mon Sep 17 00:00:00 2001 From: Edwin Jose Date: Fri, 8 Nov 2024 05:11:13 -0500 Subject: [PATCH] fix: component-set-handle-list-tools (#4465) update component.py I added a StructuredTool to define the set function in the component. This change resolved an error that occurred when the list of tools was set by the component. In the future, we may need to add tests to manage unexpected situations in the component's set function. I also updated the pytest. --- src/backend/base/langflow/custom/custom_component/component.py | 3 ++- .../tests/unit/components/agents/test_agent_component.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/backend/base/langflow/custom/custom_component/component.py b/src/backend/base/langflow/custom/custom_component/component.py index 3e3751ef0..16bbe7b58 100644 --- a/src/backend/base/langflow/custom/custom_component/component.py +++ b/src/backend/base/langflow/custom/custom_component/component.py @@ -10,6 +10,7 @@ from typing import TYPE_CHECKING, Any, ClassVar, get_type_hints import nanoid import yaml +from langchain_core.tools import StructuredTool from pydantic import BaseModel, ValidationError from langflow.base.tools.constants import TOOL_OUTPUT_DISPLAY_NAME, TOOL_OUTPUT_NAME @@ -494,7 +495,7 @@ class Component(CustomComponent): # if value is a list of components, we need to process each component # Note this update make sure it is not a list str | int | float | bool | type(None) if isinstance(value, list) and not any( - isinstance(val, str | int | float | bool | type(None) | Message | Data) for val in value + isinstance(val, str | int | float | bool | type(None) | Message | Data | StructuredTool) for val in value ): for val in value: self._process_connection_or_parameter(key, val) diff --git a/src/backend/tests/unit/components/agents/test_agent_component.py b/src/backend/tests/unit/components/agents/test_agent_component.py index 968abfab9..d20297940 100644 --- a/src/backend/tests/unit/components/agents/test_agent_component.py +++ b/src/backend/tests/unit/components/agents/test_agent_component.py @@ -24,5 +24,5 @@ async def test_agent_component_with_calculator(): temperature=temperature, ) - response = await agent.get_response() + response = await agent.message_response() assert "4" in response.data.get("text")