From 583611d25f77dd6677a9174ab390c09ba9cf608b Mon Sep 17 00:00:00 2001 From: Kazuhiro Sera Date: Tue, 8 Jul 2025 20:44:33 +0900 Subject: [PATCH] Fix #968 by upgrading openai package to the latest --- pyproject.toml | 2 +- src/agents/models/openai_responses.py | 12 +++++++++++- tests/test_items_helpers.py | 13 +++++++++++-- tests/test_run_step_processing.py | 8 +++++++- uv.lock | 8 ++++---- 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index e659348ca..1aaedf1b6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ requires-python = ">=3.9" license = "MIT" authors = [{ name = "OpenAI", email = "support@openai.com" }] dependencies = [ - "openai>=1.87.0", + "openai>=1.93.1, <2", "pydantic>=2.10, <3", "griffe>=1.5.6, <2", "typing-extensions>=4.12.2, <5", diff --git a/src/agents/models/openai_responses.py b/src/agents/models/openai_responses.py index a7ce62983..46cf21a32 100644 --- a/src/agents/models/openai_responses.py +++ b/src/agents/models/openai_responses.py @@ -303,10 +303,19 @@ class ConvertedTools: class Converter: @classmethod def convert_tool_choice( - cls, tool_choice: Literal["auto", "required", "none"] | str | None + cls, tool_choice: Literal["auto", "required", "none"] | str | dict[str, Any] | None ) -> response_create_params.ToolChoice | NotGiven: if tool_choice is None: return NOT_GIVEN + elif isinstance(tool_choice, dict): + if tool_choice.get("type") == "mcp": + return { + "server_label": tool_choice.get("server_label") or "mcp", + "type": "mcp", + "name": tool_choice.get("name"), + } + else: + raise UserError(f"Unknown tool choice: {tool_choice}") elif tool_choice == "required": return "required" elif tool_choice == "auto": @@ -335,6 +344,7 @@ def convert_tool_choice( } elif tool_choice == "mcp": return { + "server_label": "mcp", "type": "mcp", } else: diff --git a/tests/test_items_helpers.py b/tests/test_items_helpers.py index 5dba21d88..f711f21e1 100644 --- a/tests/test_items_helpers.py +++ b/tests/test_items_helpers.py @@ -11,7 +11,10 @@ ) from openai.types.responses.response_function_tool_call import ResponseFunctionToolCall from openai.types.responses.response_function_tool_call_param import ResponseFunctionToolCallParam -from openai.types.responses.response_function_web_search import ResponseFunctionWebSearch +from openai.types.responses.response_function_web_search import ( + ActionSearch, + ResponseFunctionWebSearch, +) from openai.types.responses.response_function_web_search_param import ResponseFunctionWebSearchParam from openai.types.responses.response_output_message import ResponseOutputMessage from openai.types.responses.response_output_message_param import ResponseOutputMessageParam @@ -225,7 +228,12 @@ def test_to_input_items_for_file_search_call() -> None: def test_to_input_items_for_web_search_call() -> None: """A web search tool call output should produce the same dict as a web search input.""" - ws_call = ResponseFunctionWebSearch(id="w1", status="completed", type="web_search_call") + ws_call = ResponseFunctionWebSearch( + id="w1", + action=ActionSearch(type="search", query="query"), + status="completed", + type="web_search_call", + ) resp = ModelResponse(output=[ws_call], usage=Usage(), response_id=None) input_items = resp.to_input_items() assert isinstance(input_items, list) and len(input_items) == 1 @@ -233,6 +241,7 @@ def test_to_input_items_for_web_search_call() -> None: "id": "w1", "status": "completed", "type": "web_search_call", + "action": {"type": "search", "query": "query"}, } assert input_items[0] == expected diff --git a/tests/test_run_step_processing.py b/tests/test_run_step_processing.py index 6a2904791..27d36afa8 100644 --- a/tests/test_run_step_processing.py +++ b/tests/test_run_step_processing.py @@ -7,6 +7,7 @@ ResponseFunctionWebSearch, ) from openai.types.responses.response_computer_tool_call import ActionClick +from openai.types.responses.response_function_web_search import ActionSearch from openai.types.responses.response_reasoning_item import ResponseReasoningItem, Summary from pydantic import BaseModel @@ -306,7 +307,12 @@ async def test_file_search_tool_call_parsed_correctly(): @pytest.mark.asyncio async def test_function_web_search_tool_call_parsed_correctly(): agent = Agent(name="test") - web_search_call = ResponseFunctionWebSearch(id="w1", status="completed", type="web_search_call") + web_search_call = ResponseFunctionWebSearch( + id="w1", + action=ActionSearch(type="search", query="query"), + status="completed", + type="web_search_call", + ) response = ModelResponse( output=[get_text_message("hello"), web_search_call], usage=Usage(), diff --git a/uv.lock b/uv.lock index d882c9bc5..387b5ce2e 100644 --- a/uv.lock +++ b/uv.lock @@ -1461,7 +1461,7 @@ wheels = [ [[package]] name = "openai" -version = "1.87.0" +version = "1.93.1" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "anyio" }, @@ -1473,9 +1473,9 @@ dependencies = [ { name = "tqdm" }, { name = "typing-extensions" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/47/ed/2b3f6c7e950784e9442115ab8ebeff514d543fb33da10607b39364645a75/openai-1.87.0.tar.gz", hash = "sha256:5c69764171e0db9ef993e7a4d8a01fd8ff1026b66f8bdd005b9461782b6e7dfc", size = 470880, upload-time = "2025-06-16T19:04:26.316Z" } +sdist = { url = "https://files.pythonhosted.org/packages/5e/a8/e4427729da048cb33bda15e70f09f7520bdf3577bafc546b135ecb36af7d/openai-1.93.1.tar.gz", hash = "sha256:11eb8932965d0f79ecc4cb38a60a0c4cef4bcd5fcf08b99fc9a399fa5f1e50ab", size = 487124, upload-time = "2025-07-07T16:40:38.389Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/36/ac/313ded47ce1d5bc2ec02ed5dd5506bf5718678a4655ac20f337231d9aae3/openai-1.87.0-py3-none-any.whl", hash = "sha256:f9bcae02ac4fff6522276eee85d33047335cfb692b863bd8261353ce4ada5692", size = 734368, upload-time = "2025-06-16T19:04:23.181Z" }, + { url = "https://files.pythonhosted.org/packages/64/4f/875e5af1fb4e5ed4ea9e4a88f482d9ca2e48932105605b6c516e9a14de25/openai-1.93.1-py3-none-any.whl", hash = "sha256:a2c2946c4f21346d4902311a7440381fd8a33466ee7ca688133d1cad29a9357c", size = 755081, upload-time = "2025-07-07T16:40:36.585Z" }, ] [[package]] @@ -1536,7 +1536,7 @@ requires-dist = [ { name = "litellm", marker = "extra == 'litellm'", specifier = ">=1.67.4.post1,<2" }, { name = "mcp", marker = "python_full_version >= '3.10'", specifier = ">=1.9.4,<2" }, { name = "numpy", marker = "python_full_version >= '3.10' and extra == 'voice'", specifier = ">=2.2.0,<3" }, - { name = "openai", specifier = ">=1.87.0" }, + { name = "openai", specifier = ">=1.93.1,<2" }, { name = "pydantic", specifier = ">=2.10,<3" }, { name = "requests", specifier = ">=2.0,<3" }, { name = "types-requests", specifier = ">=2.0,<3" },