Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(toolbox-langchain): Support per-invocation auth viaRunnableConfig#291

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
anubhav756 wants to merge4 commits intoanubhav-state-li
base:anubhav-state-li
Choose a base branch
Loading
fromanubhav-self-auth-tools

Conversation

@anubhav756
Copy link
Contributor

@anubhav756anubhav756 commentedJun 19, 2025
edited
Loading

Summary

This PR introduces a major enhancement to thetoolbox-langchain package by adding support for dynamic, per-invocation authentication. This is achieved by readingauth_token_getters from LangChain's standardRunnableConfig, enablingToolboxTool to be used safely and effectively in multi-user environments like LangGraph.

Motivation

Currently, authentication tokens can only be provided to aToolboxTool at initialization time, either viaToolboxClient.load_tool/load_toolset or by callingtool.add_auth_token_getters() on the tool instance. This static binding of credentials poses a significant challenge in modern agentic frameworks like LangGraph.

Challenge

In LangGraph, a single graph containing tool instances is often created once and then shared across multiple users and requests. It is insecure and impractical to configure these shared tool instances with any single user's credentials. The required credentials must be provided dynamically, on a per-request basis.

Proposed Solution

This PR solves this problem by introducing a third, invocation-time method for providing auth. It leverages LangChain's idiomaticRunnableConfig as the vehicle for passing request-specific authentication, makingtoolbox-langchain fully compatible with multi-tenant and shared-use patterns.

Description of Changes

The core of this change lies in how theToolboxTool handles an invocation:

  • The tool's invocation method (_arun/_run) is updated to accept theconfig: RunnableConfig argument, which is standard in the LangChain.
  • The tool inspects the config for a specific key:config["configurable"]["auth_token_getters"].
  • Ifauth_token_getters are found in the config, the tool:
    a. Introspects its own authentication and authorization requirements (using the properties exposed infix(toolbox-core): Expose authorization token requirements onToolboxTool #294).
    b. Creates a temporary, in-memory copy of the underlying proxiedToolboxTool. This is critical, as it ensures the original shared tool instance is never mutated.
  • Theauth_token_getters from theconfig are applied to this new, temporary copy of the tool using itsadd_auth_token_getters method.
  • The actual tool execution is performed using this temporary, request-specific authenticated tool instance.

This mechanism provides a thread-safe and secure way to handle user-specific credentials without affecting the shared state of the primary tool in the graph.

Usage Example

fromlangchain_core.runnablesimportRunnableConfig# Define the per-invocation configuration with the user's token getterconfig=RunnableConfig(configurable={"auth_token_getters": {"my-google-auth":lambda:"<TOKEN>"        }    })...result=awaitagent_executor.ainvoke(    {"input":"Search for rows by my user ID"},config=config)

@anubhav756
Copy link
ContributorAuthor

/gcbrun

@anubhav756anubhav756force-pushed theanubhav-self-auth-tools branch from336b8d5 to0f50eb0CompareJune 19, 2025 14:32
@anubhav756anubhav756 marked this pull request as ready for reviewJune 19, 2025 14:43
@anubhav756anubhav756 requested a review froma team as acode ownerJune 19, 2025 14:43
@anubhav756anubhav756 changed the titlefeat(toolbox-langchain): Implement self-authenticated toolsfeat(toolbox-langchain): Support per-invocation auth viaRunnableConfigJun 19, 2025
@twishabansal
Copy link
Contributor

In LangGraph, a single graph containing tool instances is often created once and then shared across multiple users and requests. It is insecure and impractical to configure these shared tool instances with any single user's credentials.

In this case, we expect users to use dynamic methods for fetching tokens like getGoogleIdToken.
Does the user need to hardcode any credentials?

@anubhav756
Copy link
ContributorAuthor

In LangGraph, a single graph containing tool instances is often created once and then shared across multiple users and requests. It is insecure and impractical to configure these shared tool instances with any single user's credentials.

In this case, we expect users to use dynamic methods for fetching tokens like getGoogleIdToken. Does the user need to hardcode any credentials?

Not necessarily in such a function like this one. For instance the app dev could fetch the user ID token from the frontend through a login button, and the app ID could be injected as an env var. Does that make sense?

@anubhav756anubhav756force-pushed theanubhav-self-auth-tools branch from09410c4 tof41566aCompareJune 24, 2025 12:43
@anubhav756anubhav756force-pushed theanubhav-self-auth-tools branch 2 times, most recently from57fd562 to4e53bc0CompareJuly 2, 2025 20:01
anubhav756 added a commit to GoogleCloudPlatform/cymbal-air-toolbox-demo that referenced this pull requestJul 3, 2025
* Remove client session management from the orchestration class  * This is now managed by Toolbox SDK internally* Simplify prompt creation  * This is handled by the respective tools* Tools descriptions, params, annotations, etc. are loaded from Toolbox  * These are added through `bind_tools` from LangGraph* This enables removal of the custom response message creation (whichwas added as a `TODO`)* Add logged in user's token to the `RunnableConfig`* This is necessary so that the tools that require authentication canread the user's token if available* Simplify tools helper file by removing tools and helpers since thoseare now handled by Toolbox SDK internally* Add a Toolbox URL to connect to through integration tests* Removes `ToolMessage` while inserting ticket.  * This was causing an issue with `langchain-google-vertexai`  ```google.api_core.exceptions.InvalidArgument: 400 Please ensure that thenumber of function response parts should be equal to number of functioncall parts of the function call turn.  ```* Remove unused human and AI messages post book ticket flow.## Diagram![image](https://github.com/user-attachments/assets/46af0a74-3395-45a8-8ff4-f5466b034f17)> [!IMPORTANT]> This PR depends on a couple of features from Toolbox SDK:> * Support for optional parameters([#290](googleapis/mcp-toolbox-sdk-python#290))> * Self-authenticated tools via `RunnableConfig`([#291](googleapis/mcp-toolbox-sdk-python#291))> [!NOTE]> The failure in the integration test is expected. This PR is part of aseries of changes, and the corresponding fix for this test is in asubsequent PR.> ### Reasoning> We've intentionally split the work into smaller, focused PRs to makethe review process more manageable and efficient.> ### Merge Plan> All related PRs will be merged into the `toolbox-main` branch first.We will ensure all tests are passing on `toolbox-main` before mergingthe entire feature set into `main`.
@anubhav756anubhav756force-pushed theanubhav-self-auth-tools branch from4e53bc0 to76c6fa4CompareJuly 11, 2025 05:06
@anubhav756anubhav756force-pushed theanubhav-self-auth-tools branch from76c6fa4 to5607a2cCompareJuly 21, 2025 07:13
@anubhav756anubhav756force-pushed theanubhav-state-li branch 2 times, most recently from35f5cf7 todac36c5CompareJuly 21, 2025 07:16
@anubhav756anubhav756force-pushed theanubhav-self-auth-tools branch from5607a2c to6f8cbfcCompareJuly 21, 2025 07:16
anubhav756 added a commit to GoogleCloudPlatform/cymbal-air-toolbox-demo that referenced this pull requestJul 23, 2025
This PR updates the existing workflow to replace the prebuilt tool nodewith a new custom tool node. This new node is designed to intelligentlyhandle tool auth by reading auth headers from the provided`RunnableConfig` by LangGraph.The custom node inspects the auth requirements of the underlying coretool within the `ToolboxTool`. If the tool requires authentication, thenode dynamically creates an authenticated copy of the tool by attachingthe necessary auth token getters using the `add_auth_token_getter` API.This authenticated tool instance is then used for the call andsubsequently discarded. This same auth handling logic has also beenapplied to the node responsible for ticket insertion.> [!NOTE]> The functionality introduced in these custom nodes will be abstractedinto the `ToolboxTool` itself in an upcoming release of the`toolbox-langchain`[#291](googleapis/mcp-toolbox-sdk-python#291).This will simplify the workflow in the future by handling authenticationdirectly within the tool.
@anubhav756anubhav756 marked this pull request as draftSeptember 8, 2025 06:47
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@kurtisvgkurtisvgAwaiting requested review from kurtisvg

@twishabansaltwishabansalAwaiting requested review from twishabansal

Assignees

@anubhav756anubhav756

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@anubhav756@twishabansal

[8]ページ先頭

©2009-2025 Movatter.jp