Skip to content

Commit 4ab499b

Browse files
committed
recommended bug fixes and logging
1 parent c8b4631 commit 4ab499b

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

src/backend/v3/magentic_agents/foundry_agent.py

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
""" Agent template for building foundry agents with Azure AI Search, Bing, and MCP plugins. """
22

3+
import asyncio
34
import logging
45
from typing import List, Optional
56

@@ -39,7 +40,7 @@ def __init__(self, agent_name: str,
3940
self._bing_connection = None
4041
self.logger = logging.getLogger(__name__)
4142
# input validation
42-
if self.model_deployment_name is any(["o3", "o4-mini"]):
43+
if self.model_deployment_name in any(["o3", "o4-mini"]):
4344
raise ValueError("The current version of Foundry agents do not support reasoning models.")
4445

4546
# async def _make_bing_tool(self) -> Optional[BingGroundingTool]:
@@ -76,9 +77,11 @@ async def _make_azure_search_tool(self) -> Optional[AzureAISearchTool]:
7677
return search_tool
7778

7879
except Exception as ex:
79-
self.logger.error(f"Azure AI Search tool creation failed: {ex} Connection name: " /
80-
f"{self.search.connection_name} Index name: {self.search.index_name}" /
81-
" Make sure the connection exists in Azure AI Foundry portal")
80+
self.logger.error(
81+
"Azure AI Search tool creation failed: %s | Connection name: %s | Index name: %s | "
82+
"Make sure the connection exists in Azure AI Foundry portal",
83+
ex, self.search.connection_name, self.search.index_name
84+
)
8285
return None
8386

8487
async def _collect_tools_and_resources(self) -> tuple[List, dict]:
@@ -143,8 +146,39 @@ async def _after_open(self) -> None:
143146
self.logger.error("Failed to create AzureAIAgent: %s", ex)
144147
raise
145148

149+
# After self._agent creation in _after_open:
150+
# Diagnostics
151+
try:
152+
tool_names = [t.get("function", {}).get("name") for t in (definition.tools or []) if isinstance(t, dict)]
153+
self.logger.info(
154+
"Foundry agent '%s' initialized. Azure tools: %s | MCP plugin: %s",
155+
self.agent_name,
156+
tool_names,
157+
getattr(self.mcp_plugin, 'name', None)
158+
)
159+
if not tool_names and not plugins:
160+
self.logger.warning(
161+
"Foundry agent '%s' has no Azure tool definitions and no MCP plugin. "
162+
"Subsequent tool calls may fail.", self.agent_name
163+
)
164+
except Exception as diag_ex:
165+
self.logger.warning("Diagnostics collection failed: %s", diag_ex)
166+
146167
self.logger.info("%s initialized with %d tools and %d plugins", self.agent_name, len(tools), len(plugins))
147168

169+
async def fetch_run_details(self, thread_id: str, run_id: str):
170+
"""Fetch and log run details after a failure."""
171+
try:
172+
run = await self.client.agents.runs.get(thread=thread_id, run=run_id)
173+
self.logger.error(
174+
"Run failure details | status=%s | id=%s | last_error=%s | usage=%s",
175+
getattr(run, 'status', None),
176+
run_id,
177+
getattr(run, 'last_error', None),
178+
getattr(run, 'usage', None),
179+
)
180+
except Exception as ex:
181+
self.logger.error("Could not fetch run details: %s", ex)
148182

149183
async def create_foundry_agent(agent_name:str,
150184
agent_description:str,

src/backend/v3/orchestration/human_approval_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
orchestration_config)
2222
from v3.models.models import MPlan, MStep
2323

24-
# Create a progress ledger that indicates the request is satisfied (task complete)
24+
# Create a progress ledger that indicates the request is satisfied (task complete)
2525

2626

2727
class HumanApprovalMagenticManager(StandardMagenticManager):

0 commit comments

Comments
 (0)