Python: Fix OAuth consent event forwarding in as_tool()#4578
Open
coding-shalabh wants to merge 1 commit intomicrosoft:mainfrom
Open
Python: Fix OAuth consent event forwarding in as_tool()#4578coding-shalabh wants to merge 1 commit intomicrosoft:mainfrom
coding-shalabh wants to merge 1 commit intomicrosoft:mainfrom
Conversation
Fixes microsoft#4499 Adds exception-based OAuth consent event forwarding to enable proper OAuth flows when using agents as tools. Changes: - Added OAuthConsentRequiredException to exceptions.py - Modified as_tool() to detect oauth_consent_request events in both streaming and non-streaming modes - Raises OAuthConsentRequiredException with consent_url when OAuth consent is required - Parent agents can now catch this exception and forward the consent request to the user This implements the exception-based approach (Option A) discussed in issue microsoft#4499, allowing proper OAuth flow handling when wrapping agents as tools. The fix ensures that OAuth consent requests are not silently swallowed when using as_tool(), enabling proper multi-agent OAuth workflows.
Author
|
@microsoft-github-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #4499
Adds exception-based OAuth consent event forwarding to enable proper OAuth flows when using agents as tools.
Changes Made
New Exception Class
Added
OAuthConsentRequiredExceptionto exceptions.py:114-131:consent_urlattribute for the OAuth consent URLModified as_tool() Method
Updated
as_tool()in _agents.py:533-561:OAuthConsentRequiredExceptionwith the consent URLImplementation Details
This implements the exception-based approach (Option A) discussed in issue #4499.
Detection logic:
Parent agent handling:
Why This Change?
Currently, when using
as_tool()to wrap an agent, OAuth consent request events are silently discarded because the method only returns.text. This makes proper OAuth flows impossible in multi-agent scenarios.This fix enables:
Testing Recommendations
oauth_consent_requesteventsas_tool()OAuthConsentRequiredExceptionis raised with correct consent_urlRelated Issues
Closes #4499