33import logging
44from typing import List , Optional
55
6- from agent_framework import (ChatAgent , ChatMessage , HostedCodeInterpreterTool ,
7- Role )
6+ from agent_framework import (Agent , Message , ChatOptions )
87from agent_framework_azure_ai import \
98 AzureAIClient # Provided by agent_framework
109from azure .ai .projects .models import (
1110 PromptAgentDefinition ,
12- AzureAISearchAgentTool ,
11+ AzureAISearchTool ,
1312 AzureAISearchToolResource ,
1413 AISearchIndexResource ,
1514)
@@ -92,17 +91,13 @@ def _is_azure_search_requested(self) -> bool:
9291 return False
9392
9493 async def _collect_tools (self ) -> List :
95- """Collect tool definitions for ChatAgent (MCP path only)."""
94+ """Collect tool definitions for Agent (MCP path only)."""
9695 tools : List = []
9796
98- # Code Interpreter (only in MCP path per incompatibility note)
97+ # Code Interpreter is now handled server-side via AzureAIClient agent definition.
98+ # HostedCodeInterpreterTool was removed in rc4.
9999 if self .enable_code_interpreter :
100- try :
101- code_tool = HostedCodeInterpreterTool ()
102- tools .append (code_tool )
103- self .logger .info ("Added Code Interpreter tool." )
104- except Exception as ie :
105- self .logger .error ("Code Interpreter tool creation failed: %s" , ie )
100+ self .logger .info ("Code Interpreter requested — handled server-side by AzureAIClient." )
106101
107102 # MCP Tool (from base class)
108103 if self .mcp_tool :
@@ -121,7 +116,7 @@ async def _create_azure_search_enabled_client(self) -> Optional[AzureAIClient]:
121116
122117 This uses the AIProjectClient.agents.create_version() approach with:
123118 - PromptAgentDefinition for agent configuration
124- - AzureAISearchAgentTool with AzureAISearchToolResource for search capability
119+ - AzureAISearchTool with AzureAISearchToolResource for search capability
125120 - AISearchIndexResource for index configuration with project_connection_id
126121
127122 Requirements:
@@ -167,7 +162,7 @@ async def _create_azure_search_enabled_client(self) -> Optional[AzureAIClient]:
167162 top_k ,
168163 )
169164
170- # Create agent using create_version with PromptAgentDefinition and AzureAISearchAgentTool
165+ # Create agent using create_version with PromptAgentDefinition and AzureAISearchTool
171166 # This approach matches the Knowledge Mining Solution Accelerator pattern
172167 try :
173168 enhanced_instructions = (
@@ -181,7 +176,7 @@ async def _create_azure_search_enabled_client(self) -> Optional[AzureAIClient]:
181176 model = self .model_deployment_name ,
182177 instructions = enhanced_instructions ,
183178 tools = [
184- AzureAISearchAgentTool (
179+ AzureAISearchTool (
185180 azure_ai_search = AzureAISearchToolResource (
186181 indexes = [
187182 AISearchIndexResource (
@@ -253,37 +248,39 @@ async def _after_open(self) -> None:
253248 )
254249
255250 # In Azure Search raw tool path, tools/tool_choice are handled server-side.
256- self ._agent = ChatAgent (
251+ self ._agent = Agent (
257252 id = self .get_agent_id (),
258- chat_client = chat_client ,
253+ client = chat_client ,
259254 instructions = self .agent_instructions ,
260255 name = self .agent_name ,
261256 description = self .agent_description ,
262- tool_choice = "required" , # Force usage
263- temperature = temp ,
264- model_id = self .model_deployment_name ,
265- default_options = {"store" : False }, # Client-managed conversation to avoid stale tool call IDs across rounds
257+ default_options = ChatOptions (
258+ store = False ,
259+ tool_choice = "required" ,
260+ temperature = temp ,
261+ ),
266262 )
267263 else :
268264 # MCP path (also used by RAI agent which has no tools)
269265 self .logger .info ("Initializing agent in MCP mode." )
270266 tools = await self ._collect_tools ()
271- self ._agent = ChatAgent (
267+ self ._agent = Agent (
272268 id = self .get_agent_id (),
273- chat_client = self .get_chat_client (),
269+ client = self .get_chat_client (),
274270 instructions = self .agent_instructions ,
275271 name = self .agent_name ,
276272 description = self .agent_description ,
277273 tools = tools if tools else None ,
278- tool_choice = "auto" if tools else "none" ,
279- temperature = temp ,
280- model_id = self .model_deployment_name ,
281- default_options = {"store" : False }, # Client-managed conversation to avoid stale tool call IDs across rounds
274+ default_options = ChatOptions (
275+ store = False ,
276+ tool_choice = "auto" if tools else "none" ,
277+ temperature = temp ,
278+ ),
282279 )
283- self .logger .info ("Initialized ChatAgent '%s'" , self .agent_name )
280+ self .logger .info ("Initialized Agent '%s'" , self .agent_name )
284281
285282 except Exception as ex :
286- self .logger .error ("Failed to initialize ChatAgent : %s" , ex )
283+ self .logger .error ("Failed to initialize Agent : %s" , ex )
287284 raise
288285
289286 # Register agent globally
@@ -305,9 +302,9 @@ async def invoke(self, prompt: str):
305302 if not self ._agent :
306303 raise RuntimeError ("Agent not initialized; call open() first." )
307304
308- messages = [ChatMessage (role = Role . USER , text = prompt )]
305+ messages = [Message (role = "user" , text = prompt )]
309306
310- async for update in self ._agent .run_stream (messages ):
307+ async for update in self ._agent .run (messages , stream = True ):
311308 yield update
312309
313310 # -------------------------
0 commit comments