From baeb73a58cdda25cc7d871481eaf7872a938e759 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 19 May 2026 05:52:04 +0000 Subject: [PATCH] fix: capture streaming response format after prepare Agent-Logs-Url: https://github.com/microsoft/agent-framework/sessions/f62076ef-558d-49e8-8fe2-f38d527c9639 Co-authored-by: eavanvalkenburg <13749212+eavanvalkenburg@users.noreply.github.com> --- .../openai/agent_framework_openai/_chat_client.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/python/packages/openai/agent_framework_openai/_chat_client.py b/python/packages/openai/agent_framework_openai/_chat_client.py index 080e4a7803..a71d387057 100644 --- a/python/packages/openai/agent_framework_openai/_chat_client.py +++ b/python/packages/openai/agent_framework_openai/_chat_client.py @@ -614,19 +614,18 @@ class RawOpenAIChatClient( # type: ignore[misc] function_call_ids: dict[int, tuple[str, str]] = {} seen_reasoning_delta_item_ids: set[str] = set() validated_options: dict[str, Any] | None = None + response_format: Any | None = None def _finalize_streamed_response(updates: Sequence[ChatResponseUpdate]) -> ChatResponse[Any]: - return self._finalize_response_updates( - updates, - response_format=validated_options.get("response_format") if validated_options else None, - ) + return self._finalize_response_updates(updates, response_format=response_format) async def _stream() -> AsyncIterable[ChatResponseUpdate]: - nonlocal validated_options + nonlocal response_format, validated_options if continuation_token is not None: # Resume a background streaming response by retrieving with stream=True client = self.client validated_options = await self._validate_options(options) + response_format = validated_options.get("response_format") try: raw_stream_response = await client.responses.with_raw_response.retrieve( continuation_token["response_id"], @@ -652,6 +651,7 @@ class RawOpenAIChatClient( # type: ignore[misc] run_options, validated_options, ) = await self._prepare_request(messages, options) + response_format = validated_options.get("response_format") try: if "text_format" in run_options: # The SDK's ``responses.stream(text_format=...)`` helper preserves