Skip to content

Python: Handle invocation-time Foundry Toolbox OAuth consent - #10339

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 2 commits into
python-foundry-hosting-rcfrom
foundry-toolbox-oauth-consent
Nov 13, 2026
Merged

Eduard van Valkenburg (eavanvalkenburg) merged 2 commits into
python-foundry-hosting-rcfrom
foundry-toolbox-oauth-consent

Conversation

@eavanvalkenburg

@eavanvalkenburg Eduard van Valkenburg (eavanvalkenburg) commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Motivation & Context

Invocation-time Foundry Toolbox OAuth consent currently becomes a generic function error, leaving callers without the authorization link. Simply forwarding a consent request also leaves its function call unresolved and breaks stored continuation.

This implements the agreed consent follow-up on python-foundry-hosting-rc, targeting the feature branch for #10260 rather than opening a separate integration path.

Description & Review Guide

  • What are the major changes? Translate validated Toolbox CONSENT_REQUIRED failures into native consent requests, paired with one terminal result per interrupted invocation. Finish the authorized batch under its configured concurrency and retain successful, failed, and additional consent outcomes. Reuse native pending-batch state when another call still needs approval or input, including replacement-approval identity, caller instructions, and restored call budgets.
  • What is the impact of these changes? Stored hosted responses expose actionable consent with incomplete status, without automatically replaying completed calls. Fully terminal batches reconcile actual outputs with inference-service history before exposing consent; mixed pending batches retain their outputs until the remaining calls resolve. Streaming and non-streaming paths preserve continuation and usage accounting. store=false consent fails explicitly. Ordinary MCP failures and provider-owned consent retain their existing handling.
  • What do you want reviewers to focus on? The Toolbox-specific error and URL-validation boundary, function-call/result pairing, mixed-pause continuation without duplicate execution, and foreground service-history reconciliation. The batch-finishing behaviour follows the updated maintainer direction from the implementation discussion; it intentionally supersedes the earlier issue comments proposing that later calls be stopped. Pre-execution approval gating is unchanged; eager execution before approval remains separate work in Python: [Team][Investigation] Explore eager execution of allowed calls before approval pauses #10334.

Caller setup is unchanged. Before this change, the protected invocation produced a generic error; the same configuration now returns structured consent and a resumable incomplete response:

from agent_framework import Agent
from agent_framework_foundry_hosting import FoundryToolbox, ResponsesHostServer

toolbox = FoundryToolbox(credential, url=toolbox_url)
host = ResponsesHostServer(
    Agent(client=client, tools=toolbox),
    history_source="inference_service",
)

The function-loop specification and proposed hosting ADR describe the selected contract. Package version/dependency-floor coordination and README finalization remain separate from this change. No new public configuration API or generic MCP URL-elicitation support is introduced.

Related Issue

Fixes #10020
Fixes #9903

Both issues have explicit maintainer decisions. #10260 is the parent feature-integration PR, not a competing implementation; this PR supplies its OAuth-consent follow-up. No other open implementation PR was found for these issues.

AI Assistance

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

AI assistance details: GitHub Copilot assisted with the design, implementation, regression tests, specification and ADR updates, and this PR description.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

@agent-framework-automation agent-framework-automation Bot added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python labels Nov 13, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

MAF Automated Review — Iteration 1

Result: Findings reported
Scope: full PR (1 commit(s)): 05cb63a861fd
Model: gpt-5.6-sol

Overview

The PR translates validated invocation-time Toolbox consent failures into paired terminal results and consent actions, with substantial coverage for streaming and non-streaming execution, sibling ordering, URL validation, stored continuation, and service-history settlement. Its mixed-pause persistence and replay guards are especially thorough. One Medium issue remains: a gateway payload containing both consent and a hard failure is reclassified as pure resumable consent, suppressing the failure that authorization cannot resolve.

Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
1 verified finding remained after source verification (1 medium) across 1 file. Details are attached to the affected lines below.

Affected areas: python/packages/foundry_hosting/agent_framework_foundry_hosting/_toolbox.py

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

MAF Automated Review — Iteration 2

Result: Findings reported
Scope: 1 net-new commit(s): 47eb14ec5386
Model: gpt-5.6-sol

Overview

The review found 1 verified inline finding(s).

Reviewed the supplied incremental change set across correctness, security/reliability, architecture, and failure behavior.
1 verified finding remained after source verification (1 medium) across 1 file. Details are attached to the affected lines below.

Affected areas: python/packages/foundry_hosting/agent_framework_foundry_hosting/_toolbox.py

return None
error = cast(dict[str, object], raw_error)
if error.get("type") not in ("mcp", "a2a_preview"):
return None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

An aggregate containing valid mcp and unfamiliar-source CONSENT_REQUIRED entries returns None at line 180, causing _invoke_tool to re-raise and emit a generic function failure without consent URLs or continuation; any fix must reconcile the tested invariant that unsupported source types are not classified as consent (test_responses.py:9241-9272).

@eavanvalkenburg
Eduard van Valkenburg (eavanvalkenburg) merged commit f118d9a into python-foundry-hosting-rc Nov 13, 2026
5 checks passed
@eavanvalkenburg
Eduard van Valkenburg (eavanvalkenburg) deleted the foundry-toolbox-oauth-consent branch November 13, 2026 16:42

This branch was successfully deployed

1 active deployment
github-app-auth — 47eb14ec Deployed Nov 13, 2026 by eavanvalkenburg via team_check #9435
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants