33import logging
44from abc import ABC , abstractmethod
55from typing import Any , Generic , List , Optional , TypeVar , Union
6- import json
76
8- # Removed broken import:
9- # from azure.ai.projects.models import ResponseFormatJsonSchema, ResponseFormatJsonSchemaType
7+ from azure .ai .agents .models import (
8+ ResponseFormatJsonSchema ,
9+ ResponseFormatJsonSchemaType ,
10+ )
1011
1112from semantic_kernel .agents .azure_ai .azure_ai_agent import AzureAIAgent
1213from semantic_kernel .functions import KernelArguments
@@ -106,30 +107,23 @@ async def setup(self) -> AzureAIAgent:
106107
107108 kernel_args = self .get_kernel_arguments ()
108109
109- # Define an agent on the Azure AI agent service
110- # Construct response_format manually
111- response_format = None
112- if self .response_object :
113- response_format = {
114- "type" : "json_schema" ,
115- "json_schema" : {
116- "name" : self .response_object .__name__ ,
117- "description" : f"respond with { self .response_object .__name__ .lower ()} " ,
118- "schema" : self .response_object .model_json_schema ()
119- }
120- }
121-
122110 try :
111+ # Define an agent on the Azure AI agent service
123112 agent_definition = await self .config .ai_project_client .agents .create_agent (
124113 model = _deployment_name ,
125114 name = _name ,
126115 instructions = template_content ,
127116 temperature = self .temperature ,
128- response_format = response_format ,
117+ response_format = ResponseFormatJsonSchemaType (
118+ json_schema = ResponseFormatJsonSchema (
119+ name = self .response_object .__name__ ,
120+ description = f"respond with { self .response_object .__name__ .lower ()} " ,
121+ schema = self .response_object .model_json_schema (),
122+ )
123+ ),
129124 )
130125 except Exception as exc :
131126 logger .error ("Error creating agent definition: %s" , exc )
132- raise
133127 # Set the agent definition with the response format
134128
135129 # Create a Semantic Kernel agent based on the agent definition
@@ -157,4 +151,4 @@ async def execute(self, inputs: Any) -> T:
157151 """Execute the agent with the given inputs."""
158152 agent = await self .get_agent ()
159153 response = await agent .invoke (inputs )
160- return response # Type will be inferred from T
154+ return response # Type will be inferred from T
0 commit comments