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

* Fix: Parse oauth_consent_request events in Azure AI client (#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>

* addressed comment

* addressed comments

* addressed comments

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Giles Odigwe
2026-03-03 23:02:03 +00:00
committed by GitHub
co-authored by Copilot
parent 7135ed13eb
commit 2b3c401848
6 changed files with 259 additions and 0 deletions
@@ -372,6 +372,15 @@ def _emit_usage(content: Content) -> list[BaseEvent]:
return [CustomEvent(name="usage", value=usage_details)]
def _emit_oauth_consent(content: Content) -> list[BaseEvent]:
"""Emit an OAuth consent request as a custom event so frontends can render a consent link."""
return (
[CustomEvent(name="oauth_consent_request", value={"consent_link": content.consent_link})]
if content.consent_link
else []
)
def _emit_content(
content: Any,
flow: FlowState,
@@ -391,5 +400,7 @@ def _emit_content(
return _emit_approval_request(content, flow, predictive_handler, require_confirmation)
if content_type == "usage":
return _emit_usage(content)
if content_type == "oauth_consent_request":
return _emit_oauth_consent(content)
logger.debug("Skipping unsupported content type in AG-UI emitter: %s", content_type)
return []