Skip to content

Commit 303c866

Browse files
Refactor FoundryAgentTemplate and MagenticAgentFactory to remove debug print statements and streamline logging
1 parent 643306f commit 303c866

4 files changed

Lines changed: 4 additions & 40 deletions

File tree

src/backend/v4/magentic_agents/foundry_agent.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,18 @@ def __init__(
7070
self._use_azure_search = self._is_azure_search_requested()
7171
self.use_reasoning = use_reasoning
7272

73-
# Placeholder for server-created Azure AI agent id/version (if Azure Search path)
73+
# Placeholder for server-created Azure AI agent id (if Azure Search path)
7474
self._azure_server_agent_id: Optional[str] = None
75-
self._azure_server_agent_version: Optional[str] = None
7675

7776
# -------------------------
7877
# Mode detection
7978
# -------------------------
8079
def _is_azure_search_requested(self) -> bool:
8180
"""Determine if Azure AI Search raw tool path should be used."""
82-
print(f"[DEBUG _is_azure_search_requested] Agent={self.agent_name}, search={self.search}")
8381
if not self.search:
84-
print(f"[DEBUG _is_azure_search_requested] Agent={self.agent_name}: No search config, returning False")
8582
return False
8683
# Minimal heuristic: presence of required attributes
87-
8884
has_index = hasattr(self.search, "index_name") and bool(self.search.index_name)
89-
print(f"[DEBUG _is_azure_search_requested] Agent={self.agent_name}: has_index={has_index}, index_name={getattr(self.search, 'index_name', None)}")
9085
if has_index:
9186
self.logger.info(
9287
"Azure AI Search requested (connection_id=%s, index=%s).",
@@ -137,7 +132,6 @@ async def _create_azure_search_enabled_client(self, chatClient=None) -> Optional
137132
Returns:
138133
AzureAIClient | None
139134
"""
140-
print(f"[DEBUG _create_azure_search_enabled_client] Agent={self.agent_name}, chatClient={chatClient}, search_config={self.search}")
141135
if chatClient:
142136
self.logger.info("Reusing existing chatClient for agent '%s' (already has Azure Search configured)", self.agent_name)
143137
return chatClient
@@ -185,9 +179,6 @@ async def _create_azure_search_enabled_client(self, chatClient=None) -> Optional
185179
"Always use the Azure AI Search tool and configured index for knowledge retrieval."
186180
)
187181

188-
print(f"[AGENT CREATE] 🆕 Creating agent in Foundry: '{self.agent_name}'", flush=True)
189-
print(f"[AGENT CREATE] Model: {self.model_deployment_name}", flush=True)
190-
print(f"[AGENT CREATE] Search: connection={connection_name}, index={index_name}", flush=True)
191182

192183
azure_agent = await self.project_client.agents.create_version(
193184
agent_name=self.agent_name, # Use original name
@@ -212,8 +203,7 @@ async def _create_azure_search_enabled_client(self, chatClient=None) -> Optional
212203
)
213204

214205
self._azure_server_agent_id = azure_agent.id
215-
self._azure_server_agent_version = azure_agent.version
216-
print(f"[AGENT CREATE] ✅ Created agent: name={azure_agent.name}, id={azure_agent.id}, version={azure_agent.version}", flush=True)
206+
217207
self.logger.info(
218208
"Created Azure AI Search agent via create_version (name=%s, id=%s, version=%s).",
219209
azure_agent.name,
@@ -239,8 +229,6 @@ async def _create_azure_search_enabled_client(self, chatClient=None) -> Optional
239229
index_name,
240230
ex,
241231
)
242-
import traceback
243-
traceback.print_exc()
244232
return None
245233

246234
# -------------------------
@@ -257,7 +245,6 @@ async def _after_open(self) -> None:
257245

258246
try:
259247
chatClient = await self.get_database_team_agent()
260-
print(f"[DEBUG _after_open] Agent={self.agent_name}, _use_azure_search={self._use_azure_search}, search_config={self.search}, chatClient={chatClient}")
261248

262249
if self._use_azure_search:
263250
# Azure Search mode (skip MCP + Code Interpreter due to incompatibility)
@@ -266,7 +253,6 @@ async def _after_open(self) -> None:
266253
self.agent_name,
267254
getattr(self.search, "index_name", "N/A") if self.search else "N/A"
268255
)
269-
print(f"[DEBUG _after_open] Creating Azure Search client for {self.agent_name}")
270256
chat_client = await self._create_azure_search_enabled_client(chatClient)
271257
if not chat_client:
272258
raise RuntimeError(

src/backend/v4/magentic_agents/magentic_agent_factory.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ async def create_agent_from_config(
115115
index_name,
116116
"Reasoning" if use_reasoning else "Foundry",
117117
)
118-
print(f"[FACTORY] 🆕 Creating NEW agent: {agent_obj.name} (id={id(agent_obj)})", flush=True)
119118

120119
agent = FoundryAgentTemplate(
121120
agent_name=agent_obj.name,

src/backend/v4/orchestration/human_approval_manager.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class HumanApprovalMagenticManager(StandardMagenticManager):
3333
approval_enabled: bool = True
3434
magentic_plan: Optional[MPlan] = None
3535
current_user_id: str # populated in __init__
36-
_called_agents: set # Track which agents have been called
3736

3837
def __init__(self, user_id: str, agent, *args, **kwargs):
3938
"""
@@ -44,9 +43,6 @@ def __init__(self, user_id: str, agent, *args, **kwargs):
4443
*args: Additional positional arguments for the parent StandardMagenticManager.
4544
**kwargs: Additional keyword arguments for the parent StandardMagenticManager.
4645
"""
47-
48-
# Initialize called agents tracker
49-
self._called_agents = set()
5046

5147
plan_append = """
5248

src/backend/v4/orchestration/orchestration_manager.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ async def init_orchestration(
202202
# The orchestrator uses agent.name to identify them
203203
participant_list = list(participants.values())
204204
cls.logger.info("Participants for workflow: %s", list(participants.keys()))
205-
print(f"[DEBUG] Participants for workflow: {list(participants.keys())}", flush=True)
206205

207206
builder = (
208207
MagenticBuilder()
@@ -277,24 +276,17 @@ async def get_current_or_new_orchestration(
277276
cls.logger.error(
278277
"Failed to create agents for user '%s': %s", user_id, e
279278
)
280-
print(f"Failed to create agents for user '{user_id}': {e}")
281279
raise
282280
try:
283281
cls.logger.info("Initializing new orchestration for user '%s'", user_id)
284-
print(f"[DEBUG] Initializing new orchestration for user '{user_id}'")
285282
workflow = await cls.init_orchestration(
286283
agents, team_config, team_service.memory_context, user_id
287284
)
288285
orchestration_config.orchestrations[user_id] = workflow
289-
print(f"[DEBUG] Stored workflow for user '{user_id}': {workflow is not None}")
290-
print(f"[DEBUG] orchestrations keys: {list(orchestration_config.orchestrations.keys())}")
291286
except Exception as e:
292287
cls.logger.error(
293288
"Failed to initialize orchestration for user '%s': %s", user_id, e
294289
)
295-
print(f"Failed to initialize orchestration for user '{user_id}': {e}")
296-
import traceback
297-
traceback.print_exc()
298290
raise
299291
return orchestration_config.get_current_orchestration(user_id)
300292

@@ -310,13 +302,9 @@ async def run_orchestration(self, user_id: str, input_task) -> None:
310302
self.logger.info(
311303
"Starting orchestration job '%s' for user '%s'", job_id, user_id
312304
)
313-
print(f"[DEBUG] run_orchestration called for user '{user_id}'")
314-
print(f"[DEBUG] orchestrations keys before get: {list(orchestration_config.orchestrations.keys())}")
315305

316306
workflow = orchestration_config.get_current_orchestration(user_id)
317-
print(f"[DEBUG] workflow is None: {workflow is None}")
318307
if workflow is None:
319-
print(f"[ERROR] Orchestration not initialized for user '{user_id}'")
320308
raise ValueError("Orchestration not initialized for user.")
321309
# Fresh thread per participant to avoid cross-run state bleed
322310
executors = getattr(workflow, "executors", {})
@@ -393,7 +381,7 @@ async def run_orchestration(self, user_id: str, input_task) -> None:
393381
final_output: str | None = None
394382

395383
self.logger.info("Starting workflow execution...")
396-
print(f"[ORCHESTRATOR] 🚀 Starting workflow with max_rounds={orchestration_config.max_rounds}", flush=True)
384+
397385
last_message_id: str | None = None
398386
async for event in workflow.run_stream(task_text):
399387
try:
@@ -448,10 +436,9 @@ async def run_orchestration(self, user_id: str, input_task) -> None:
448436
agent_name,
449437
call_num
450438
)
451-
print(f"[ORCHESTRATOR] 📤 REQUEST SENT round={event.round_index} to agent={agent_name} (call #{call_num})", flush=True)
452439

453440
if call_num > 1:
454-
print(f"[ORCHESTRATOR] ⚠️ WARNING: Agent '{agent_name}' called {call_num} times!", flush=True)
441+
self.logger.warning("Agent '%s' called %d times", agent_name, call_num)
455442

456443
# Handle group chat response received - THIS IS WHERE AGENT RESPONSES COME
457444
elif isinstance(event, GroupChatResponseReceivedEvent):
@@ -513,10 +500,6 @@ async def run_orchestration(self, user_id: str, input_task) -> None:
513500
final_text = final_output if final_output else ""
514501

515502
# Log agent call summary
516-
print(f"\n[ORCHESTRATOR] 📊 AGENT CALL SUMMARY:", flush=True)
517-
for agent_name, count in agent_call_counts.items():
518-
status = "✅" if count == 1 else "⚠️ DUPLICATE"
519-
print(f" {status} {agent_name}: called {count} time(s)", flush=True)
520503
self.logger.info("Agent call counts: %s", agent_call_counts)
521504

522505
# Log results

0 commit comments

Comments
 (0)