Python: multiple bug fixes (#3150)

* fix Python: kwargs are not passed to _prepare_thread_and_messages in ChatAgent.run
Fixes #3118

* fix Python: [Bug]: model_id versus model_deployment_name is confusing in Azure AI Agents
Fixes #3147

* add types

* fixed type and docstring
This commit is contained in:
Eduard van Valkenburg
2026-01-12 02:01:41 +01:00
committed by GitHub
Unverified
parent 6445b6b3a6
commit 551c2c3abe
5 changed files with 35 additions and 6 deletions
@@ -421,6 +421,13 @@ class AzureAIClient(OpenAIBaseResponsesClient):
return run_options
@override
def _check_model_presence(self, run_options: dict[str, Any]) -> None:
if not run_options.get("model"):
if not self.model_id:
raise ValueError("model_deployment_name must be a non-empty string")
run_options["model"] = self.model_id
def _transform_input_for_azure_ai(self, input_items: list[dict[str, Any]]) -> list[dict[str, Any]]:
"""Transform input items to match Azure AI Projects expected schema.
@@ -834,7 +834,7 @@ class ChatAgent(BaseAgent): # type: ignore[misc]
"""
input_messages = self._normalize_messages(messages)
thread, run_chat_options, thread_messages = await self._prepare_thread_and_messages(
thread=thread, input_messages=input_messages
thread=thread, input_messages=input_messages, **kwargs
)
normalized_tools: list[ToolProtocol | Callable[..., Any] | MutableMapping[str, Any]] = ( # type:ignore[reportUnknownVariableType]
[] if tools is None else tools if isinstance(tools, list) else [tools]
@@ -820,8 +820,10 @@ class AIFunction(BaseTool, Generic[ArgsT, ReturnT]):
else:
logger.info(f"Function {self.name} succeeded.")
if OBSERVABILITY_SETTINGS.SENSITIVE_DATA_ENABLED: # type: ignore[name-defined]
from ._types import prepare_function_call_results
try:
json_result = json.dumps(result)
json_result = prepare_function_call_results(result)
except (TypeError, OverflowError):
span.set_attribute(OtelAttr.TOOL_RESULT, "<non-serializable result>")
logger.debug("Function result: <non-serializable result>")
@@ -1,5 +1,6 @@
# Copyright (c) Microsoft. All rights reserved.
import sys
from collections.abc import Mapping
from typing import Any, TypeVar
from urllib.parse import urljoin
@@ -18,6 +19,11 @@ from ._shared import (
AzureOpenAISettings,
)
if sys.version_info >= (3, 12):
from typing import override # type: ignore # pragma: no cover
else:
from typing_extensions import override # type: ignore[import] # pragma: no cover
TAzureOpenAIResponsesClient = TypeVar("TAzureOpenAIResponsesClient", bound="AzureOpenAIResponsesClient")
@@ -144,3 +150,10 @@ class AzureOpenAIResponsesClient(AzureOpenAIConfigMixin, OpenAIBaseResponsesClie
client=async_client,
instruction_role=instruction_role,
)
@override
def _check_model_presence(self, run_options: dict[str, Any]) -> None:
if not run_options.get("model"):
if not self.model_id:
raise ValueError("deployment_name must be a non-empty string")
run_options["model"] = self.model_id
@@ -414,10 +414,7 @@ class OpenAIBaseResponsesClient(OpenAIBase, BaseChatClient):
run_options["input"] = request_input
# model id
if not run_options.get("model"):
if not self.model_id:
raise ValueError("model_id must be a non-empty string")
run_options["model"] = self.model_id
self._check_model_presence(run_options)
# translations between ChatOptions and Responses API
translations = {
@@ -479,6 +476,16 @@ class OpenAIBaseResponsesClient(OpenAIBase, BaseChatClient):
return run_options
def _check_model_presence(self, run_options: dict[str, Any]) -> None:
"""Check if the 'model' param is present, and if not raise a Error.
Since AzureAIClients use a different param for this, this method is overridden in those clients.
"""
if not run_options.get("model"):
if not self.model_id:
raise ValueError("model_id must be a non-empty string")
run_options["model"] = self.model_id
def _get_current_conversation_id(self, chat_options: ChatOptions, **kwargs: Any) -> str | None:
"""Get the current conversation ID from chat options or kwargs."""
return chat_options.conversation_id or kwargs.get("conversation_id")