diff --git a/src/agents/models/chatcmpl_converter.py b/src/agents/models/chatcmpl_converter.py index 25d9f083..31dc6f8f 100644 --- a/src/agents/models/chatcmpl_converter.py +++ b/src/agents/models/chatcmpl_converter.py @@ -302,7 +302,11 @@ def ensure_assistant_message() -> ChatCompletionAssistantMessageParam: return current_assistant_msg for item in items: - # 1) Check easy input message + # 1) Ignore reasoning items, which are not sent to the LLM. + if isinstance(item, dict) and item.get("type") == "reasoning": + continue + + # 2) Check easy input message if easy_msg := cls.maybe_easy_input_message(item): role = easy_msg["role"] content = easy_msg["content"] diff --git a/tests/test_openai_chatcompletions_converter.py b/tests/test_openai_chatcompletions_converter.py index bcfca549..2591a01e 100644 --- a/tests/test_openai_chatcompletions_converter.py +++ b/tests/test_openai_chatcompletions_converter.py @@ -428,3 +428,17 @@ def test_assistant_messages_in_history(): assert messages[1]["content"] == "Hello?" assert messages[2]["role"] == "user" assert messages[2]["content"] == "What was my Name?" + + +def test_items_to_messages_ignores_reasoning_item() -> None: + """ + A `reasoning` item in the input should be ignored, resulting in an empty + message list if it's the only item. + """ + reasoning_item: TResponseInputItem = { + "type": "reasoning", + "reasoning": "Thinking about what to do...", # type: ignore + } + messages = Converter.items_to_messages([reasoning_item]) + assert len(messages) == 0 +