fix: make agent work with new tool mode backend updates (#7314)

* update tools in agents

* fix: update tool status check to default to True

* refactor: rename to_toolkit method to _get_tools and remove deprecated code

* [autofix.ci] apply automated fixes

* fix: makes agent tool metadata be correctly generated

* Update agent JSON files with new code for Agent component

* Enhance Financial Agent JSON configuration with updated code for the Agent component, including improved memory handling, tool validation, and error logging for better robustness and async functionality.

---------

Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
Edwin Jose 2025-03-31 10:23:19 -04:00 committed by GitHub
commit 58b12b40e1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 23 additions and 48 deletions

View file

@ -238,7 +238,7 @@ class LCToolsAgentComponent(LCAgentComponent):
tools_names = ", ".join([tool.name for tool in self.tools])
return tools_names
async def to_toolkit(self) -> list[Tool]:
async def _get_tools(self) -> list[Tool]:
component_toolkit = _get_component_toolkit()
tools_names = self._build_tools_names()
agent_description = self.get_tool_description()

View file

@ -317,7 +317,7 @@ class ComponentToolkit:
if tag in metadata_dict:
tool_metadata = metadata_dict[tag]
# Only include tools with status=True
if tool_metadata.get("status", False):
if tool_metadata.get("status", True):
tool.name = tool_metadata.get("name", tool.name)
tool.description = tool_metadata.get("description", tool.description)
if tool_metadata.get("commands"):

View file

@ -12,9 +12,7 @@ from langflow.base.models.model_utils import get_model_name
from langflow.components.helpers import CurrentDateComponent
from langflow.components.helpers.memory import MemoryComponent
from langflow.components.langchain_utilities.tool_calling import ToolCallingAgentComponent
from langflow.custom.custom_component.component import _get_component_toolkit
from langflow.custom.utils import update_component_build_config
from langflow.field_typing import Tool
from langflow.io import BoolInput, DropdownInput, MultilineInput, Output
from langflow.logging import logger
from langflow.schema.dotdict import dotdict
@ -270,16 +268,3 @@ class AgentComponent(ToolCallingAgentComponent):
component_class, build_config, field_value, "model_name"
)
return dotdict({k: v.to_dict() if hasattr(v, "to_dict") else v for k, v in build_config.items()})
async def to_toolkit(self) -> list[Tool]:
component_toolkit = _get_component_toolkit()
tools_names = self._build_tools_names()
agent_description = self.get_tool_description()
# 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

View file

@ -2,8 +2,6 @@ from langchain.agents import create_tool_calling_agent
from langchain_core.prompts import ChatPromptTemplate
from langflow.base.agents.agent import LCToolsAgentComponent
from langflow.custom.custom_component.component import _get_component_toolkit
from langflow.field_typing import Tool
from langflow.inputs import MessageTextInput
from langflow.inputs.inputs import DataInput, HandleInput
from langflow.schema import Data
@ -56,11 +54,3 @@ class ToolCallingAgentComponent(LCToolsAgentComponent):
except NotImplementedError as e:
message = f"{self.display_name} does not support tool calling. Please try using a compatible model."
raise NotImplementedError(message) from e
async def to_toolkit(self) -> list[Tool]:
component_toolkit = _get_component_toolkit()
toolkit = component_toolkit(component=self)
tools = toolkit.get_tools(callbacks=self.get_langchain_callbacks())
if hasattr(self, "tools_metadata"):
tools = toolkit.update_tools_metadata(tools=tools)
return tools

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long