|
3 | 3 | import logging |
4 | 4 | from abc import ABC, abstractmethod |
5 | 5 | from typing import Any, Generic, List, Optional, TypeVar, Union |
| 6 | +import json |
6 | 7 |
|
7 | | -from azure.ai.projects.models import ( |
8 | | - ResponseFormatJsonSchema, |
9 | | - ResponseFormatJsonSchemaType, |
10 | | -) |
| 8 | +# Removed broken import: |
| 9 | +# from azure.ai.projects.models import ResponseFormatJsonSchema, ResponseFormatJsonSchemaType |
11 | 10 |
|
12 | 11 | from semantic_kernel.agents.azure_ai.azure_ai_agent import AzureAIAgent |
13 | 12 | from semantic_kernel.functions import KernelArguments |
@@ -107,23 +106,30 @@ async def setup(self) -> AzureAIAgent: |
107 | 106 |
|
108 | 107 | kernel_args = self.get_kernel_arguments() |
109 | 108 |
|
| 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 | + |
110 | 122 | try: |
111 | | - # Define an agent on the Azure AI agent service |
112 | 123 | agent_definition = await self.config.ai_project_client.agents.create_agent( |
113 | 124 | model=_deployment_name, |
114 | 125 | name=_name, |
115 | 126 | instructions=template_content, |
116 | 127 | temperature=self.temperature, |
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 | | - ), |
| 128 | + response_format=response_format, |
124 | 129 | ) |
125 | 130 | except Exception as exc: |
126 | 131 | logger.error("Error creating agent definition: %s", exc) |
| 132 | + raise |
127 | 133 | # Set the agent definition with the response format |
128 | 134 |
|
129 | 135 | # Create a Semantic Kernel agent based on the agent definition |
|
0 commit comments