Skip to content

Python: [Team][Investigation] Explore eager execution of allowed calls before approval pauses #10334

Open

Description

Describe the problem before proposing implementation. Filing an issue does not reserve the work or approve a pull request.

Problem

The current session-backed function-approval contract defers an entire model-produced function-call batch when any call requires approval. This can cause two successive user-input round trips: first for function approval, then for OAuth consent discovered only when another, already-allowed call finally executes.

Explore whether the loop should attempt every currently allowed call before returning a pause, so it can surface known approval and OAuth requirements together while retaining completed results.

Use Case and Evidence

A model returns four function-call contents (FCCs):

  1. A requires function approval; B, C, and D are already allowed.
  2. Today, the loop pauses for A and defers B/C/D too.
  3. After the user approves A, execution discovers that C needs OAuth consent. The loop must return to the user again.

An alternative would leave A unexecuted, attempt B/C/D, retain B/D's completed results, and surface A's approval request alongside C's OAuth consent request in the same pause.

This arose while discussing invocation-time Foundry Toolbox OAuth consent in #10020 and #9903. The goal here is to reduce user-input round trips, not to conflate them with provider requests needed to reconcile service-owned history.

Desired Outcome

Determine whether eager execution of allowed calls should become supported behavior. If so, define a contract that collects all known input requirements after eligible calls settle, stores successful sibling results, and resumes only unresolved work without replaying completed calls.

An OAuth requirement from one concurrent call should not, by itself, prevent other already-allowed calls from being attempted.

Alternatives Considered

  • Keep the existing batch-wide approval pause. This preserves current behavior but may require separate approval and OAuth interactions.
  • Stop later dispatch after the first OAuth requirement. This may leave other allowed calls unattempted and additional consent requirements undiscovered.

Proposed Direction

Investigate reusing the existing approval and user-input pause paths while allowing eligible calls to settle before the pause is returned. Do not prescribe a new pause manager or state store.

Resolve these questions:

  • Which calls may execute before all approval decisions are available, and should this be the default or an opt-in policy?
  • How should approval requests and multiple OAuth consent requests be presented and answered together, including partial answers?
  • How are completed results and pending calls retained with framework-owned and service-owned history, in streaming and non-streaming modes?
  • What are the retry and approval rules for a consent-blocked call, and how do we prevent replay of successful siblings or reuse of stale approval authority?
  • What are the consequences of executing allowed siblings before the user approves or rejects another call, especially for side effects, cancellation, failures, and execution limits?
  • Should sequential execution retain its existing behavior, or follow a different rule?

If A itself needs OAuth consent, that may not be discoverable before A is approved. Never execute an unapproved call merely to discover its consent requirements; identify where a combined interaction is and is not possible.

The investigation should end with an agreed behavior contract and a focused regression scenario set, or a documented decision to retain the current behavior.

Scope and Non-Goals

Team-owned vNext investigation into Python function-call execution and pause semantics. This is not approval to implement the proposal or change the current approval contract as part of #10020 or #9903.

Do not bypass approval, assume rollback of sibling side effects, automatically replay completed calls, or introduce a broader workflow/checkpoint redesign.

Language

Python

Contribution Intent

I am only requesting the feature. This investigation is reserved for the Agent Framework team; implementation remains subject to maintainer agreement.

Acknowledgements

  • I searched existing issues and did not find a duplicate.
  • I will wait for explicit maintainer agreement before starting implementation of a non-trivial change.

Activity

  1. added
    python
    vnext
    team-only
    on Nov 13, 2026
  2. eavanvalkenburg commented on Nov 13, 2026

    @eavanvalkenburg
    MemberAuthor

    /plan the goal here is to reduce the odds of having two rounds of user access for one tool call loop, but this might need configurable behavior as it might depend on the specifics of the environment and setup, for instance when approval takes long, reducing it by waiting to see if one tool comes back with oauth and then being able to handle both approval and oauth in the same approval flow is very helpful

  3. github-actions commented on Nov 13, 2026

    @github-actions
    Contributor

    Summary

    When a model returns several tool calls and one needs approval, the loop pauses and holds back the other (already-allowed) calls. After the user approves, one of those held calls may need OAuth consent. That causes a second user round trip. You want to lower the odds of that, and you expect the behavior may need to be configurable. Example: when approval is slow, it helps to run the allowed calls first so approval and OAuth can be handled in one prompt.

    What the code does today (read, not run)

    • In _try_execute_function_call_groups in _tools.py, when any call needs approval (requires_approval), the function returns approval pauses immediately and runs nothing.
    • Allowed siblings are recorded through _store_already_approved_approval_requests. They stay hidden until the visible approval is answered.
    • The spec (004, "Safe and approval-required calls in one batch") documents this as intended: "Hidden safe calls replay only with the matching visible approval." Sequential mode also waits for every decision.
    • The declaration-only (Host-owned) path is a precedent for the opposite policy. Local siblings are deferred when an authoritative session exists, but they execute in the same turn when there is no session (has_declaration_only_call branch). So the framework already has both "defer" and "run now" behaviors, chosen by context.
    • FunctionInvocationConfiguration already has per-run switches such as allow_concurrent_invocation, so an opt-in policy has a natural home.
    • I did not find existing handling that collects OAuth-consent pauses from siblings while an approval is pending. I did not look at the Foundry Toolbox consent code, so I cannot say how a consent pause is raised there.

    Recommendation

    An investigation is warranted, and code changes are plausible but should not be assumed yet. The issue itself says this ends in either an agreed contract or a documented decision to keep the current behavior. I would recommend an opt-in policy, keeping today's batch-wide deferral as the default. The default is a documented, spec-tested safety contract. Running allowed siblings early changes when side effects happen. It also changes cancellation, max_function_calls accounting and hidden-state replay, and every one of those has a spec row and tests.

    Trade-off: opt-in covers your slow-approval case without surprising existing users. The cost is two code paths to test, in streaming and non-streaming modes and in sequential and concurrent modes. A documentation-only outcome (keep current behavior, document the extra consent round trip) stays valid if the contract turns out too costly.

    Proposed plan (investigation first; nothing has been changed)

    1. Write the behavior contract as a short design note (an ADR in docs/decisions/) before any code. Answer the issue's open questions:

      • Which calls count as "eligible" (known never_require tools only).
      • How an approval request and one or more consent requests are shown together.
      • What happens with partial answers.
      • Whether an approved retry of a consent-blocked call needs new approval.
      • The rule for sequential mode (likely unchanged, or "run allowed calls in order up to the first approval-required call").
    2. Define the policy knob, for example a FunctionInvocationConfiguration option with values like "defer_all" (current default) and "run_allowed_first". Maybe add a bounded wait for slow consent. Never execute an approval-required call to discover its consent needs.

    3. Prototype the loop change in the requires_approval branch. Run eligible siblings with the existing execute_local_calls, keep their function_result groups, and return approval and consent pauses together. Store the finished results in the existing pending-batch state so resume runs only the unresolved calls and never replays finished ones. Reuse existing pause storage rather than adding a new store.

    4. Handle resume rules: a consent-blocked call must not reuse stale approval authority. A partial answer must leave the rest pending. Rejection or cancellation of A must still keep B/D's completed results. max_function_calls is counted per executed group, which the spec already defines.

    5. Tests, mapped into spec 004's scenario table:

      • The four-call example from the issue (A approval; B, C, D allowed; C needs OAuth) results in one pause and no replay of B/D.
      • A needing OAuth itself still takes two rounds.
      • Both execution modes, streaming and non-streaming, session-backed and sessionless, serialization round trip, an unrelated turn before resume, rejection, cancellation, and a failing sibling.
      • The default setting behaves exactly as today.
    6. Docs: update spec 004 only for the changed rows, and add a short note on when to opt in (slow approvals, OAuth-heavy toolsets) and the side-effect caveat.

    Success means: the agreed contract is recorded, the opt-in setting yields one user round trip for the example, and the default behavior and its existing tests are unchanged.

    Questions for the team (non-blocking)

    • Should "wait for the other calls to settle" have a time limit, or only wait for sibling completion?
    • Is the policy per agent or per run? Per tool might be better, since "safe to run early" is a tool property.

    This is a proposal only. No changes have been made.

    Generated by Issue Planning for #10334 · copilot · auto · ~37 AIC · ⌖ ~1 AIC · ⊞ 4.8K · ◷

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

Metadata

Metadata

Labels

pythonteam-onlyvnext

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions