From 82a17690a1f9ad4902ffee37523cb5608fb4da8a Mon Sep 17 00:00:00 2001 From: Giles Odigwe Date: Tue, 20 Jan 2026 14:04:47 -0800 Subject: [PATCH 1/2] prefer kwargs conversation_id over options --- .../packages/core/agent_framework/openai/_responses_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/packages/core/agent_framework/openai/_responses_client.py b/python/packages/core/agent_framework/openai/_responses_client.py index 37a35ae9bc..ca37103f93 100644 --- a/python/packages/core/agent_framework/openai/_responses_client.py +++ b/python/packages/core/agent_framework/openai/_responses_client.py @@ -606,7 +606,7 @@ def _check_model_presence(self, options: dict[str, Any]) -> None: def _get_current_conversation_id(self, options: dict[str, Any], **kwargs: Any) -> str | None: """Get the current conversation ID from options dict or kwargs.""" - return options.get("conversation_id") or kwargs.get("conversation_id") + return kwargs.get("conversation_id") or options.get("conversation_id") def _prepare_messages_for_openai(self, chat_messages: Sequence[ChatMessage]) -> list[dict[str, Any]]: """Prepare the chat messages for a request. From f181817cdb89dc62638222ded4aa9d3d9b2a992d Mon Sep 17 00:00:00 2001 From: Giles Odigwe Date: Tue, 20 Jan 2026 18:42:25 -0800 Subject: [PATCH 2/2] addressed comments --- .../agent_framework/openai/_responses_client.py | 6 +++++- .../tests/openai/test_openai_responses_client.py | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/python/packages/core/agent_framework/openai/_responses_client.py b/python/packages/core/agent_framework/openai/_responses_client.py index ca37103f93..87ac6acf29 100644 --- a/python/packages/core/agent_framework/openai/_responses_client.py +++ b/python/packages/core/agent_framework/openai/_responses_client.py @@ -605,7 +605,11 @@ def _check_model_presence(self, options: dict[str, Any]) -> None: options["model"] = self.model_id def _get_current_conversation_id(self, options: dict[str, Any], **kwargs: Any) -> str | None: - """Get the current conversation ID from options dict or kwargs.""" + """Get the current conversation ID, preferring kwargs over options. + + This ensures runtime-updated conversation IDs (for example, from tool execution + loops) take precedence over the initial configuration provided in options. + """ return kwargs.get("conversation_id") or options.get("conversation_id") def _prepare_messages_for_openai(self, chat_messages: Sequence[ChatMessage]) -> list[dict[str, Any]]: diff --git a/python/packages/core/tests/openai/test_openai_responses_client.py b/python/packages/core/tests/openai/test_openai_responses_client.py index c91297d7df..977d948c3d 100644 --- a/python/packages/core/tests/openai/test_openai_responses_client.py +++ b/python/packages/core/tests/openai/test_openai_responses_client.py @@ -1682,6 +1682,20 @@ async def test_prepare_options_store_parameter_handling() -> None: assert "previous_response_id" not in options +async def test_conversation_id_precedence_kwargs_over_options() -> None: + """When both kwargs and options contain conversation_id, kwargs wins.""" + client = OpenAIResponsesClient(model_id="test-model", api_key="test-key") + messages = [ChatMessage(role="user", text="Hello")] + + # options has a stale response id, kwargs carries the freshest one + opts = {"conversation_id": "resp_old_123"} + run_opts = await client._prepare_options(messages, opts, conversation_id="resp_new_456") # type: ignore + + # Verify kwargs takes precedence and maps to previous_response_id for resp_* IDs + assert run_opts.get("previous_response_id") == "resp_new_456" + assert "conversation" not in run_opts + + def test_with_callable_api_key() -> None: """Test OpenAIResponsesClient initialization with callable API key."""