Skip to content

Commit

Permalink
fix: fixes langchain tool calling agent component toolkit (#5878)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
3 people authored Jan 31, 2025
1 parent 5804336 commit e15fddd
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 13 deletions.
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.

0 comments on commit e15fddd

Please sign in to comment.