Skip to content

Commit 57786a6

Browse files
committed
fix: Fix issue causing async core tools for creating sync tools
1 parent 433339b commit 57786a6

File tree

1 file changed

+22
-16
lines changed
  • packages/toolbox-langchain/src/toolbox_langchain

1 file changed

+22
-16
lines changed

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

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
from .tools import ToolboxTool
2020
from toolbox_core.sync_client import ToolboxSyncClient as ToolboxCoreSyncClient
21+
from toolbox_core.sync_tool import ToolboxSyncTool
2122

2223

2324

@@ -90,15 +91,16 @@ async def aload_tool(
9091
bound_params=bound_params
9192
)
9293

93-
# If a loop has not been provided, attempt to run in current thread.
9494
if not self.__core_sync_client._ToolboxSyncClient__loop:
95-
return await coro
96-
97-
# Otherwise, run in the background thread.
98-
core_sync_tool = await asyncio.wrap_future(
99-
asyncio.run_coroutine_threadsafe(coro, self.__core_sync_client._ToolboxSyncClient__loop)
100-
)
101-
95+
# If a loop has not been provided, attempt to run in current thread.
96+
core_tool = await coro
97+
else:
98+
# Otherwise, run in the background thread.
99+
core_tool = await asyncio.wrap_future(
100+
asyncio.run_coroutine_threadsafe(coro, self.__core_sync_client._ToolboxSyncClient__loop)
101+
)
102+
103+
core_sync_tool = ToolboxSyncTool(core_tool, self.__core_sync_client._ToolboxSyncClient__loop, self.__core_sync_client._ToolboxSyncClient__thread)
102104
return ToolboxTool(core_sync_tool=core_sync_tool)
103105

104106
async def aload_toolset(
@@ -165,15 +167,19 @@ async def aload_toolset(
165167
strict=strict
166168
)
167169

168-
# If a loop has not been provided, attempt to run in current thread.
169170
if not self.__core_sync_client._ToolboxSyncClient__loop:
170-
return await coro
171-
172-
# Otherwise, run in the background thread.
173-
core_sync_tools = await asyncio.wrap_future(
174-
asyncio.run_coroutine_threadsafe(coro, self.__core_sync_client._ToolboxSyncClient__loop)
175-
)
176-
171+
# If a loop has not been provided, attempt to run in current thread.
172+
core_tools = await coro
173+
else:
174+
# Otherwise, run in the background thread.
175+
core_tools = await asyncio.wrap_future(
176+
asyncio.run_coroutine_threadsafe(coro, self.__core_sync_client._ToolboxSyncClient__loop)
177+
)
178+
179+
core_sync_tools = [
180+
ToolboxSyncTool(core_tool, self.__core_sync_client._ToolboxSyncClient__loop, self.__core_sync_client._ToolboxSyncClient__thread)
181+
for core_tool in core_tools
182+
]
177183
tools = []
178184
for core_sync_tool in core_sync_tools:
179185
tools.append(ToolboxTool(core_sync_tool=core_sync_tool))

0 commit comments

Comments
 (0)