Python: Fix: Parse oauth_consent_request events in Azure AI client #4197
Open
giles17 wants to merge 1 commit intomicrosoft:mainfrom
Open
Python: Fix: Parse oauth_consent_request events in Azure AI client #4197giles17 wants to merge 1 commit intomicrosoft:mainfrom
giles17 wants to merge 1 commit intomicrosoft:mainfrom
Conversation
…#3950) When Azure AI Agent Service returns an oauth_consent_request output item for OAuth-protected MCP tools, the base OpenAI responses parser drops it (hits case _ default branch). This causes agent runs to complete silently with zero content. Changes: - Add oauth_consent_request ContentType and Content.from_oauth_consent_request() factory with consent_link field and user_input_request=True - Override _parse_response_from_openai and _parse_chunk_from_openai in RawAzureAIClient to intercept Azure-specific oauth_consent_request items - Add _emit_oauth_consent helper in AG-UI to emit CustomEvent for frontends - Add tests proving base parser drops the event and Azure AI override catches it Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Member
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes issue #3950 where OAuth consent request events from Azure AI Agent Service were silently dropped, preventing users from being notified when OAuth consent is required for MCP tools.
Changes:
- Added
oauth_consent_requestcontent type to the core framework with aconsent_linkfield - Extended Azure AI client to parse OAuth consent request output items in both streaming and non-streaming responses
- Updated AG-UI to emit OAuth consent requests as custom events for frontend rendering
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
python/packages/core/agent_framework/_types.py |
Added oauth_consent_request to ContentType literal, added consent_link field to Content class, implemented from_oauth_consent_request() factory method, and updated to_dict() serialization |
python/packages/core/tests/core/test_types.py |
Added unit tests for OAuth consent request content creation and serialization |
python/packages/azure-ai/agent_framework_azure_ai/_client.py |
Overrode _parse_response_from_openai and _parse_chunk_from_openai to handle Azure-specific oauth_consent_request output items before they're dropped by the base parser |
python/packages/azure-ai/tests/test_azure_ai_client.py |
Added tests for parsing OAuth consent requests in both streaming and non-streaming scenarios |
python/packages/ag-ui/agent_framework_ag_ui/_run_common.py |
Added _emit_oauth_consent() helper and wired it into _emit_content() to emit CustomEvent for frontends |
python/packages/ag-ui/tests/ag_ui/test_run.py |
Added tests for OAuth consent request event emission with and without consent_link |
python/packages/core/agent_framework/openai/_chat_client.py |
Auto-formatting changes only (line length adjustments) |
python/packages/core/agent_framework/observability.py |
Removed unused SpanAttributes import and auto-formatting |
| for item in response.output: | ||
| if item.type == "oauth_consent_request": | ||
| consent_link = item.consent_link | ||
| if consent_link and result.messages: |
Member
There was a problem hiding this comment.
this logic will mean it drops silently if the result.messages list is empty, probably not intended?
| ) -> ChatResponseUpdate: | ||
| """Parse an Azure AI streaming event, handling Azure-specific event types.""" | ||
| # Intercept output_item.added events for Azure-specific item types | ||
| if event.type == "response.output_item.added" and event.item.type == "oauth_consent_request": |
Member
There was a problem hiding this comment.
and this logic will silently ignore other content types? And that seems inconsistent with the non-streaming flow?
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 #3950 - When Azure AI Agent Service returns an oauth_consent_request output item for OAuth-protected MCP tools, the SDK silently drops it, causing agent runs to complete with zero content.
Root Cause
The oauth_consent_request item type is Azure-specific (defined in azure.ai.projects.models.OAuthConsentRequestItemResource), not part of the OpenAI SDK type union. The base RawOpenAIResponsesClient parser hits the default branch and logs Unparsed event, discarding the event.
Changes
Core (agent_framework/_types.py)
Azure AI Client (agent_framework_azure_ai/_client.py)
AG-UI (agent_framework_ag_ui/_run_common.py)
Tests