Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixes langchain tool calling agent component toolkit #5878

Merged
merged 12 commits into from
Jan 31, 2025
2 changes: 1 addition & 1 deletion src/backend/base/langflow/base/agents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]

Expand Down
15 changes: 15 additions & 0 deletions src/backend/base/langflow/components/agents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
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
Expand Down Expand Up @@ -264,3 +266,16 @@ async def update_build_config(
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
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
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
Expand Down Expand Up @@ -54,3 +56,11 @@ def create_agent_runnable(self):
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

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading