26
26
27
27
class ToolboxSyncClient :
28
28
"""
29
- A synchronous client for interacting with a Toolbox service.
29
+ An synchronous client for interacting with a Toolbox service.
30
30
31
31
Provides methods to discover and load tools defined by a remote Toolbox
32
- service endpoint, returning synchronous tool wrappers (`ToolboxSyncTool`).
33
- It manages an underlying asynchronous `ToolboxClient`.
32
+ service endpoint.
34
33
"""
35
34
36
35
__session : Optional [ClientSession ] = None
@@ -42,7 +41,7 @@ def __init__(
42
41
url : str ,
43
42
):
44
43
"""
45
- Initializes the ToolboxSyncClient .
44
+ Initializes the ToolboxClient .
46
45
47
46
Args:
48
47
url: The base URL for the Toolbox service API (e.g., "http://localhost:5000").
@@ -91,31 +90,45 @@ async def __run_as_async(self, coro: Awaitable[T]) -> T:
91
90
asyncio .run_coroutine_threadsafe (coro , self .__loop )
92
91
)
93
92
93
+ def close (self ):
94
+ """
95
+ Synchronously closes the underlying client session. Doing so will cause
96
+ any tools created by this Client to cease to function.
97
+
98
+ If the session was provided externally during initialization, the caller
99
+ is responsible for its lifecycle, but calling close here will still
100
+ attempt to close it.
101
+ """
102
+ coro = self .__session .close ()
103
+ self .__run_as_sync (coro )
104
+
94
105
def load_tool (
95
106
self ,
96
- tool_name : str ,
107
+ name : str ,
97
108
auth_token_getters : dict [str , Callable [[], str ]] = {},
98
109
bound_params : Mapping [str , Union [Callable [[], Any ], Any ]] = {},
99
110
) -> ToolboxSyncTool :
100
111
"""
101
112
Synchronously loads a tool from the server.
102
113
103
- Retrieves the schema for the specified tool and returns a callable,
104
- synchronous object (`ToolboxSyncTool`) that can be used to invoke the
114
+ Retrieves the schema for the specified tool from the Toolbox server and
115
+ returns a callable object (`ToolboxSyncTool`) that can be used to invoke the
105
116
tool remotely.
106
117
107
118
Args:
108
- tool_name: Name of the tool to load.
119
+ name: The unique name or identifier of the tool to load.
109
120
auth_token_getters: A mapping of authentication service names to
110
121
callables that return the corresponding authentication token.
111
122
bound_params: A mapping of parameter names to bind to specific values or
112
123
callables that are called to produce values as needed.
113
124
114
125
Returns:
115
- ToolboxSyncTool: A synchronous callable object representing the loaded tool.
126
+ ToolboxSyncTool: A callable object representing the loaded tool, ready
127
+ for execution. The specific arguments and behavior of the callable
128
+ depend on the tool itself.
116
129
"""
117
130
async_tool = self .__run_as_sync (
118
- self .__async_client .load_tool (tool_name , auth_token_getters , bound_params )
131
+ self .__async_client .load_tool (name , auth_token_getters , bound_params )
119
132
)
120
133
121
134
if not self .__loop or not self .__thread :
@@ -124,27 +137,27 @@ def load_tool(
124
137
125
138
def load_toolset (
126
139
self ,
127
- toolset_name : str ,
140
+ name : str ,
128
141
auth_token_getters : dict [str , Callable [[], str ]] = {},
129
142
bound_params : Mapping [str , Union [Callable [[], Any ], Any ]] = {},
130
143
) -> list [ToolboxSyncTool ]:
131
144
"""
132
145
Synchronously fetches a toolset and loads all tools defined within it.
133
146
134
147
Args:
135
- toolset_name : Name of the toolset to load tools from .
148
+ name : Name of the toolset to load tools.
136
149
auth_token_getters: A mapping of authentication service names to
137
150
callables that return the corresponding authentication token.
138
151
bound_params: A mapping of parameter names to bind to specific values or
139
152
callables that are called to produce values as needed.
140
153
141
154
Returns:
142
- list[ToolboxSyncTool]: A list of synchronous callables, one for each
143
- tool defined in the toolset.
155
+ list[ToolboxSyncTool]: A list of callables, one for each tool defined
156
+ in the toolset.
144
157
"""
145
158
async_tools = self .__run_as_sync (
146
159
self .__async_client .load_toolset (
147
- toolset_name , auth_token_getters , bound_params
160
+ name , auth_token_getters , bound_params
148
161
)
149
162
)
150
163
@@ -155,12 +168,6 @@ def load_toolset(
155
168
tools .append (ToolboxSyncTool (async_tool , self .__loop , self .__thread ))
156
169
return tools
157
170
158
- def close (self ):
159
- """
160
- Synchronously closes the client session if it was created internally by the client.
161
- """
162
- coro = self .__session .close ()
163
- self .__run_as_sync (coro )
164
171
165
172
def __enter__ (self ):
166
173
"""Enter the runtime context related to this client instance."""
0 commit comments