Skip to content

Commit f6f7af9

Browse files
committed
fix(langchain-sdk): Inherit from BaseTool and implement placeholder _run method.
This is some ground-work before we add sync tool calls support to ToolboxTool.
1 parent e1b6420 commit f6f7af9

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/toolbox_langchain_sdk/tools.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from warnings import warn
1818

1919
from aiohttp import ClientSession
20-
from langchain_core.tools import StructuredTool
20+
from langchain_core.tools import BaseTool
2121
from typing_extensions import Self
2222

2323
from .utils import (
@@ -30,7 +30,7 @@
3030
)
3131

3232

33-
class ToolboxTool(StructuredTool):
33+
class ToolboxTool(BaseTool):
3434
"""
3535
A subclass of LangChain's StructuredTool that supports features specific to
3636
Toolbox, like bound parameters and authenticated tools.
@@ -120,8 +120,6 @@ def __init__(
120120
# Due to how pydantic works, we must initialize the underlying
121121
# StructuredTool class before assigning values to member variables.
122122
super().__init__(
123-
coroutine=self.__tool_func,
124-
func=None,
125123
name=name,
126124
description=schema.description,
127125
args_schema=_schema_to_model(model_name=name, schema=schema.parameters),
@@ -139,7 +137,7 @@ def __init__(
139137
# tool invocation.
140138
self.__validate_auth(strict=False)
141139

142-
async def __tool_func(self, **kwargs: Any) -> dict:
140+
async def _arun(self, **kwargs: Any) -> dict[str, Any]:
143141
"""
144142
The coroutine that invokes the tool with the given arguments.
145143
@@ -171,6 +169,9 @@ async def __tool_func(self, **kwargs: Any) -> dict:
171169
self._url, self._session, self._name, kwargs, self._auth_tokens
172170
)
173171

172+
def _run(self, **kwargs: Any) -> dict[str, Any]:
173+
raise NotImplementedError("Sync tool calls not supported yet.")
174+
174175
def __validate_auth(self, strict: bool = True) -> None:
175176
"""
176177
Checks if a tool meets the authentication requirements.

tests/test_tools.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,14 @@ async def test_toolbox_tool_call(toolbox_tool):
268268
assert result == {"result": "test-result"}
269269

270270

271+
@pytest.mark.asyncio
272+
async def test_toolbox_sync_tool_call_(toolbox_tool):
273+
async for tool in toolbox_tool:
274+
with pytest.raises(NotImplementedError) as e:
275+
result = tool.invoke({"param1": "test-value", "param2": 123})
276+
assert "Sync tool calls not supported yet." in str(e.value)
277+
278+
271279
@pytest.mark.asyncio
272280
async def test_toolbox_tool_call_with_bound_params(toolbox_tool):
273281
async for tool in toolbox_tool:

0 commit comments

Comments
 (0)