Skip to content

Comments

Python: Fix: Parse oauth_consent_request events in Azure AI client #4197

Open
giles17 wants to merge 1 commit intomicrosoft:mainfrom
giles17:oauth_event_fix
Open

Python: Fix: Parse oauth_consent_request events in Azure AI client #4197
giles17 wants to merge 1 commit intomicrosoft:mainfrom
giles17:oauth_event_fix

Conversation

@giles17
Copy link
Contributor

@giles17 giles17 commented Feb 23, 2026

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)

  • Add oauth_consent_request to ContentType literal
  • Add consent_link field to Content.init
  • Add Content.from_oauth_consent_request() factory method (with user_input_request=True)
  • Add consent_link to to_dict() serialization

Azure AI Client (agent_framework_azure_ai/_client.py)

  • Override _parse_response_from_openai to detect oauth_consent_request output items after base parsing
  • Override _parse_chunk_from_openai to intercept response.output_item.added events with oauth_consent_request items before delegating to base parser

AG-UI (agent_framework_ag_ui/_run_common.py)

  • Add _emit_oauth_consent() helper emitting CustomEvent for frontends
  • Wire into _emit_content() for the new content type

Tests

  • Core: creation + serialization roundtrip tests
  • Azure AI: streaming + non-streaming parser tests, plus a before/after test proving the base parser drops the event while the override catches it
  • AG-UI: emission tests with and without consent_link

…#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>
Copilot AI review requested due to automatic review settings February 23, 2026 22:44
@github-actions github-actions bot changed the title Fix: Parse oauth_consent_request events in Azure AI client (#3950) Python: Fix: Parse oauth_consent_request events in Azure AI client (#3950) Feb 23, 2026
@giles17 giles17 changed the title Python: Fix: Parse oauth_consent_request events in Azure AI client (#3950) Python: Fix: Parse oauth_consent_request events in Azure AI client Feb 23, 2026
@markwallace-microsoft
Copy link
Member

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/ag-ui/agent_framework_ag_ui
   _run_common.py2013184%46, 51–52, 54, 61, 65, 69–70, 72, 96, 173, 191–192, 204–205, 219, 246–248, 273–274, 280–285, 380, 382, 387–388
packages/azure-ai/agent_framework_azure_ai
   _client.py2964186%382, 384, 427, 435–447, 460, 520, 535–540, 583, 604–605, 630, 638, 673, 675, 708, 916, 919, 922–923, 925–928, 971
packages/core/agent_framework
   _types.py10028791%49, 58–59, 113, 118, 137, 139, 143, 147, 149, 151, 153, 171, 175, 201, 223, 228, 233, 237, 263, 267, 619–620, 1022, 1085, 1102, 1120, 1125, 1143, 1153, 1170–1171, 1173, 1191–1192, 1194, 1201–1202, 1204, 1239, 1250–1251, 1253, 1291, 1518, 1570, 1661–1666, 1688, 1693, 1859, 1871, 2114, 2123, 2144, 2239, 2468, 2675, 2745, 2757, 2775, 2973–2975, 2978–2980, 2984, 2989, 2993, 3077–3079, 3108, 3162, 3181–3182, 3185–3189, 3195
   observability.py6258286%354, 356–358, 361–363, 368–369, 375–376, 382–383, 390, 392–394, 397–399, 404–405, 411–412, 418–419, 426, 464, 555, 697, 700, 708–709, 712–715, 717, 720–722, 725–726, 754, 756, 767–769, 771–773, 777, 785, 886, 888, 1037, 1039, 1043–1048, 1050, 1053–1057, 1059, 1168–1169, 1171, 1228–1229, 1364, 1534, 1537, 1596, 1764, 1918, 1920
packages/core/agent_framework/openai
   _chat_client.py2812491%210, 240–241, 245, 363, 370, 446–453, 455–458, 468, 546, 548, 564, 610, 626
TOTAL22182347684% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
4271 240 💤 0 ❌ 0 🔥 1m 13s ⏱️

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_request content type to the core framework with a consent_link field
  • 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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and this logic will silently ignore other content types? And that seems inconsistent with the non-streaming flow?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: response.oauth_consent_requested events silently dropped - OAuth consent link never surfaces to callers

3 participants