feat: Add support for sync operations #15
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR introduces asynchronous support for the
ToolboxClient
by proxying newAsyncToolboxClient
andAsyncToolboxTool
classes that provide purely asynchronous interfaces.ToolboxClient
andToolboxTool
classes act as wrappers aroundAsyncToolboxClient
andAsyncToolboxTool
respectively, providing both synchronous and asynchronous methods.The synchronous methods are implemented by utilizing a dedicated background event loop running in a separate thread. When a synchronous method is called, it delegates the operation to the underlying
AsyncToolboxClient
orAsyncToolboxtool
, usingasyncio.run_coroutine_threadsafe
and blocks until the result is available. This approach allows existing synchronous code to seamlessly interact with the new asynchronous capabilities.Key changes:
AsyncToolboxClient
: A fully asynchronous interface for toolbox operations. This class is similar to theToolboxClient
class before this change. It adds the new async interfacesaload_tool
andaload_toolset
.AsyncToolboxTool
: A fully asynchronous interface for toolbox tool invocations and validations. This class is similar to theToolboxTool
class before this change and implements the_arun
method of LangChain'sBaseTool
.ToolboxClient
: A wrapper class exposing both synchronous and asynchronous methods, delegating toAsyncToolboxClient
under the hood.ToolboxTool
: A wrapper class exposing both synchronous and asynchronous methods, delegating toAsyncToolboxTool
under the hood.Benefit
This approach allows us to modernize the Toolbox LangChain SDK while ensuring backward compatibility and providing users with the flexibility to choose between synchronous and asynchronous methods.
Diagram
Note
README
updates are done in #16.