|
3 | 3 | import uuid |
4 | 4 | from typing import Any, Dict, List, Optional, Tuple |
5 | 5 |
|
6 | | -from azure.ai.projects.models import (ResponseFormatJsonSchema, |
| 6 | +from azure.ai.agents.models import (ResponseFormatJsonSchema, |
7 | 7 | ResponseFormatJsonSchemaType) |
8 | 8 | from context.cosmos_memory_kernel import CosmosMemoryContext |
9 | 9 | from event_utils import track_event_if_configured |
@@ -133,37 +133,43 @@ async def create( |
133 | 133 | try: |
134 | 134 | logging.info("Initializing PlannerAgent from async init azure AI Agent") |
135 | 135 |
|
| 136 | + # Construct response_format with the required 'type' field |
| 137 | + response_format = { |
| 138 | + "type": "json_schema", # Add the missing type field |
| 139 | + "json_schema": { |
| 140 | + "name": PlannerResponsePlan.__name__, |
| 141 | + "description": f"respond with {PlannerResponsePlan.__name__.lower()}", |
| 142 | + "schema": PlannerResponsePlan.model_json_schema() |
| 143 | + } |
| 144 | + } |
| 145 | + |
136 | 146 | # Create the Azure AI Agent using AppConfig with string instructions |
137 | 147 | agent_definition = await cls._create_azure_ai_agent_definition( |
138 | 148 | agent_name=agent_name, |
139 | | - instructions=cls._get_template(), # Pass the formatted string, not an object |
| 149 | + instructions=cls._get_template(), # Pass the formatted string |
140 | 150 | temperature=0.0, |
141 | | - response_format=ResponseFormatJsonSchemaType( |
142 | | - json_schema=ResponseFormatJsonSchema( |
143 | | - name=PlannerResponsePlan.__name__, |
144 | | - description=f"respond with {PlannerResponsePlan.__name__.lower()}", |
145 | | - schema=PlannerResponsePlan.model_json_schema(), |
146 | | - ) |
147 | | - ), |
| 151 | + response_format=response_format, |
148 | 152 | ) |
149 | 153 |
|
150 | | - return cls( |
151 | | - session_id=session_id, |
152 | | - user_id=user_id, |
153 | | - memory_store=memory_store, |
154 | | - tools=tools, |
155 | | - system_message=system_message, |
156 | | - agent_name=agent_name, |
157 | | - available_agents=available_agents, |
158 | | - agent_instances=agent_instances, |
159 | | - client=client, |
160 | | - definition=agent_definition, |
161 | | - ) |
162 | | - |
163 | | - except Exception as e: |
164 | | - logging.error(f"Failed to create Azure AI Agent for PlannerAgent: {e}") |
| 154 | + except Exception as exc: |
| 155 | + logging.error("Error initializing PlannerAgent definition: %s", exc) |
165 | 156 | raise |
166 | 157 |
|
| 158 | + return cls( |
| 159 | + session_id=session_id, |
| 160 | + user_id=user_id, |
| 161 | + memory_store=memory_store, |
| 162 | + tools=tools, |
| 163 | + system_message=system_message, |
| 164 | + agent_name=agent_name, |
| 165 | + available_agents=available_agents, |
| 166 | + agent_instances=agent_instances, |
| 167 | + client=client, |
| 168 | + definition=agent_definition, |
| 169 | + ) |
| 170 | + |
| 171 | + |
| 172 | + |
167 | 173 | async def handle_input_task(self, input_task: InputTask) -> str: |
168 | 174 | """Handle the initial input task from the user. |
169 | 175 |
|
|
0 commit comments