Skip to content

Commit 993cf7e

Browse files
committed
fix: Use correct core tool interfaces in langchain tool
1 parent 60ce3cb commit 993cf7e

File tree

1 file changed

+4
-12
lines changed
  • packages/toolbox-langchain/src/toolbox_langchain

1 file changed

+4
-12
lines changed

packages/toolbox-langchain/src/toolbox_langchain/tools.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import asyncio
15+
from asyncio import wrap_future
1616
from typing import Any, Callable, Union
1717

1818
from langchain_core.tools import BaseTool
1919
from toolbox_core.sync_tool import ToolboxSyncTool as ToolboxCoreSyncTool
20+
from toolbox_core.utils import params_to_pydantic_model
2021

2122

2223
class ToolboxTool(BaseTool):
@@ -41,24 +42,15 @@ def __init__(
4142
super().__init__(
4243
name=core_tool.__name__,
4344
description=core_tool.__doc__,
44-
args_schema=core_tool._async_tool._pydantic_model,
45+
args_schema=params_to_pydantic_model(core_tool._name, core_tool._params),
4546
)
4647
self.__core_tool = core_tool
4748

4849
def _run(self, **kwargs: Any) -> str:
4950
return self.__core_tool(**kwargs)
5051

5152
async def _arun(self, **kwargs: Any) -> str:
52-
coro = self.__core_tool._async_tool(**kwargs)
53-
54-
# If a loop has not been provided, attempt to run in current thread.
55-
if not self.__core_tool._loop:
56-
return await coro
57-
58-
# Otherwise, run in the background thread.
59-
return await asyncio.wrap_future(
60-
asyncio.run_coroutine_threadsafe(coro, self.__core_tool._loop)
61-
)
53+
return await wrap_future(self.__core_tool._call_future(**kwargs))
6254

6355
def add_auth_token_getters(
6456
self, auth_token_getters: dict[str, Callable[[], str]]

0 commit comments

Comments
 (0)