diff --git a/pyproject.toml b/pyproject.toml index fec596f28..257c26002 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.97.1,<2", + "openai>=1.99.6,<2", "pydantic>=2.10, <3", "griffe>=1.5.6, <2", "typing-extensions>=4.12.2, <5", diff --git a/src/agents/extensions/models/litellm_model.py b/src/agents/extensions/models/litellm_model.py index d933e872f..68b4843f1 100644 --- a/src/agents/extensions/models/litellm_model.py +++ b/src/agents/extensions/models/litellm_model.py @@ -18,13 +18,17 @@ ) from _e from openai import NOT_GIVEN, AsyncStream, NotGiven -from openai.types.chat import ChatCompletionChunk, ChatCompletionMessageToolCall +from openai.types.chat import ( + ChatCompletionChunk, + ChatCompletionMessageFunctionToolCall, +) from openai.types.chat.chat_completion_message import ( Annotation, AnnotationURLCitation, ChatCompletionMessage, ) -from openai.types.chat.chat_completion_message_tool_call import Function +from openai.types.chat.chat_completion_message_function_tool_call import Function +from openai.types.chat.chat_completion_message_tool_call import ChatCompletionMessageToolCall from openai.types.responses import Response from ... import _debug @@ -362,7 +366,7 @@ def convert_message_to_openai( if message.role != "assistant": raise ModelBehaviorError(f"Unsupported role: {message.role}") - tool_calls = ( + tool_calls: list[ChatCompletionMessageToolCall] | None = ( [LitellmConverter.convert_tool_call_to_openai(tool) for tool in message.tool_calls] if message.tool_calls else None @@ -413,11 +417,12 @@ def convert_annotations_to_openai( @classmethod def convert_tool_call_to_openai( cls, tool_call: litellm.types.utils.ChatCompletionMessageToolCall - ) -> ChatCompletionMessageToolCall: - return ChatCompletionMessageToolCall( + ) -> ChatCompletionMessageFunctionToolCall: + return ChatCompletionMessageFunctionToolCall( id=tool_call.id, type="function", function=Function( - name=tool_call.function.name or "", arguments=tool_call.function.arguments + name=tool_call.function.name or "", + arguments=tool_call.function.arguments, ), ) diff --git a/src/agents/models/chatcmpl_converter.py b/src/agents/models/chatcmpl_converter.py index b84f2e669..77cfc4e1a 100644 --- a/src/agents/models/chatcmpl_converter.py +++ b/src/agents/models/chatcmpl_converter.py @@ -12,8 +12,8 @@ ChatCompletionContentPartTextParam, ChatCompletionDeveloperMessageParam, ChatCompletionMessage, + ChatCompletionMessageFunctionToolCallParam, ChatCompletionMessageParam, - ChatCompletionMessageToolCallParam, ChatCompletionSystemMessageParam, ChatCompletionToolChoiceOptionParam, ChatCompletionToolMessageParam, @@ -126,15 +126,18 @@ def message_to_output_items(cls, message: ChatCompletionMessage) -> list[TRespon if message.tool_calls: for tool_call in message.tool_calls: - items.append( - ResponseFunctionToolCall( - id=FAKE_RESPONSES_ID, - call_id=tool_call.id, - arguments=tool_call.function.arguments, - name=tool_call.function.name, - type="function_call", + if tool_call.type == "function": + items.append( + ResponseFunctionToolCall( + id=FAKE_RESPONSES_ID, + call_id=tool_call.id, + arguments=tool_call.function.arguments, + name=tool_call.function.name, + type="function_call", + ) ) - ) + elif tool_call.type == "custom": + pass return items @@ -420,7 +423,7 @@ def ensure_assistant_message() -> ChatCompletionAssistantMessageParam: elif file_search := cls.maybe_file_search_call(item): asst = ensure_assistant_message() tool_calls = list(asst.get("tool_calls", [])) - new_tool_call = ChatCompletionMessageToolCallParam( + new_tool_call = ChatCompletionMessageFunctionToolCallParam( id=file_search["id"], type="function", function={ @@ -440,7 +443,7 @@ def ensure_assistant_message() -> ChatCompletionAssistantMessageParam: asst = ensure_assistant_message() tool_calls = list(asst.get("tool_calls", [])) arguments = func_call["arguments"] if func_call["arguments"] else "{}" - new_tool_call = ChatCompletionMessageToolCallParam( + new_tool_call = ChatCompletionMessageFunctionToolCallParam( id=func_call["call_id"], type="function", function={ diff --git a/tests/test_openai_chatcompletions.py b/tests/test_openai_chatcompletions.py index a6909b195..6291418f6 100644 --- a/tests/test_openai_chatcompletions.py +++ b/tests/test_openai_chatcompletions.py @@ -9,8 +9,8 @@ from openai.types.chat.chat_completion import ChatCompletion, Choice from openai.types.chat.chat_completion_chunk import ChatCompletionChunk from openai.types.chat.chat_completion_message import ChatCompletionMessage -from openai.types.chat.chat_completion_message_tool_call import ( - ChatCompletionMessageToolCall, +from openai.types.chat.chat_completion_message_tool_call import ( # type: ignore[attr-defined] + ChatCompletionMessageFunctionToolCall, Function, ) from openai.types.completion_usage import ( @@ -152,7 +152,7 @@ async def test_get_response_with_tool_call(monkeypatch) -> None: should append corresponding `ResponseFunctionToolCall` items after the assistant message item with matching name/arguments. """ - tool_call = ChatCompletionMessageToolCall( + tool_call = ChatCompletionMessageFunctionToolCall( id="call-id", type="function", function=Function(name="do_thing", arguments="{'x':1}"), diff --git a/tests/test_openai_chatcompletions_converter.py b/tests/test_openai_chatcompletions_converter.py index bcfca5495..1740af3d1 100644 --- a/tests/test_openai_chatcompletions_converter.py +++ b/tests/test_openai_chatcompletions_converter.py @@ -26,7 +26,7 @@ from typing import Literal, cast import pytest -from openai.types.chat import ChatCompletionMessage, ChatCompletionMessageToolCall +from openai.types.chat import ChatCompletionMessage, ChatCompletionMessageFunctionToolCall from openai.types.chat.chat_completion_message_tool_call import Function from openai.types.responses import ( ResponseFunctionToolCall, @@ -87,7 +87,7 @@ def test_message_to_output_items_with_tool_call(): be reflected as separate `ResponseFunctionToolCall` items appended after the message item. """ - tool_call = ChatCompletionMessageToolCall( + tool_call = ChatCompletionMessageFunctionToolCall( id="tool1", type="function", function=Function(name="myfn", arguments='{"x":1}'), @@ -185,7 +185,7 @@ def test_items_to_messages_with_output_message_and_function_call(): # Refusal in output message should be represented in assistant message assert "refusal" in assistant assert assistant["refusal"] == refusal.refusal - # Tool calls list should contain one ChatCompletionMessageToolCall dict + # Tool calls list should contain one ChatCompletionMessageFunctionToolCall dict tool_calls = assistant.get("tool_calls") assert isinstance(tool_calls, list) assert len(tool_calls) == 1 @@ -341,8 +341,8 @@ def test_tool_call_conversion(): tool_call = tool_calls[0] assert tool_call["id"] == function_call["call_id"] - assert tool_call["function"]["name"] == function_call["name"] - assert tool_call["function"]["arguments"] == function_call["arguments"] + assert tool_call["function"]["name"] == function_call["name"] # type: ignore + assert tool_call["function"]["arguments"] == function_call["arguments"] # type: ignore @pytest.mark.parametrize("role", ["user", "system", "developer"]) diff --git a/uv.lock b/uv.lock index d8efb6e8c..65ac2d4dc 100644 --- a/uv.lock +++ b/uv.lock @@ -1463,7 +1463,7 @@ wheels = [ [[package]] name = "openai" -version = "1.97.1" +version = "1.99.6" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "anyio" }, @@ -1475,9 +1475,9 @@ dependencies = [ { name = "tqdm" }, { name = "typing-extensions" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/a6/57/1c471f6b3efb879d26686d31582997615e969f3bb4458111c9705e56332e/openai-1.97.1.tar.gz", hash = "sha256:a744b27ae624e3d4135225da9b1c89c107a2a7e5bc4c93e5b7b5214772ce7a4e", size = 494267, upload-time = "2025-07-22T13:10:12.607Z" } +sdist = { url = "https://files.pythonhosted.org/packages/11/45/38a87bd6949236db5ae3132f41d5861824702b149f86d2627d6900919103/openai-1.99.6.tar.gz", hash = "sha256:f48f4239b938ef187062f3d5199a05b69711d8b600b9a9b6a3853cd271799183", size = 505364, upload-time = "2025-08-09T15:20:54.438Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/ee/35/412a0e9c3f0d37c94ed764b8ac7adae2d834dbd20e69f6aca582118e0f55/openai-1.97.1-py3-none-any.whl", hash = "sha256:4e96bbdf672ec3d44968c9ea39d2c375891db1acc1794668d8149d5fa6000606", size = 764380, upload-time = "2025-07-22T13:10:10.689Z" }, + { url = "https://files.pythonhosted.org/packages/d6/dd/9aa956485c2856346b3181542fbb0aea4e5b457fa7a523944726746da8da/openai-1.99.6-py3-none-any.whl", hash = "sha256:e40d44b2989588c45ce13819598788b77b8fb80ba2f7ae95ce90d14e46f1bd26", size = 786296, upload-time = "2025-08-09T15:20:51.95Z" }, ] [[package]] @@ -1541,7 +1541,7 @@ requires-dist = [ { name = "litellm", marker = "extra == 'litellm'", specifier = ">=1.67.4.post1,<2" }, { name = "mcp", marker = "python_full_version >= '3.10'", specifier = ">=1.11.0,<2" }, { name = "numpy", marker = "python_full_version >= '3.10' and extra == 'voice'", specifier = ">=2.2.0,<3" }, - { name = "openai", specifier = ">=1.97.1,<2" }, + { name = "openai", specifier = ">=1.99.6,<2" }, { name = "pydantic", specifier = ">=2.10,<3" }, { name = "requests", specifier = ">=2.0,<3" }, { name = "types-requests", specifier = ">=2.0,<3" },