diff --git a/src/backend/base/langflow/base/agents/agent.py b/src/backend/base/langflow/base/agents/agent.py index e154b1968..0bceeaded 100644 --- a/src/backend/base/langflow/base/agents/agent.py +++ b/src/backend/base/langflow/base/agents/agent.py @@ -57,10 +57,11 @@ class LCAgentComponent(Component): ), MultilineInput( name="agent_description", - display_name="Agent Description", + display_name="Agent Description [Deprecated]", info=( "The description of the agent. This is only used when in Tool Mode. " - f"Defaults to '{DEFAULT_TOOLS_DESCRIPTION}' and tools are added dynamically." + f"Defaults to '{DEFAULT_TOOLS_DESCRIPTION}' and tools are added dynamically. " + "This feature is deprecated and will be removed in future versions." ), advanced=True, value=DEFAULT_TOOLS_DESCRIPTION, @@ -236,11 +237,11 @@ class LCToolsAgentComponent(LCAgentComponent): component_toolkit = _get_component_toolkit() tools_names = self._build_tools_names() agent_description = self.get_tool_description() - # Check if tools_description is the default value - if agent_description == DEFAULT_TOOLS_DESCRIPTION: - description = f"{agent_description}{tools_names}" - else: - description = agent_description - return component_toolkit(component=self).get_tools( + # TODO: Agent Description Depreciated Feature to be removed + description = f"{agent_description}{tools_names}" + tools = component_toolkit(component=self).get_tools( tool_name=self.get_tool_name(), tool_description=description, callbacks=self.get_langchain_callbacks() ) + if hasattr(self, "tools_metadata"): + tools = component_toolkit(component=self, metadata=self.tools_metadata).update_tools_metadata(tools=tools) + return tools diff --git a/src/backend/base/langflow/base/tools/component_tool.py b/src/backend/base/langflow/base/tools/component_tool.py index e3f82d8d6..30e1d83d4 100644 --- a/src/backend/base/langflow/base/tools/component_tool.py +++ b/src/backend/base/langflow/base/tools/component_tool.py @@ -218,6 +218,7 @@ class ComponentToolkit: args_schema=args_schema, handle_tool_error=True, callbacks=callbacks, + tags=[formatted_name], ) ) else: @@ -229,6 +230,7 @@ class ComponentToolkit: args_schema=args_schema, handle_tool_error=True, callbacks=callbacks, + tags=[formatted_name], ) ) if len(tools) == 1 and (tool_name or tool_description): @@ -243,17 +245,37 @@ class ComponentToolkit: raise ValueError(msg) return tools + def get_tools_metadata_dictionary(self) -> dict: + if isinstance(self.metadata, pd.DataFrame): + try: + return { + record["tags"][0]: record + for record in self.metadata.to_dict(orient="records") + if record.get("tags") + } + except (KeyError, IndexError) as e: + msg = "Error processing metadata records: " + str(e) + raise ValueError(msg) from e + return {} + def update_tools_metadata( self, tools: list[BaseTool | StructuredTool], ) -> list[BaseTool]: # update the tool_name and description according to the name and secriotion mentioned in the list if isinstance(self.metadata, pd.DataFrame): - metadata_dict = self.metadata.to_dict(orient="records") - for tool, metadata in zip(tools, metadata_dict, strict=False): - if isinstance(tool, StructuredTool | BaseTool): - tool.name = metadata.get("name", tool.name) - tool.description = metadata.get("description", tool.description) + metadata_dict = self.get_tools_metadata_dictionary() + for tool in tools: + if isinstance(tool, StructuredTool | BaseTool) and tool.tags: + try: + tag = tool.tags[0] + except IndexError: + msg = "Tool tags cannot be empty." + raise ValueError(msg) from None + if tag in metadata_dict: + tool_metadata = metadata_dict[tag] + tool.name = tool_metadata.get("name", tool.name) + tool.description = tool_metadata.get("description", tool.description) else: msg = f"Expected a StructuredTool or BaseTool, got {type(tool)}" raise TypeError(msg) diff --git a/src/backend/base/langflow/base/tools/constants.py b/src/backend/base/langflow/base/tools/constants.py index 507445c5e..64bd4c3cf 100644 --- a/src/backend/base/langflow/base/tools/constants.py +++ b/src/backend/base/langflow/base/tools/constants.py @@ -6,20 +6,35 @@ TOOLS_METADATA_INPUT_NAME = "tools_metadata" TOOL_TABLE_SCHEMA = [ { "name": "name", - "display_name": "Name", + "display_name": "Tool Name", "type": "str", - "description": "Specify the name of the output field.", + "description": "Specify the name of the tool.", "sortable": False, "filterable": False, "edit_mode": EditMode.INLINE, }, { "name": "description", - "display_name": "Description", + "display_name": "Tool Description", "type": "str", - "description": "Describe the purpose of the output field.", + "description": "Describe the purpose of the tool.", + "sortable": False, + "filterable": False, + "edit_mode": EditMode.INLINE, + }, + { + "name": "tags", + "display_name": "Tool Identifiers", + "type": "str", + "description": ( + "These are the default identifiers for the tools and cannot be changed. " + "Tool Name and Tool Description are the only editable fields." + ), + "disable_edit": True, "sortable": False, "filterable": False, "edit_mode": EditMode.INLINE, }, ] + +TOOLS_METADATA_INFO = "Use the table to configure the tools." diff --git a/src/backend/base/langflow/custom/custom_component/component.py b/src/backend/base/langflow/custom/custom_component/component.py index 948a9cb48..a25a4ef85 100644 --- a/src/backend/base/langflow/custom/custom_component/component.py +++ b/src/backend/base/langflow/custom/custom_component/component.py @@ -18,6 +18,7 @@ from langflow.base.tools.constants import ( TOOL_OUTPUT_DISPLAY_NAME, TOOL_OUTPUT_NAME, TOOL_TABLE_SCHEMA, + TOOLS_METADATA_INFO, TOOLS_METADATA_INPUT_NAME, ) from langflow.custom.tree_visitor import RequiredInputsVisitor @@ -1174,7 +1175,7 @@ class Component(CustomComponent): tool_data = ( self.tools_metadata if hasattr(self, TOOLS_METADATA_INPUT_NAME) - else [{"name": tool.name, "description": tool.description} for tool in tools] + else [{"name": tool.name, "description": tool.description, "tags": tool.tags} for tool in tools] ) try: from langflow.io import TableInput @@ -1184,7 +1185,7 @@ class Component(CustomComponent): return TableInput( name=TOOLS_METADATA_INPUT_NAME, - info="Use the table to configure the tools.", + info=TOOLS_METADATA_INFO, display_name="Toolset configuration", real_time_refresh=True, table_schema=TOOL_TABLE_SCHEMA, diff --git a/src/backend/base/langflow/initial_setup/starter_projects/Instagram Copywriter.json b/src/backend/base/langflow/initial_setup/starter_projects/Instagram Copywriter.json index 868c4b652..d21a51466 100644 --- a/src/backend/base/langflow/initial_setup/starter_projects/Instagram Copywriter.json +++ b/src/backend/base/langflow/initial_setup/starter_projects/Instagram Copywriter.json @@ -1656,9 +1656,9 @@ "agent_description": { "_input_type": "MultilineInput", "advanced": true, - "display_name": "Agent Description", + "display_name": "Agent Description [Deprecated]", "dynamic": false, - "info": "The description of the agent. This is only used when in Tool Mode. Defaults to 'A helpful assistant with access to the following tools:' and tools are added dynamically.", + "info": "The description of the agent. This is only used when in Tool Mode. Defaults to 'A helpful assistant with access to the following tools:' and tools are added dynamically. This feature is deprecated and will be removed in future versions.", "input_types": [ "Message" ], diff --git a/src/backend/base/langflow/initial_setup/starter_projects/Market Research.json b/src/backend/base/langflow/initial_setup/starter_projects/Market Research.json index 17785e589..5092ba26e 100644 --- a/src/backend/base/langflow/initial_setup/starter_projects/Market Research.json +++ b/src/backend/base/langflow/initial_setup/starter_projects/Market Research.json @@ -1900,9 +1900,9 @@ "agent_description": { "_input_type": "MultilineInput", "advanced": true, - "display_name": "Agent Description", + "display_name": "Agent Description [Deprecated]", "dynamic": false, - "info": "The description of the agent. This is only used when in Tool Mode. Defaults to 'A helpful assistant with access to the following tools:' and tools are added dynamically.", + "info": "The description of the agent. This is only used when in Tool Mode. Defaults to 'A helpful assistant with access to the following tools:' and tools are added dynamically. This feature is deprecated and will be removed in future versions.", "input_types": [ "Message" ], diff --git a/src/backend/base/langflow/initial_setup/starter_projects/Research Agent.json b/src/backend/base/langflow/initial_setup/starter_projects/Research Agent.json index e6a53e43c..a7f5903da 100644 --- a/src/backend/base/langflow/initial_setup/starter_projects/Research Agent.json +++ b/src/backend/base/langflow/initial_setup/starter_projects/Research Agent.json @@ -2147,9 +2147,9 @@ "agent_description": { "_input_type": "MultilineInput", "advanced": true, - "display_name": "Agent Description", + "display_name": "Agent Description [Deprecated]", "dynamic": false, - "info": "The description of the agent. This is only used when in Tool Mode. Defaults to 'A helpful assistant with access to the following tools:' and tools are added dynamically.", + "info": "The description of the agent. This is only used when in Tool Mode. Defaults to 'A helpful assistant with access to the following tools:' and tools are added dynamically. This feature is deprecated and will be removed in future versions.", "input_types": [ "Message" ], diff --git a/src/backend/base/langflow/initial_setup/starter_projects/SaaS Pricing.json b/src/backend/base/langflow/initial_setup/starter_projects/SaaS Pricing.json index ef620be6f..9f3af6a97 100644 --- a/src/backend/base/langflow/initial_setup/starter_projects/SaaS Pricing.json +++ b/src/backend/base/langflow/initial_setup/starter_projects/SaaS Pricing.json @@ -721,9 +721,9 @@ "agent_description": { "_input_type": "MultilineInput", "advanced": true, - "display_name": "Agent Description", + "display_name": "Agent Description [Deprecated]", "dynamic": false, - "info": "The description of the agent. This is only used when in Tool Mode. Defaults to 'A helpful assistant with access to the following tools:' and tools are added dynamically.", + "info": "The description of the agent. This is only used when in Tool Mode. Defaults to 'A helpful assistant with access to the following tools:' and tools are added dynamically. This feature is deprecated and will be removed in future versions.", "input_types": [ "Message" ], diff --git a/src/backend/base/langflow/initial_setup/starter_projects/Sequential Tasks Agents .json b/src/backend/base/langflow/initial_setup/starter_projects/Sequential Tasks Agents .json index 916cc46ec..ee5075964 100644 --- a/src/backend/base/langflow/initial_setup/starter_projects/Sequential Tasks Agents .json +++ b/src/backend/base/langflow/initial_setup/starter_projects/Sequential Tasks Agents .json @@ -670,9 +670,9 @@ "agent_description": { "_input_type": "MultilineInput", "advanced": true, - "display_name": "Agent Description", + "display_name": "Agent Description [Deprecated]", "dynamic": false, - "info": "The description of the agent. This is only used when in Tool Mode. Defaults to 'A helpful assistant with access to the following tools:' and tools are added dynamically.", + "info": "The description of the agent. This is only used when in Tool Mode. Defaults to 'A helpful assistant with access to the following tools:' and tools are added dynamically. This feature is deprecated and will be removed in future versions.", "input_types": [ "Message" ], @@ -1248,9 +1248,9 @@ "agent_description": { "_input_type": "MultilineInput", "advanced": true, - "display_name": "Agent Description", + "display_name": "Agent Description [Deprecated]", "dynamic": false, - "info": "The description of the agent. This is only used when in Tool Mode. Defaults to 'A helpful assistant with access to the following tools:' and tools are added dynamically.", + "info": "The description of the agent. This is only used when in Tool Mode. Defaults to 'A helpful assistant with access to the following tools:' and tools are added dynamically. This feature is deprecated and will be removed in future versions.", "input_types": [ "Message" ], @@ -3141,9 +3141,9 @@ "agent_description": { "_input_type": "MultilineInput", "advanced": true, - "display_name": "Agent Description", + "display_name": "Agent Description [Deprecated]", "dynamic": false, - "info": "The description of the agent. This is only used when in Tool Mode. Defaults to 'A helpful assistant with access to the following tools:' and tools are added dynamically.", + "info": "The description of the agent. This is only used when in Tool Mode. Defaults to 'A helpful assistant with access to the following tools:' and tools are added dynamically. This feature is deprecated and will be removed in future versions.", "input_types": [ "Message" ], diff --git a/src/backend/base/langflow/initial_setup/starter_projects/Simple Agent.json b/src/backend/base/langflow/initial_setup/starter_projects/Simple Agent.json index 1f45fb504..ac27610bc 100644 --- a/src/backend/base/langflow/initial_setup/starter_projects/Simple Agent.json +++ b/src/backend/base/langflow/initial_setup/starter_projects/Simple Agent.json @@ -204,9 +204,9 @@ "agent_description": { "_input_type": "MultilineInput", "advanced": true, - "display_name": "Agent Description", + "display_name": "Agent Description [Deprecated]", "dynamic": false, - "info": "The description of the agent. This is only used when in Tool Mode. Defaults to 'A helpful assistant with access to the following tools:' and tools are added dynamically.", + "info": "The description of the agent. This is only used when in Tool Mode. Defaults to 'A helpful assistant with access to the following tools:' and tools are added dynamically. This feature is deprecated and will be removed in future versions.", "input_types": [ "Message" ], diff --git a/src/backend/base/langflow/initial_setup/starter_projects/Travel Planning Agents.json b/src/backend/base/langflow/initial_setup/starter_projects/Travel Planning Agents.json index 2068cc5e3..0e2ff530c 100644 --- a/src/backend/base/langflow/initial_setup/starter_projects/Travel Planning Agents.json +++ b/src/backend/base/langflow/initial_setup/starter_projects/Travel Planning Agents.json @@ -1299,9 +1299,9 @@ "agent_description": { "_input_type": "MultilineInput", "advanced": true, - "display_name": "Agent Description", + "display_name": "Agent Description [Deprecated]", "dynamic": false, - "info": "The description of the agent. This is only used when in Tool Mode. Defaults to 'A helpful assistant with access to the following tools:' and tools are added dynamically.", + "info": "The description of the agent. This is only used when in Tool Mode. Defaults to 'A helpful assistant with access to the following tools:' and tools are added dynamically. This feature is deprecated and will be removed in future versions.", "input_types": [ "Message" ], @@ -1877,9 +1877,9 @@ "agent_description": { "_input_type": "MultilineInput", "advanced": true, - "display_name": "Agent Description", + "display_name": "Agent Description [Deprecated]", "dynamic": false, - "info": "The description of the agent. This is only used when in Tool Mode. Defaults to 'A helpful assistant with access to the following tools:' and tools are added dynamically.", + "info": "The description of the agent. This is only used when in Tool Mode. Defaults to 'A helpful assistant with access to the following tools:' and tools are added dynamically. This feature is deprecated and will be removed in future versions.", "input_types": [ "Message" ], @@ -2455,9 +2455,9 @@ "agent_description": { "_input_type": "MultilineInput", "advanced": true, - "display_name": "Agent Description", + "display_name": "Agent Description [Deprecated]", "dynamic": false, - "info": "The description of the agent. This is only used when in Tool Mode. Defaults to 'A helpful assistant with access to the following tools:' and tools are added dynamically.", + "info": "The description of the agent. This is only used when in Tool Mode. Defaults to 'A helpful assistant with access to the following tools:' and tools are added dynamically. This feature is deprecated and will be removed in future versions.", "input_types": [ "Message" ],