Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions docs/decisions/0055-python-foundry-hosting-contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,20 @@ approvals and rejections. Exact pre-header HTTP 400 behavior remains blocked on
validation hook under #9537; the native approval migration does not claim to implement that requirement.

Represent invocation-time OAuth consent as structured consent with incomplete response status.
Pair each emitted function call with one terminal result, preserve completed sibling results, and stop
later protected calls. Require `store=true` so continuation can retain the required state;
Pair each OAuth-interrupted invocation with one terminal result and preserve every authorized batch result.
OAuth consent does not suspend sibling calls: let the batch finish under its configured concurrency,
then return all consent requests with the complete results. Existing pre-execution approval gating
remains unchanged; eager execution before approval is separate vNext work tracked in #10334.
Require `store=true` so continuation can retain the required state;
do not support ephemeral consent under `store=false`.
Preserve results rather than cancelling or automatically replaying completed calls.
For inference-service history, reconcile a fully terminal batch before publishing consent and retain the accepted
continuation even when the service's reconciliation output is rejected. When another call still requires approval
or other input, publish both requests and retain completed results and unsent caller input in the native pending
batch until that call is resolved. Submit the real results together on continuation without replaying completed
calls or fabricating a terminal result for a pending call.
This behavior depends on the coordinated native Core change; select and validate the released Core
dependency floor during release preparation rather than adding a hosting-only compatibility fallback.

### Unresolved boundaries

Expand Down
24 changes: 22 additions & 2 deletions docs/specs/004-python-function-calling-loop.md

Large diffs are not rendered by default.

35 changes: 23 additions & 12 deletions python/packages/ag-ui/tests/ag_ui/test_approval_result_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import json
from typing import Any

import pytest
from ag_ui.core import ToolCallResultEvent
from agent_framework import AgentResponseUpdate, Content, FunctionInvocationContext, FunctionTool
from agent_framework.exceptions import UserInputRequiredException
Expand Down Expand Up @@ -262,31 +263,41 @@ async def test_mixed_batch_preserves_approved_result_identity_and_order() -> Non
assert [(event.tool_call_id, event.content) for event in results] == [("call-seattle", "Sunny in Seattle")]


async def test_approval_follow_up_group_remains_in_history_without_live_tool_result() -> None:
"""Approval-time user-input requests remain grouped without becoming terminal tool results."""
@pytest.mark.parametrize("oauth", [False, True], ids=["user-input", "oauth"])
async def test_approval_follow_up_group_preserves_terminal_result_contract(oauth: bool) -> None:
"""OAuth has a paired terminal result; other follow-up input remains pending."""
prompts = (
[
Content.from_oauth_consent_request(consent_link="https://example.com/first"),
Content.from_oauth_consent_request(consent_link="https://example.com/second"),
]
if oauth
else [Content("text", text="Please provide more input.", user_input_request=True)]
)

def request_consent() -> str:
raise UserInputRequiredException(
contents=[
Content.from_oauth_consent_request(consent_link="https://example.com/first"),
Content.from_oauth_consent_request(consent_link="https://example.com/second"),
]
)
raise UserInputRequiredException(contents=prompts)

events, agent = await _run_custom_approval(
FunctionTool(name="request_consent", description="Request consent", func=request_consent)
)

assert not [event for event in events if getattr(event, "type", None) == "TOOL_CALL_RESULT"]
results = [event for event in events if isinstance(event, ToolCallResultEvent)]
if oauth:
assert len(results) == 1
assert results[0].tool_call_id == "call-custom"
assert "OAuth consent is required" in results[0].content
assert "https://" not in results[0].content
else:
assert not results
requests = [
content
for message in agent.messages_received
for content in message.contents
if isinstance(content, Content) and content.user_input_request
]
assert [request.consent_link for request in requests] == [
"https://example.com/first",
"https://example.com/second",
assert [(request.type, request.consent_link, request.text) for request in requests] == [
(prompt.type, prompt.consent_link, prompt.text) for prompt in prompts
]


Expand Down
4 changes: 3 additions & 1 deletion python/packages/core/agent_framework/_mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
Content,
Message,
)
from .exceptions import ToolException, ToolExecutionException
from .exceptions import ToolException, ToolExecutionException, UserInputRequiredException
from .observability import (
OtelAttr,
create_mcp_client_span,
Expand Down Expand Up @@ -3742,6 +3742,8 @@ async def _call_tool_with_retries(
span_error_recorded = True
raise _mcp_tool_execution_exception(text or str(parsed))
return parser(result)
except UserInputRequiredException:
raise
except ToolExecutionException as tool_ex:
if span.is_recording() and not span_error_recorded:
set_mcp_span_error(span, type(tool_ex).__name__, str(tool_ex))
Expand Down
Loading
Loading