Skip to content

Commit e15fddd

Browse files
edwinjosechittilappillyautofix-ci[bot]ogabrielluiz
authored
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>
1 parent 5804336 commit e15fddd

File tree

11 files changed

+38
-13
lines changed

11 files changed

+38
-13
lines changed

src/backend/base/langflow/base/agents/agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class LCAgentComponent(Component):
6969
]
7070

7171
outputs = [
72-
Output(display_name="Agent", name="agent", method="build_agent", hidden=True),
72+
Output(display_name="Agent", name="agent", method="build_agent", hidden=True, tool_mode=False),
7373
Output(display_name="Response", name="response", method="message_response"),
7474
]
7575

src/backend/base/langflow/components/agents/agent.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
from langflow.components.helpers import CurrentDateComponent
1111
from langflow.components.helpers.memory import MemoryComponent
1212
from langflow.components.langchain_utilities.tool_calling import ToolCallingAgentComponent
13+
from langflow.custom.custom_component.component import _get_component_toolkit
1314
from langflow.custom.utils import update_component_build_config
15+
from langflow.field_typing import Tool
1416
from langflow.io import BoolInput, DropdownInput, MultilineInput, Output
1517
from langflow.logging import logger
1618
from langflow.schema.dotdict import dotdict
@@ -264,3 +266,16 @@ async def update_build_config(
264266
component_class, build_config, field_value, "model_name"
265267
)
266268
return dotdict({k: v.to_dict() if hasattr(v, "to_dict") else v for k, v in build_config.items()})
269+
270+
async def to_toolkit(self) -> list[Tool]:
271+
component_toolkit = _get_component_toolkit()
272+
tools_names = self._build_tools_names()
273+
agent_description = self.get_tool_description()
274+
# TODO: Agent Description Depreciated Feature to be removed
275+
description = f"{agent_description}{tools_names}"
276+
tools = component_toolkit(component=self).get_tools(
277+
tool_name=self.get_tool_name(), tool_description=description, callbacks=self.get_langchain_callbacks()
278+
)
279+
if hasattr(self, "tools_metadata"):
280+
tools = component_toolkit(component=self, metadata=self.tools_metadata).update_tools_metadata(tools=tools)
281+
return tools

src/backend/base/langflow/components/langchain_utilities/csv_agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class CSVAgentComponent(LCAgentComponent):
5656

5757
outputs = [
5858
Output(display_name="Response", name="response", method="build_agent_response"),
59-
Output(display_name="Agent", name="agent", method="build_agent", hidden=True),
59+
Output(display_name="Agent", name="agent", method="build_agent", hidden=True, tool_mode=False),
6060
]
6161

6262
def _path(self) -> str:

src/backend/base/langflow/components/langchain_utilities/tool_calling.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from langchain_core.prompts import ChatPromptTemplate
33

44
from langflow.base.agents.agent import LCToolsAgentComponent
5+
from langflow.custom.custom_component.component import _get_component_toolkit
6+
from langflow.field_typing import Tool
57
from langflow.inputs import MessageTextInput
68
from langflow.inputs.inputs import DataInput, HandleInput
79
from langflow.schema import Data
@@ -54,3 +56,11 @@ def create_agent_runnable(self):
5456
except NotImplementedError as e:
5557
message = f"{self.display_name} does not support tool calling. Please try using a compatible model."
5658
raise NotImplementedError(message) from e
59+
60+
async def to_toolkit(self) -> list[Tool]:
61+
component_toolkit = _get_component_toolkit()
62+
toolkit = component_toolkit(component=self)
63+
tools = toolkit.get_tools(callbacks=self.get_langchain_callbacks())
64+
if hasattr(self, "tools_metadata"):
65+
tools = toolkit.update_tools_metadata(tools=tools)
66+
return tools

src/backend/base/langflow/initial_setup/starter_projects/Instagram Copywriter.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/backend/base/langflow/initial_setup/starter_projects/Market Research.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/backend/base/langflow/initial_setup/starter_projects/Research Agent.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/backend/base/langflow/initial_setup/starter_projects/SaaS Pricing.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/backend/base/langflow/initial_setup/starter_projects/Sequential Tasks Agents .json

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

src/backend/base/langflow/initial_setup/starter_projects/Simple Agent.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/backend/base/langflow/initial_setup/starter_projects/Travel Planning Agents.json

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)