From a0ef3003690e42a86d0d42a720e32c96fa444088 Mon Sep 17 00:00:00 2001 From: Jeremiah Lowin <153965+jlowin@users.noreply.github.com> Date: Fri, 13 Sep 2024 06:50:41 -0400 Subject: [PATCH 1/2] Improve gemini support --- src/controlflow/tools/tools.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/controlflow/tools/tools.py b/src/controlflow/tools/tools.py index c678a89c..2ecc72be 100644 --- a/src/controlflow/tools/tools.py +++ b/src/controlflow/tools/tools.py @@ -51,10 +51,17 @@ class Tool(ControlFlowModel): metadata: dict = {} fn: Callable = Field(None, exclude=True) + _lc_tool: Optional[langchain_core.tools.BaseTool] = None def to_lc_tool(self) -> dict: - payload = self.model_dump(include={"name", "description", "parameters"}) - return dict(type="function", function=payload) + if self._lc_tool is None: + self._lc_tool = langchain_core.tools.StructuredTool.from_function( + self.fn, + name=self.name, + description=self.description, + ) + + return self._lc_tool @prefect_task(task_run_name="Tool call: {self.name}") def run(self, input: dict): From c3046bfaf2692f60def3738ee9793401ccb64dc8 Mon Sep 17 00:00:00 2001 From: Jeremiah Lowin <153965+jlowin@users.noreply.github.com> Date: Fri, 13 Sep 2024 06:58:48 -0400 Subject: [PATCH 2/2] Update tools.py --- src/controlflow/tools/tools.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/controlflow/tools/tools.py b/src/controlflow/tools/tools.py index 2ecc72be..683f09e4 100644 --- a/src/controlflow/tools/tools.py +++ b/src/controlflow/tools/tools.py @@ -54,14 +54,8 @@ class Tool(ControlFlowModel): _lc_tool: Optional[langchain_core.tools.BaseTool] = None def to_lc_tool(self) -> dict: - if self._lc_tool is None: - self._lc_tool = langchain_core.tools.StructuredTool.from_function( - self.fn, - name=self.name, - description=self.description, - ) - - return self._lc_tool + payload = self.model_dump(include={"name", "description", "parameters"}) + return payload @prefect_task(task_run_name="Tool call: {self.name}") def run(self, input: dict):