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 <noreply@anthropic.com>
This commit is contained in:
theCyberTech
2026-07-11 19:30:51 +08:00
parent 37a8267355
commit 6f62ed826d

View File

@@ -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(