Python: Fixing the OpenAI Responses Client to be able to persist and interact with server-side threads (#818)

* Fix options_dict handling in response client

* Update python/packages/main/agent_framework/openai/_responses_client.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update condition for storing chat options

Fixes issue where, when using server-side threads, AF would pass back the function call message due to store being in chat_options in kwargs, not at the kwargs level. Means the appending of only the tool execution result never happens.

Resulted in a "tool output not found error" as we replied with the call not the result first.

* Refactor chat_options access for clarity

* Refactor store option assignment in responses client

* Small fixes

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Dmytro Struk <13853051+dmytrostruk@users.noreply.github.com>
This commit is contained in:
fiow123
2025-09-22 02:58:50 +01:00
committed by GitHub
Unverified
parent 205cd700c8
commit 94cef85c71
3 changed files with 132 additions and 126 deletions
@@ -758,7 +758,7 @@ def _handle_function_calls_response(
# we need to keep track of all function call messages
fcc_messages.extend(response.messages)
# and add them as additional context to the messages
if kwargs.get("store"):
if getattr(kwargs.get("chat_options"), "store", False):
prepped_messages.clear()
prepped_messages.append(result_message)
else:
@@ -304,12 +304,13 @@ class OpenAIBaseResponsesClient(OpenAIBase, BaseChatClient):
options_dict["tools"] = self._tools_to_response_tools(chat_options.tools)
# other settings
if "store" not in options_dict:
if chat_options.store:
options_dict["store"] = True
else:
options_dict["store"] = False
if "conversation_id" in options_dict:
options_dict["previous_response_id"] = options_dict["conversation_id"]
options_dict.pop("conversation_id")
if "model" not in options_dict:
if chat_options.conversation_id:
options_dict["previous_response_id"] = chat_options.conversation_id
if chat_options.ai_model_id is None:
options_dict["model"] = self.ai_model_id
return options_dict