11from __future__ import annotations
22
3- import os
43from contextlib import AsyncExitStack
54from typing import Any , Optional
65
@@ -29,7 +28,7 @@ def __init__(self, mcp: MCPConfig | None = None) -> None:
2928 self ._stack : AsyncExitStack | None = None
3029 self .mcp_cfg : MCPConfig | None = mcp
3130 self .mcp_tool : HostedMCPTool | None = None
32- self ._agent : ChatAgent | None = None
31+ self ._agent : ChatAgent | None = None
3332
3433 async def open (self ) -> "MCPEnabledBase" :
3534 if self ._stack is not None :
@@ -47,12 +46,12 @@ async def close(self) -> None:
4746 if self ._agent and hasattr (self ._agent , "close" ):
4847 try :
4948 await self ._agent .close () # AzureAIAgentClient has async close
50- except Exception :
49+ except Exception :
5150 pass
5251 # Unregister from registry if present
5352 try :
5453 agent_registry .unregister_agent (self )
55- except Exception :
54+ except Exception :
5655 pass
5756 await self ._stack .aclose ()
5857 finally :
@@ -89,7 +88,7 @@ async def _prepare_mcp_tool(self) -> None:
8988 )
9089 await self ._stack .enter_async_context (mcp_tool )
9190 self .mcp_tool = mcp_tool # Store for later use
92- except Exception :
91+ except Exception :
9392 self .mcp_tool = None
9493
9594
@@ -106,7 +105,7 @@ def __init__(self, mcp: MCPConfig | None = None, model_deployment_name: str | No
106105 super ().__init__ (mcp = mcp )
107106 self .creds : Optional [DefaultAzureCredential ] = None
108107 self .client : Optional [AzureAIAgentClient ] = None
109-
108+
110109 self ._created_ephemeral : bool = (
111110 False # reserved if you add ephemeral agent cleanup
112111 )
@@ -118,7 +117,6 @@ async def open(self) -> "AzureAgentBase":
118117 return self
119118 self ._stack = AsyncExitStack ()
120119
121-
122120 # Acquire credential
123121 self .creds = DefaultAzureCredential ()
124122 await self ._stack .enter_async_context (self .creds )
@@ -130,7 +128,7 @@ async def open(self) -> "AzureAgentBase":
130128 # async_credential=self.creds,
131129 # )
132130
133- #Create AgentsClient
131+ # Create AgentsClient
134132 self .client = AgentsClient (
135133 endpoint = self .project_endpoint ,
136134 credential = self .creds ,
@@ -146,7 +144,7 @@ async def open(self) -> "AzureAgentBase":
146144 # Register agent (best effort)
147145 try :
148146 agent_registry .register_agent (self )
149- except Exception :
147+ except Exception :
150148 pass
151149
152150 return self
@@ -170,25 +168,25 @@ async def close(self) -> None:
170168 if self ._agent and hasattr (self ._agent , "close" ):
171169 try :
172170 await self ._agent .close ()
173- except Exception :
171+ except Exception :
174172 pass
175173
176174 # Unregister from registry
177175 try :
178176 agent_registry .unregister_agent (self )
179- except Exception :
177+ except Exception :
180178 pass
181179
182180 # Close credential and project client
183181 if self .client :
184182 try :
185183 await self .client .close ()
186- except Exception :
184+ except Exception :
187185 pass
188186 if self .creds :
189187 try :
190188 await self .creds .close ()
191- except Exception :
189+ except Exception :
192190 pass
193191
194192 finally :
0 commit comments