Skip to content

Commit a433f76

Browse files
Merge pull request #648 from microsoft/psl-extralogs
fix: added extra logs for debugging
2 parents 6848e71 + a339555 commit a433f76

File tree

8 files changed

+60
-9
lines changed

8 files changed

+60
-9
lines changed

src/backend/v3/api/router.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,10 +749,12 @@ async def upload_team_config(
749749
)
750750

751751
# Validate search indexes
752+
logger.info(f"🔍 Validating search indexes for user: {user_id}")
752753
search_valid, search_errors = await team_service.validate_team_search_indexes(
753754
json_data
754755
)
755756
if not search_valid:
757+
logger.warning(f"❌ Search validation failed for user {user_id}: {search_errors}")
756758
error_message = (
757759
f"Search index validation failed:\n\n{chr(10).join([f'• {error}' for error in search_errors])}\n\n"
758760
f"Please ensure all referenced search indexes exist in your Azure AI Search service."
@@ -768,6 +770,7 @@ async def upload_team_config(
768770
)
769771
raise HTTPException(status_code=400, detail=error_message)
770772

773+
logger.info(f"✅ Search validation passed for user: {user_id}")
771774
track_event_if_configured(
772775
"Team configuration search validation passed",
773776
{"status": "passed", "user_id": user_id, "filename": file.filename},

src/backend/v3/callbacks/response_handlers.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
WebsocketMessageType,
1818
)
1919

20+
logger = logging.getLogger(__name__)
21+
2022

2123
def clean_citations(text: str) -> str:
2224
"""Remove citation markers from agent responses while preserving formatting."""
@@ -43,18 +45,26 @@ def agent_response_callback(message: ChatMessageContent, user_id: str = None) ->
4345
# Get agent name to determine handling
4446
agent_name = message.name or "Unknown Agent"
4547

48+
logger.info(f"🤖 Agent Response from '{agent_name}' for user: {user_id}")
49+
4650
role = getattr(message, "role", "unknown")
4751

4852
# Send to WebSocket
4953
if user_id:
5054
try:
5155
if message.items and message.items[0].content_type == "function_call":
56+
logger.info(f" Message content_type: {message.items[0].content_type}")
57+
logger.info(f"🔧 Tool calls detected from agent: {agent_name}")
5258
final_message = AgentToolMessage(agent_name=agent_name)
5359
for item in message.items:
5460
if item.content_type == "function_call":
61+
tool_name = item.name or "unknown_tool"
62+
tool_args = item.arguments or {}
63+
logger.info(f"🛠️ Tool call: {tool_name} with args: {str(tool_args)[:200]}...")
64+
5565
tool_call = AgentToolCall(
56-
tool_name=item.name or "unknown_tool",
57-
arguments=item.arguments or {},
66+
tool_name=tool_name,
67+
arguments=tool_args,
5868
)
5969
final_message.tool_calls.append(tool_call)
6070

@@ -67,9 +77,18 @@ def agent_response_callback(message: ChatMessageContent, user_id: str = None) ->
6777
)
6878
logging.info(f"Function call: {final_message}")
6979
elif message.items and message.items[0].content_type == "function_result":
80+
# Log function results for debugging
81+
logger.info(f" Message content_type: {message.items[0].content_type}")
82+
logger.info(f"📥 Function result received from agent: {agent_name}")
83+
for item in message.items:
84+
if item.content_type == "function_result":
85+
result_content = str(item.result)[:300] if hasattr(item, 'result') else "No result"
86+
logger.info(f"🔍 Function result: {result_content}...")
7087
# skip returning these results for now - agent will return in a later message
7188
pass
7289
else:
90+
logger.info(f" Message content_type: {message.items[0].content_type}")
91+
logger.info(f"💬 Text message from agent: {agent_name}")
7392
final_message = AgentMessage(
7493
agent_name=agent_name,
7594
timestamp=time.time() or "",

src/backend/v3/config/settings.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,17 @@ def __init__(self):
6161
self.url = config.MCP_SERVER_ENDPOINT
6262
self.name = config.MCP_SERVER_NAME
6363
self.description = config.MCP_SERVER_DESCRIPTION
64+
logger.info(f"🔧 MCP Config initialized - URL: {self.url}, Name: {self.name}")
6465

6566
def get_headers(self, token: str):
6667
"""Get MCP headers with authentication token."""
67-
return (
68+
headers = (
6869
{"Authorization": f"Bearer {token}", "Content-Type": "application/json"}
6970
if token
7071
else {}
7172
)
73+
logger.debug(f"📋 MCP Headers created: {headers}")
74+
return headers
7275

7376

7477
class OrchestrationConfig:
@@ -127,6 +130,7 @@ async def wait_for_approval(self, plan_id: str, timeout: Optional[float] = None)
127130
asyncio.TimeoutError: If timeout is exceeded
128131
KeyError: If plan_id is not found in approvals
129132
"""
133+
logger.info(f"Waiting for approval: {plan_id}")
130134
if timeout is None:
131135
timeout = self.default_timeout
132136

@@ -142,9 +146,11 @@ async def wait_for_approval(self, plan_id: str, timeout: Optional[float] = None)
142146

143147
try:
144148
await asyncio.wait_for(self._approval_events[plan_id].wait(), timeout=timeout)
149+
logger.info(f"Approval received: {plan_id}")
145150
return self.approvals[plan_id]
146151
except asyncio.TimeoutError:
147152
# Clean up on timeout
153+
logger.warning(f"Approval timeout: {plan_id}")
148154
self.cleanup_approval(plan_id)
149155
raise
150156
except asyncio.CancelledError:

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from contextlib import AsyncExitStack
22
from typing import Any
3+
import logging
34

45
from azure.ai.projects.aio import AIProjectClient
56
from azure.identity.aio import DefaultAzureCredential
@@ -8,6 +9,8 @@
89
from v3.magentic_agents.models.agent_models import MCPConfig
910
from v3.config.agent_registry import agent_registry
1011

12+
logger = logging.getLogger(__name__)
13+
1114

1215
class MCPEnabledBase:
1316
"""
@@ -74,6 +77,7 @@ async def _after_open(self) -> None:
7477

7578
async def _enter_mcp_if_configured(self) -> None:
7679
if not self.mcp_cfg:
80+
logger.error("No MCP configuration provided")
7781
return
7882
# headers = self._build_mcp_headers()
7983
plugin = MCPStreamableHttpPlugin(
@@ -85,7 +89,13 @@ async def _enter_mcp_if_configured(self) -> None:
8589
# Enter MCP async context via the stack to ensure correct LIFO cleanup
8690
if self._stack is None:
8791
self._stack = AsyncExitStack()
88-
self.mcp_plugin = await self._stack.enter_async_context(plugin)
92+
93+
try:
94+
self.mcp_plugin = await self._stack.enter_async_context(plugin)
95+
logger.info(f"✅ MCP plugin '{self.mcp_cfg.name}' successfully initialized")
96+
except Exception as e:
97+
logger.error(f"❌ Failed to initialize MCP plugin '{self.mcp_cfg.name}': {e}")
98+
raise
8999

90100

91101
class AzureAgentBase(MCPEnabledBase):

src/backend/v3/magentic_agents/foundry_agent.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,22 @@ async def _after_open(self) -> None:
172172
# Add MCP plugins if available
173173
plugins = [self.mcp_plugin] if self.mcp_plugin else []
174174

175+
if self.mcp_plugin:
176+
self.logger.info(f"🔧 Adding MCP plugin to agent: {self.agent_name}")
177+
self.logger.debug(f"MCP plugin name: {getattr(self.mcp_plugin, 'name', 'Unknown')}")
178+
else:
179+
self.logger.debug(f"No MCP plugin for agent: {self.agent_name}")
180+
175181
try:
182+
self.logger.info(f"🤖 Creating AzureAI agent: {self.agent_name}")
176183
self._agent = AzureAIAgent(
177184
client=self.client,
178185
definition=definition,
179186
plugins=plugins,
180187
)
188+
self.logger.info(f"✅ AzureAI agent created successfully: {self.agent_name}")
181189
except Exception as ex:
182-
self.logger.error("Failed to create AzureAIAgent: %s", ex)
190+
self.logger.error("Failed to create AzureAIAgent '%s': %s", self.agent_name, ex)
183191
raise
184192

185193
# Register agent with global registry for tracking and cleanup

src/backend/v3/magentic_agents/proxy_agent.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ async def _wait_for_user_clarification(
282282
Raises:
283283
asyncio.TimeoutError: If timeout is exceeded (300 seconds default)
284284
"""
285-
# logger.info(f"Waiting for user clarification for request: {request_id}")
285+
logger.info(f"Waiting for clarification: {request_id}")
286286

287287
# Initialize clarification as pending using the new event-driven method
288288
orchestration_config.set_clarification_pending(request_id)
@@ -291,14 +291,14 @@ async def _wait_for_user_clarification(
291291
# Wait for clarification with timeout using the new event-driven method
292292
answer = await orchestration_config.wait_for_clarification(request_id)
293293

294-
# logger.info(f"Clarification received for request {request_id}: {answer}")
294+
logger.info(f"Clarification received for {request_id} : {answer}")
295295
return UserClarificationResponse(
296296
request_id=request_id,
297297
answer=answer,
298298
)
299299
except asyncio.TimeoutError:
300300
# Enhanced timeout handling - notify user via WebSocket and cleanup
301-
logger.debug(f"Clarification timeout for request {request_id} - notifying user and terminating process")
301+
logger.warning(f"Clarification timeout for request: {request_id}")
302302

303303
# Create timeout notification message
304304
from v3.models.messages import TimeoutNotification, WebsocketMessageType

src/backend/v3/orchestration/human_approval_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def __init__(self, user_id: str, *args, **kwargs):
5353
# Remove any custom kwargs before passing to parent
5454

5555
plan_append = """
56+
5657
IMPORTANT: Never ask the user for information or clarification until all agents on the team have been asked first.
5758
5859
EXAMPLE: If the user request involves product information, first ask all agents on the team to provide the information.
@@ -69,7 +70,6 @@ def __init__(self, user_id: str, *args, **kwargs):
6970
- **DocumentCreationAgent** to draft a comprehensive onboarding plan that includes a checklist of resources and materials needed for effective onboarding.
7071
- **ProxyAgent** to review the drafted onboarding plan for clarity and completeness.
7172
- **MagenticManager** to finalize the onboarding plan and prepare it for presentation to stakeholders.
72-
7373
"""
7474

7575
final_append = """

src/backend/v3/orchestration/orchestration_manager.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ async def init_orchestration(
3939
cls, agents: List, user_id: str = None
4040
) -> MagenticOrchestration:
4141
"""Main function to run the agents."""
42+
cls.logger.info(f"Initializing orchestration for user: {user_id}")
4243

4344
# Custom execution settings that should work with Azure OpenAI
4445
execution_settings = OpenAIChatPromptExecutionSettings(
@@ -97,6 +98,7 @@ async def get_current_or_new_orchestration(
9798
cls, user_id: str, team_config: TeamConfiguration, team_switched: bool
9899
) -> MagenticOrchestration: # add team_switched: bool parameter
99100
"""get existing orchestration instance."""
101+
cls.logger.info(f"Getting orchestration for user: {user_id}, team_switched: {team_switched}")
100102
current_orchestration = orchestration_config.get_current_orchestration(user_id)
101103
if (
102104
current_orchestration is None or team_switched
@@ -117,6 +119,7 @@ async def get_current_or_new_orchestration(
117119

118120
async def run_orchestration(self, user_id, input_task) -> None:
119121
"""Run the orchestration with user input loop."""
122+
self.logger.info(f"Starting orchestration run for user: {user_id}")
120123

121124
job_id = str(uuid.uuid4())
122125

@@ -139,13 +142,15 @@ async def run_orchestration(self, user_id, input_task) -> None:
139142

140143
runtime = InProcessRuntime()
141144
runtime.start()
145+
self.logger.info(f"🎯 Starting task execution: {input_task.description[:100]}...")
142146

143147
try:
144148

145149
orchestration_result = await magentic_orchestration.invoke(
146150
task=input_task.description,
147151
runtime=runtime,
148152
)
153+
self.logger.info("📊 Task invocation completed, retrieving results")
149154

150155
try:
151156
self.logger.info("\nAgent responses:")

0 commit comments

Comments
 (0)