@@ -84,11 +84,21 @@ async def aload_tool(
84
84
)
85
85
auth_token_getters = auth_tokens
86
86
87
- core_tool = await self .__core_sync_client ._ToolboxSyncClient__async_client .load_tool (
87
+ coro = self .__core_sync_client ._ToolboxSyncClient__async_client .load_tool (
88
88
name = tool_name ,
89
89
auth_token_getters = auth_token_getters ,
90
90
bound_params = bound_params
91
91
)
92
+
93
+ # If a loop has not been provided, attempt to run in current thread.
94
+ if not self .__core_sync_client ._ToolboxSyncClient__loop :
95
+ return await coro
96
+
97
+ # Otherwise, run in the background thread.
98
+ core_tool = await asyncio .wrap_future (
99
+ asyncio .run_coroutine_threadsafe (coro , self .__core_sync_client ._ToolboxSyncClient__loop )
100
+ )
101
+
92
102
return ToolboxTool (core_tool = core_tool )
93
103
94
104
async def aload_toolset (
@@ -148,16 +158,25 @@ async def aload_toolset(
148
158
)
149
159
auth_token_getters = auth_tokens
150
160
151
- core_tools = await self .__core_sync_client ._ToolboxSyncClient__async_client .load_toolset (
161
+ coro = self .__core_sync_client ._ToolboxSyncClient__async_client .load_toolset (
152
162
name = toolset_name ,
153
163
auth_token_getters = auth_token_getters ,
154
164
bound_params = bound_params ,
155
165
strict = strict
156
166
)
157
167
168
+ # If a loop has not been provided, attempt to run in current thread.
169
+ if not self .__core_sync_client ._ToolboxSyncClient__loop :
170
+ return await coro
171
+
172
+ # Otherwise, run in the background thread.
173
+ core_tools = await asyncio .wrap_future (
174
+ asyncio .run_coroutine_threadsafe (coro , self .__core_sync_client ._ToolboxSyncClient__loop )
175
+ )
176
+
158
177
tools = []
159
178
for core_tool in core_tools :
160
- tools .append (ToolboxTool (core_tool_instance = core_tool ))
179
+ tools .append (ToolboxTool (core_tool = core_tool ))
161
180
return tools
162
181
163
182
def load_tool (
@@ -282,5 +301,5 @@ def load_toolset(
282
301
283
302
tools = []
284
303
for core_tool in core_tools :
285
- tools .append (ToolboxTool (core_tool_instance = core_tool ))
304
+ tools .append (ToolboxTool (core_tool = core_tool ))
286
305
return tools
0 commit comments