33import logging
44from typing import List , Optional
55
6- from agent_framework import (
7- ChatAgent ,
8- ChatMessage ,
9- Role ,
10- HostedCodeInterpreterTool ,
11- )
6+ from agent_framework import (ChatAgent , ChatMessage , HostedCodeInterpreterTool ,
7+ Role )
8+ from agent_framework_azure_ai import \
9+ AzureAIAgentClient # Provided by agent_framework
10+ from azure .ai .projects .aio import AIProjectClient
1211from azure .ai .projects .models import ConnectionType
13- from agent_framework_azure_ai import AzureAIAgentClient # Provided by agent_framework
14-
15-
12+ from common .config .app_config import config
13+ from v4 .config .agent_registry import agent_registry
1614from v4 .magentic_agents .common .lifecycle import AzureAgentBase
1715from v4 .magentic_agents .models .agent_models import MCPConfig , SearchConfig
18- from v4 .config .agent_registry import agent_registry
1916
2017
2118class FoundryAgentTemplate (AzureAgentBase ):
@@ -45,6 +42,7 @@ def __init__(
4542 self .enable_code_interpreter = enable_code_interpreter
4643 self .search = search_config
4744 self .logger = logging .getLogger (__name__ )
45+ self .project_client = config .get_ai_project_client ()
4846
4947 # Decide early whether Azure Search mode should be activated
5048 self ._use_azure_search = self ._is_azure_search_requested ()
@@ -128,7 +126,7 @@ async def _create_azure_search_enabled_client(self):
128126 resolved_connection_id = None
129127
130128 try :
131- async for connection in self .client . project_client .connections .list ():
129+ async for connection in self .project_client .connections .list ():
132130 if connection .type == ConnectionType .AZURE_AI_SEARCH :
133131 # Allow direct id override
134132 if desired_connection_id and connection .id == desired_connection_id :
@@ -164,7 +162,7 @@ async def _create_azure_search_enabled_client(self):
164162
165163 # Create agent with raw tool
166164 try :
167- azure_agent = await self .client .project_client . agents . create_agent (
165+ azure_agent = await self .client .create_agent (
168166 model = self .model_deployment_name ,
169167 name = self .agent_name ,
170168 instructions = (
@@ -193,8 +191,10 @@ async def _create_azure_search_enabled_client(self):
193191 )
194192
195193 chat_client = AzureAIAgentClient (
196- project_client = self .client .project_client ,
194+ project_client = self .project_client ,
195+ #agents_client=self.client,
197196 agent_id = azure_agent .id ,
197+ async_credential = self .creds ,
198198 )
199199 return chat_client
200200 except Exception as ex :
@@ -233,7 +233,11 @@ async def _after_open(self) -> None:
233233 self .logger .info ("Initializing agent in MCP mode." )
234234 tools = await self ._collect_tools ()
235235 self ._agent = ChatAgent (
236- chat_client = self .client ,
236+ chat_client = AzureAIAgentClient (
237+ project_endpoint = self .project_endpoint ,
238+ model_deployment_name = self .model_deployment_name ,
239+ async_credential = self .creds ,
240+ ),
237241 instructions = self .agent_instructions ,
238242 name = self .agent_name ,
239243 description = self .agent_description ,
@@ -293,23 +297,24 @@ async def close(self) -> None:
293297# -------------------------
294298# Factory
295299# -------------------------
296- async def create_foundry_agent (
297- agent_name : str ,
298- agent_description : str ,
299- agent_instructions : str ,
300- model_deployment_name : str ,
301- mcp_config : MCPConfig | None ,
302- search_config : SearchConfig | None ,
303- ) -> FoundryAgentTemplate :
304- """Factory to create and open a FoundryAgentTemplate."""
305- agent = FoundryAgentTemplate (
306- agent_name = agent_name ,
307- agent_description = agent_description ,
308- agent_instructions = agent_instructions ,
309- model_deployment_name = model_deployment_name ,
310- enable_code_interpreter = True ,
311- mcp_config = mcp_config ,
312- search_config = search_config ,
313- )
314- await agent .open ()
315- return agent
300+ # async def create_foundry_agent(
301+ # agent_name: str,
302+ # agent_description: str,
303+ # agent_instructions: str,
304+ # model_deployment_name: str,
305+ # mcp_config: MCPConfig | None,
306+ # search_config: SearchConfig | None,
307+ # ) -> FoundryAgentTemplate:
308+ # """Factory to create and open a FoundryAgentTemplate."""
309+ # agent = FoundryAgentTemplate(
310+ # agent_name=agent_name,
311+ # agent_description=agent_description,
312+ # agent_instructions=agent_instructions,
313+ # model_deployment_name=model_deployment_name,
314+ # enable_code_interpreter=True,
315+ # mcp_config=mcp_config,
316+ # search_config=search_config,
317+
318+ # )
319+ # await agent.open()
320+ # return agent
0 commit comments