fix: fixes langchain tool calling agent component toolkit (#5878)
* update tool kit in tool calling agent * lint error * Update agent.py * [autofix.ci] apply automated fixes * format errors * [autofix.ci] apply automated fixes * [autofix.ci] apply automated fixes (attempt 2/3) * Update component_tool.py * [autofix.ci] apply automated fixes * Refactor tool calling logic for improved readability and efficiency * Add tool_mode parameter to agent outputs * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
This commit is contained in:
parent
58043362b5
commit
e15fddd3aa
11 changed files with 38 additions and 13 deletions
|
|
@ -69,7 +69,7 @@ class LCAgentComponent(Component):
|
|||
]
|
||||
|
||||
outputs = [
|
||||
Output(display_name="Agent", name="agent", method="build_agent", hidden=True),
|
||||
Output(display_name="Agent", name="agent", method="build_agent", hidden=True, tool_mode=False),
|
||||
Output(display_name="Response", name="response", method="message_response"),
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,9 @@ 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
|
||||
|
|
@ -264,3 +266,16 @@ 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
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ class CSVAgentComponent(LCAgentComponent):
|
|||
|
||||
outputs = [
|
||||
Output(display_name="Response", name="response", method="build_agent_response"),
|
||||
Output(display_name="Agent", name="agent", method="build_agent", hidden=True),
|
||||
Output(display_name="Agent", name="agent", method="build_agent", hidden=True, tool_mode=False),
|
||||
]
|
||||
|
||||
def _path(self) -> str:
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ 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
|
||||
|
|
@ -54,3 +56,11 @@ 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
Loading…
Add table
Add a link
Reference in a new issue