From 6f62ed826dcbe490fef90901e9141e654209c88f Mon Sep 17 00:00:00 2001 From: theCyberTech <84775494+theCyberTech@users.noreply.github.com> Date: Sat, 11 Jul 2026 19:30:51 +0800 Subject: [PATCH] fix(llms/openai): fix mypy list-item type error in message conversion _convert_message_to_responses_input_items() was annotated to return list[dict[str, Any]], but the passthrough branch returns the LLMMessage argument unchanged. Lists are invariant in mypy, so a bare LLMMessage (TypedDict) isn't assignable into a list[dict[str, Any]] return - this was flagged by CI's type-checker job across all Python versions. Widened the return type (and the local list built in the tool_calls branch) to list[dict[str, Any] | LLMMessage], matching what the function actually returns. Confirmed with a local mypy run and the full openai/agent_utils test suites (176 passed). Co-Authored-By: Claude Sonnet 5 --- lib/crewai/src/crewai/llms/providers/openai/completion.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/crewai/src/crewai/llms/providers/openai/completion.py b/lib/crewai/src/crewai/llms/providers/openai/completion.py index 4b872d1d2..7df42e4f1 100644 --- a/lib/crewai/src/crewai/llms/providers/openai/completion.py +++ b/lib/crewai/src/crewai/llms/providers/openai/completion.py @@ -645,7 +645,7 @@ class OpenAICompletion(BaseLLM): def _convert_message_to_responses_input_items( self, message: LLMMessage - ) -> list[dict[str, Any]]: + ) -> list[dict[str, Any] | LLMMessage]: """Convert a Chat-Completions-style message into Responses API input items. The Responses API has no message shape for an assistant turn carrying @@ -657,7 +657,7 @@ class OpenAICompletion(BaseLLM): role = message.get("role") if role == "assistant" and message.get("tool_calls"): - items: list[dict[str, Any]] = [] + items: list[dict[str, Any] | LLMMessage] = [] for tool_call in message["tool_calls"]: function = tool_call.get("function", {}) items.append(