Skip to content

feat: Add support for sync operations #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 5, 2025
Merged

feat: Add support for sync operations #15

merged 2 commits into from
Feb 5, 2025

Conversation

anubhav756
Copy link
Contributor

@anubhav756 anubhav756 commented Feb 5, 2025

Overview

This PR introduces asynchronous support for the ToolboxClient by proxying new AsyncToolboxClient and AsyncToolboxTool classes that provide purely asynchronous interfaces. ToolboxClient and ToolboxTool classes act as wrappers around AsyncToolboxClient and AsyncToolboxTool 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 or AsyncToolboxtool, using asyncio.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 the ToolboxClient class before this change. It adds the new async interfaces aload_tool and aload_toolset.
  • AsyncToolboxTool: A fully asynchronous interface for toolbox tool invocations and validations. This class is similar to the ToolboxTool class before this change and implements the _arun method of LangChain's BaseTool.
  • ToolboxClient: A wrapper class exposing both synchronous and asynchronous methods, delegating to AsyncToolboxClient under the hood.
  • ToolboxTool: A wrapper class exposing both synchronous and asynchronous methods, delegating to AsyncToolboxTool 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

image

Note

README updates are done in #16.

@anubhav756 anubhav756 marked this pull request as ready for review February 5, 2025 21:32
@anubhav756 anubhav756 requested a review from a team as a code owner February 5, 2025 21:32
@kurtisvg kurtisvg changed the title feat(langchain-sdk)!: Add support for sync operations in Toolbox LangChain SDK. feat: Add support for sync operations in Toolbox LangChain SDK. Feb 5, 2025
@kurtisvg kurtisvg changed the title feat: Add support for sync operations in Toolbox LangChain SDK. feat: Add support for sync operations Feb 5, 2025
anubhav756 added a commit to googleapis/genai-toolbox that referenced this pull request Feb 5, 2025
@anubhav756 anubhav756 merged commit 9885469 into main Feb 5, 2025
9 checks passed
@anubhav756 anubhav756 deleted the anubhav-sync branch February 5, 2025 22:30
@release-please release-please bot mentioned this pull request Apr 8, 2025
jeffreyrubi pushed a commit to jeffreyrubi/genai-toolbox that referenced this pull request Jun 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants