@@ -18,31 +18,39 @@ class ReasoningAgentTemplate(MCPEnabledBase):
1818 No Azure AI Agents client is needed here. We only need a token provider for SK.
1919 """
2020
21- def __init__ (self , agent_name : str ,
22- agent_description : str ,
23- agent_instructions : str ,
24- model_deployment_name : str ,
25- azure_openai_endpoint : str ,
26- search_config : SearchConfig | None = None ,
27- mcp_config : MCPConfig | None = None ) -> None :
21+ def __init__ (
22+ self ,
23+ agent_name : str ,
24+ agent_description : str ,
25+ agent_instructions : str ,
26+ model_deployment_name : str ,
27+ azure_openai_endpoint : str ,
28+ search_config : SearchConfig | None = None ,
29+ mcp_config : MCPConfig | None = None ,
30+ ) -> None :
2831 super ().__init__ (mcp = mcp_config )
2932 self .agent_name = agent_name
3033 self .agent_description = agent_description
3134 self .agent_instructions = agent_instructions
3235 self ._model_deployment_name = model_deployment_name
3336 self ._openai_endpoint = azure_openai_endpoint
34- self .search_config = search_config
37+ self .search_config = search_config
3538 self .reasoning_search : ReasoningSearch | None = None
3639 self .logger = logging .getLogger (__name__ )
3740
41+ def ad_token_provider (self ) -> str :
42+ credential = config .get_azure_credentials ()
43+ token = credential .get_token (config .AZURE_COGNITIVE_SERVICES )
44+ return token .token
45+
3846 async def _after_open (self ) -> None :
3947 self .kernel = Kernel ()
4048
41-
49+ # Add Azure OpenAI Chat Completion service
4250 chat = AzureChatCompletion (
4351 deployment_name = self ._model_deployment_name ,
4452 endpoint = self ._openai_endpoint ,
45- ad_token_provider = await config . get_access_token ()
53+ ad_token_provider = self . ad_token_provider ,
4654 )
4755 self .kernel .add_service (chat )
4856
@@ -63,34 +71,36 @@ async def _after_open(self) -> None:
6371 kernel = self .kernel ,
6472 name = self .agent_name ,
6573 description = self .agent_description ,
66- instructions = self .agent_instructions
74+ instructions = self .agent_instructions ,
6775 )
68-
76+
6977 async def invoke (self , message : str ):
7078 """Invoke the agent with a message."""
7179 if not self ._agent :
7280 raise RuntimeError ("Agent not initialized. Call open() first." )
73-
81+
7482 async for response in self ._agent .invoke (message ):
7583 yield response
76-
84+
85+
7786# Backward‑compatible factory
7887async def create_reasoning_agent (
79- agent_name : str ,
80- agent_description : str ,
81- agent_instructions : str ,
82- model_deployment_name : str ,
83- azure_openai_endpoint : str ,
84- search_config : SearchConfig | None = None ,
85- mcp_config : MCPConfig | None = None ) -> ReasoningAgentTemplate :
88+ agent_name : str ,
89+ agent_description : str ,
90+ agent_instructions : str ,
91+ model_deployment_name : str ,
92+ azure_openai_endpoint : str ,
93+ search_config : SearchConfig | None = None ,
94+ mcp_config : MCPConfig | None = None ,
95+ ) -> ReasoningAgentTemplate :
8696 agent = ReasoningAgentTemplate (
87- agent_name = agent_name ,
88- agent_description = agent_description ,
97+ agent_name = agent_name ,
98+ agent_description = agent_description ,
8999 agent_instructions = agent_instructions ,
90100 model_deployment_name = model_deployment_name ,
91101 azure_openai_endpoint = azure_openai_endpoint ,
92- search_config = search_config ,
93- mcp_config = mcp_config
102+ search_config = search_config ,
103+ mcp_config = mcp_config ,
94104 )
95105 await agent .open ()
96106 return agent
0 commit comments