From 7942a52ca164c9bc63ff65706cdf103b6542388d Mon Sep 17 00:00:00 2001 From: peterychang <49209570+peterychang@users.noreply.github.com> Date: Mon, 25 Aug 2025 12:52:42 -0400 Subject: [PATCH] fix chat_options in kwargs error path in responses client (#483) --- python/packages/main/agent_framework/_clients.py | 2 ++ python/packages/main/agent_framework/_types.py | 3 +++ .../agent_framework/openai/_responses_client.py | 16 ++++------------ 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/python/packages/main/agent_framework/_clients.py b/python/packages/main/agent_framework/_clients.py index 2cbea3f83f..7fb24afc47 100644 --- a/python/packages/main/agent_framework/_clients.py +++ b/python/packages/main/agent_framework/_clients.py @@ -499,6 +499,7 @@ class ChatClientBase(AFBaseModel, ABC): Returns: A chat response from the model. """ + # Should we merge chat options instead of ignoring the input params? if "chat_options" in kwargs: chat_options = kwargs.pop("chat_options") if not isinstance(chat_options, ChatOptions): @@ -579,6 +580,7 @@ class ChatClientBase(AFBaseModel, ABC): Yields: A stream representing the response(s) from the LLM. """ + # Should we merge chat options instead of ignoring the input params? if "chat_options" in kwargs: chat_options = kwargs.pop("chat_options") if not isinstance(chat_options, ChatOptions): diff --git a/python/packages/main/agent_framework/_types.py b/python/packages/main/agent_framework/_types.py index 49dd146dff..4b19347450 100644 --- a/python/packages/main/agent_framework/_types.py +++ b/python/packages/main/agent_framework/_types.py @@ -1792,11 +1792,14 @@ class ChatOptions(AFBaseModel): if not isinstance(other, ChatOptions): return self other_tools = other.tools + # tool_choice has a specialized serialize method. Save it here so we can fix it later. + tool_choice = other.tool_choice or self.tool_choice updated_values = other.model_dump(exclude_none=True, exclude={"tools"}) logit_bias = updated_values.pop("logit_bias", {}) metadata = updated_values.pop("metadata", {}) additional_properties = updated_values.pop("additional_properties", {}) combined = self.model_copy(update=updated_values) + combined.tool_choice = tool_choice combined.logit_bias = {**(combined.logit_bias or {}), **logit_bias} combined.metadata = {**(combined.metadata or {}), **metadata} combined.additional_properties = {**(combined.additional_properties or {}), **additional_properties} diff --git a/python/packages/main/agent_framework/openai/_responses_client.py b/python/packages/main/agent_framework/openai/_responses_client.py index b6134e6970..a6ae718e42 100644 --- a/python/packages/main/agent_framework/openai/_responses_client.py +++ b/python/packages/main/agent_framework/openai/_responses_client.py @@ -166,7 +166,8 @@ class OpenAIResponsesClientBase(OpenAIHandler, ChatClientBase): ) ) - chat_options = ChatOptions( + return await super().get_response( + messages=messages, max_tokens=max_tokens, response_format=response_format, seed=seed, @@ -177,11 +178,6 @@ class OpenAIResponsesClientBase(OpenAIHandler, ChatClientBase): top_p=top_p, user=user, additional_properties=additional_properties, - ) - - return await super().get_response( - messages=messages, - chat_options=chat_options, **kwargs, ) @@ -262,7 +258,8 @@ class OpenAIResponsesClientBase(OpenAIHandler, ChatClientBase): ) ) - chat_options = ChatOptions( + async for update in super().get_streaming_response( + messages=messages, max_tokens=max_tokens, response_format=response_format, seed=seed, @@ -273,11 +270,6 @@ class OpenAIResponsesClientBase(OpenAIHandler, ChatClientBase): top_p=top_p, user=user, additional_properties=additional_properties, - ) - - async for update in super().get_streaming_response( - messages=messages, - chat_options=chat_options, **kwargs, ): yield update