diff --git a/python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py b/python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py index bdaceae0e1..10d89d198b 100644 --- a/python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py +++ b/python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py @@ -1460,25 +1460,23 @@ async def _to_outputs( elif content.type == "function_approval_request": function_call: Content = content.function_call # type: ignore server_label = function_call.additional_properties.get("server_label", "agent_framework") - approval_request_id: str | None = None + request_saved = False async for event in stream.aoutput_item_mcp_approval_request( server_label, function_call.name, # type: ignore _arguments_to_str(function_call.arguments), ): + if approval_storage is not None and not request_saved: + # Extract the approval request ID generated by the infrastructure + # when the approval request item is added to the stream. Save the + # approval request to the approval storage so it can be retrieved later + # for round trips where the original approval request needs to be looked up. + item = getattr(event, "item", None) + if item is not None and getattr(item, "id", None) is not None: + approval_request_id = cast(str, item.id) # type: ignore + await approval_storage.save_approval_request(approval_request_id, content) + request_saved = True yield event - # Extract the approval request ID generated by the infrastructure - # when the approval request item is added to the stream - if ( - getattr(event, "item", None) is not None - and getattr(event.item, "id", None) is not None # type: ignore - and approval_request_id is None - ): - approval_request_id = cast(str, event.item.id) # type: ignore - # Save the approval request to the approval storage so it can be retrieved later - # for round trips where the original approval request needs to be looked up - if approval_request_id is not None and approval_storage is not None: - await approval_storage.save_approval_request(approval_request_id, content) else: # Log a warning for unsupported content types instead of raising an error to avoid breaking the response stream. logger.warning(f"Content type '{content.type}' is not supported yet. This is usually safe to ignore.") diff --git a/python/samples/04-hosting/foundry-hosted-agents/README.md b/python/samples/04-hosting/foundry-hosted-agents/README.md index 0ff8c9e945..7f9a467b27 100644 --- a/python/samples/04-hosting/foundry-hosted-agents/README.md +++ b/python/samples/04-hosting/foundry-hosted-agents/README.md @@ -156,7 +156,7 @@ cd agent-framework/python/samples/04-hosting/foundry-hosted-agents/responses 2. Install dependencies: ```bash - pip install -r requirements.txt + uv pip install -r requirements.txt ``` 3. Create a `.env` file with your Foundry configuration following the `env.example` file in the sample.