Skip to content

Commit 541f8cd

Browse files
committed
Update lifecycle.py
1 parent e26ce50 commit 541f8cd

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

src/backend/v4/magentic_agents/common/lifecycle.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -139,26 +139,34 @@ def get_chat_client(self, chat_client) -> AzureAIAgentClient:
139139
"""Return the underlying ChatClientProtocol (AzureAIAgentClient)."""
140140
if chat_client:
141141
return chat_client
142-
if self._agent and self._agent.chat_client and self._agent.chat_client.agent_id is not None:
142+
if (
143+
self._agent
144+
and self._agent.chat_client
145+
and self._agent.chat_client.agent_id is not None
146+
):
143147
return self._agent.chat_client # type: ignore
144148
chat_client = AzureAIAgentClient(
145-
project_endpoint=self.project_endpoint,
146-
model_deployment_name=self.model_deployment_name,
147-
async_credential=self.creds,
148-
)
149-
self.logger.info("Created new AzureAIAgentClient for get chat client", extra={"agent_id": chat_client.agent_id})
149+
project_endpoint=self.project_endpoint,
150+
model_deployment_name=self.model_deployment_name,
151+
async_credential=self.creds,
152+
)
153+
self.logger.info(
154+
"Created new AzureAIAgentClient for get chat client",
155+
extra={"agent_id": chat_client.agent_id},
156+
)
150157
return chat_client
151-
158+
152159
async def get_database_team_agent(self) -> Optional[AzureAIAgentClient]:
153160
"""Retrieve existing team agent from database, if any."""
154161
chat_client = None
155162
try:
156163
currentAgent = await self.memory_store.get_team_agent(
157-
team_id=self.team_config.team_id,
158-
agent_name=self.agent_name
164+
team_id=self.team_config.team_id, agent_name=self.agent_name
159165
)
160166
if currentAgent and currentAgent.agent_foundry_id:
161-
agent = await self.client.get_agent(agent_id=currentAgent.agent_foundry_id)
167+
agent = await self.client.get_agent(
168+
agent_id=currentAgent.agent_foundry_id
169+
)
162170
if agent and agent.agent_id is not None:
163171
chat_client = AzureAIAgentClient(
164172
project_endpoint=self.project_endpoint,
@@ -167,17 +175,19 @@ async def get_database_team_agent(self) -> Optional[AzureAIAgentClient]:
167175
async_credential=self.creds,
168176
)
169177

170-
except Exception as ex: # Consider narrowing this to specific exceptions if possible
178+
except (
179+
Exception
180+
) as ex: # Consider narrowing this to specific exceptions if possible
171181
self.logger.error("Failed to initialize Get database team agent: %s", ex)
172182
return chat_client
173-
183+
174184
async def save_database_team_agent(self) -> None:
175185
"""Save current team agent to database."""
176186
try:
177187
if self._agent.chat_client.agent_id is None:
178188
self.logger.error("Cannot save database team agent: agent_id is None")
179-
return
180-
189+
return
190+
181191
currentAgent = CurrentTeamAgent(
182192
team_id=self.team_config.team_id,
183193
team_name=self.team_config.name,
@@ -190,8 +200,7 @@ async def save_database_team_agent(self) -> None:
190200

191201
except Exception as ex:
192202
self.logger.error("Failed to save save database: %s", ex)
193-
194-
203+
195204
async def _prepare_mcp_tool(self) -> None:
196205
"""Translate MCPConfig to a HostedMCPTool (agent_framework construct)."""
197206
if not self.mcp_cfg:
@@ -245,8 +254,6 @@ def __init__(
245254
False # reserved if you add ephemeral agent cleanup
246255
)
247256

248-
249-
250257
# async def open(self) -> "AzureAgentBase":
251258
# if self._stack is not None:
252259
# return self

0 commit comments

Comments
 (0)