Skip to content

Commit 7ad6447

Browse files
committed
fix(azure-ai): widen response_format types + normalize json_object/text dict shapes
Per @Copilot review: - widen _merge_options and _normalize_response_format to accept str | ResponseFormatJsonSchemaType | dict | None, matching AzureAIAgent's AgentsApiResponseFormatOption - map {'type': 'json_object'} and {'type': 'text'} dict shapes to their canonical string form so the Azure SDK sees the expected type - narrow return type to str | ResponseFormatJsonSchemaType | None (dict is only passed through as an unrecognized escape hatch, never intentionally) Avoids importing AgentsApiResponseFormatOption directly (would be circular — azure_ai_agent imports from this module). The inline union keeps type checkers satisfied without duplicating the alias definition.
1 parent a89215e commit 7ad6447

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

python/semantic_kernel/agents/azure_ai/agent_thread_actions.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ def _merge_options(
893893
*,
894894
agent: "AzureAIAgent",
895895
model: str | None = None,
896-
response_format: ResponseFormatJsonSchemaType | None = None,
896+
response_format: str | ResponseFormatJsonSchemaType | dict[str, Any] | None = None,
897897
temperature: float | None = None,
898898
top_p: float | None = None,
899899
metadata: dict[str, str] | None = None,
@@ -919,16 +919,22 @@ def _merge_options(
919919

920920
@classmethod
921921
def _normalize_response_format(
922-
cls: type[_T], response_format: ResponseFormatJsonSchemaType | dict[str, Any] | None
923-
) -> ResponseFormatJsonSchemaType | dict[str, Any] | None:
922+
cls: type[_T], response_format: str | ResponseFormatJsonSchemaType | dict[str, Any] | None
923+
) -> str | ResponseFormatJsonSchemaType | None:
924924
"""Normalize structured output response formats for Azure SDK consumers."""
925925
if response_format is None or isinstance(response_format, ResponseFormatJsonSchemaType):
926926
return response_format
927927

928928
if not isinstance(response_format, dict):
929929
return response_format
930930

931-
if response_format.get("type") != "json_schema":
931+
# Map simple dict shapes to the string form the Azure SDK expects.
932+
# {"type": "json_object"} / {"type": "text"} both have canonical string equivalents.
933+
rf_type = response_format.get("type")
934+
if rf_type in ("json_object", "text"):
935+
return rf_type
936+
937+
if rf_type != "json_schema":
932938
return response_format
933939

934940
json_schema = response_format.get("json_schema")

0 commit comments

Comments
 (0)