Skip to content

Commit 583611d

Browse files
committed
Fix #968 by upgrading openai package to the latest
1 parent 18cb55e commit 583611d

File tree

5 files changed

+34
-9
lines changed

5 files changed

+34
-9
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ requires-python = ">=3.9"
77
license = "MIT"
88
authors = [{ name = "OpenAI", email = "support@openai.com" }]
99
dependencies = [
10-
"openai>=1.87.0",
10+
"openai>=1.93.1, <2",
1111
"pydantic>=2.10, <3",
1212
"griffe>=1.5.6, <2",
1313
"typing-extensions>=4.12.2, <5",

src/agents/models/openai_responses.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,19 @@ class ConvertedTools:
303303
class Converter:
304304
@classmethod
305305
def convert_tool_choice(
306-
cls, tool_choice: Literal["auto", "required", "none"] | str | None
306+
cls, tool_choice: Literal["auto", "required", "none"] | str | dict[str, Any] | None
307307
) -> response_create_params.ToolChoice | NotGiven:
308308
if tool_choice is None:
309309
return NOT_GIVEN
310+
elif isinstance(tool_choice, dict):
311+
if tool_choice.get("type") == "mcp":
312+
return {
313+
"server_label": tool_choice.get("server_label") or "mcp",
314+
"type": "mcp",
315+
"name": tool_choice.get("name"),
316+
}
317+
else:
318+
raise UserError(f"Unknown tool choice: {tool_choice}")
310319
elif tool_choice == "required":
311320
return "required"
312321
elif tool_choice == "auto":
@@ -335,6 +344,7 @@ def convert_tool_choice(
335344
}
336345
elif tool_choice == "mcp":
337346
return {
347+
"server_label": "mcp",
338348
"type": "mcp",
339349
}
340350
else:

tests/test_items_helpers.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
)
1212
from openai.types.responses.response_function_tool_call import ResponseFunctionToolCall
1313
from openai.types.responses.response_function_tool_call_param import ResponseFunctionToolCallParam
14-
from openai.types.responses.response_function_web_search import ResponseFunctionWebSearch
14+
from openai.types.responses.response_function_web_search import (
15+
ActionSearch,
16+
ResponseFunctionWebSearch,
17+
)
1518
from openai.types.responses.response_function_web_search_param import ResponseFunctionWebSearchParam
1619
from openai.types.responses.response_output_message import ResponseOutputMessage
1720
from openai.types.responses.response_output_message_param import ResponseOutputMessageParam
@@ -225,14 +228,20 @@ def test_to_input_items_for_file_search_call() -> None:
225228

226229
def test_to_input_items_for_web_search_call() -> None:
227230
"""A web search tool call output should produce the same dict as a web search input."""
228-
ws_call = ResponseFunctionWebSearch(id="w1", status="completed", type="web_search_call")
231+
ws_call = ResponseFunctionWebSearch(
232+
id="w1",
233+
action=ActionSearch(type="search", query="query"),
234+
status="completed",
235+
type="web_search_call",
236+
)
229237
resp = ModelResponse(output=[ws_call], usage=Usage(), response_id=None)
230238
input_items = resp.to_input_items()
231239
assert isinstance(input_items, list) and len(input_items) == 1
232240
expected: ResponseFunctionWebSearchParam = {
233241
"id": "w1",
234242
"status": "completed",
235243
"type": "web_search_call",
244+
"action": {"type": "search", "query": "query"},
236245
}
237246
assert input_items[0] == expected
238247

tests/test_run_step_processing.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
ResponseFunctionWebSearch,
88
)
99
from openai.types.responses.response_computer_tool_call import ActionClick
10+
from openai.types.responses.response_function_web_search import ActionSearch
1011
from openai.types.responses.response_reasoning_item import ResponseReasoningItem, Summary
1112
from pydantic import BaseModel
1213

@@ -306,7 +307,12 @@ async def test_file_search_tool_call_parsed_correctly():
306307
@pytest.mark.asyncio
307308
async def test_function_web_search_tool_call_parsed_correctly():
308309
agent = Agent(name="test")
309-
web_search_call = ResponseFunctionWebSearch(id="w1", status="completed", type="web_search_call")
310+
web_search_call = ResponseFunctionWebSearch(
311+
id="w1",
312+
action=ActionSearch(type="search", query="query"),
313+
status="completed",
314+
type="web_search_call",
315+
)
310316
response = ModelResponse(
311317
output=[get_text_message("hello"), web_search_call],
312318
usage=Usage(),

uv.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)