Skip to content

Commit 529040a

Browse files
added extra logs
1 parent da55973 commit 529040a

File tree

9 files changed

+76
-13
lines changed

9 files changed

+76
-13
lines changed

src/backend/common/database/database_base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ async def get_steps_for_plan(self, plan_id: str) -> List[Step]:
153153
@abstractmethod
154154
async def get_current_team(self, user_id: str) -> Optional[UserCurrentTeam]:
155155
"""Retrieve the current team for a user."""
156+
pass
156157

157158
@abstractmethod
158159
async def delete_current_team(self, user_id: str) -> Optional[UserCurrentTeam]:

src/backend/v3/api/router.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,9 @@ async def plan_approval(
396396
orchestration_config
397397
and human_feedback.m_plan_id in orchestration_config.approvals
398398
):
399+
# orchestration_config.approvals[human_feedback.m_plan_id] = (
400+
# human_feedback.approved
401+
# )
399402
orchestration_config.set_approval_result(
400403
human_feedback.m_plan_id, human_feedback.approved
401404
)
@@ -528,6 +531,9 @@ async def user_clarification(
528531
orchestration_config
529532
and human_feedback.request_id in orchestration_config.clarifications
530533
):
534+
# orchestration_config.clarifications[human_feedback.request_id] = (
535+
# human_feedback.answer
536+
# )
531537
# Use the new event-driven method to set clarification result
532538
orchestration_config.set_clarification_result(
533539
human_feedback.request_id, human_feedback.answer
@@ -749,10 +755,12 @@ async def upload_team_config(
749755
)
750756

751757
# Validate search indexes
758+
logger.info(f"🔍 Validating search indexes for user: {user_id}")
752759
search_valid, search_errors = await team_service.validate_team_search_indexes(
753760
json_data
754761
)
755762
if not search_valid:
763+
logger.warning(f"❌ Search validation failed for user {user_id}: {search_errors}")
756764
error_message = (
757765
f"Search index validation failed:\n\n{chr(10).join([f'• {error}' for error in search_errors])}\n\n"
758766
f"Please ensure all referenced search indexes exist in your Azure AI Search service."
@@ -768,6 +776,7 @@ async def upload_team_config(
768776
)
769777
raise HTTPException(status_code=400, detail=error_message)
770778

779+
logger.info(f"✅ Search validation passed for user: {user_id}")
771780
track_event_if_configured(
772781
"Team configuration search validation passed",
773782
{"status": "passed", "user_id": user_id, "filename": file.filename},

src/backend/v3/callbacks/response_handlers.py

Lines changed: 19 additions & 3 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."""
@@ -42,19 +44,26 @@ def agent_response_callback(message: ChatMessageContent, user_id: str = None) ->
4244

4345
# Get agent name to determine handling
4446
agent_name = message.name or "Unknown Agent"
47+
48+
logger.info(f"🤖 Agent Response from '{agent_name}' for user: {user_id}")
4549

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"🔧 Tool calls detected from agent: {agent_name}")
5257
final_message = AgentToolMessage(agent_name=agent_name)
5358
for item in message.items:
5459
if item.content_type == "function_call":
60+
tool_name = item.name or "unknown_tool"
61+
tool_args = item.arguments or {}
62+
logger.info(f"🛠️ Tool call: {tool_name} with args: {str(tool_args)[:200]}...")
63+
5564
tool_call = AgentToolCall(
56-
tool_name=item.name or "unknown_tool",
57-
arguments=item.arguments or {},
65+
tool_name=tool_name,
66+
arguments=tool_args,
5867
)
5968
final_message.tool_calls.append(tool_call)
6069

@@ -65,11 +74,18 @@ def agent_response_callback(message: ChatMessageContent, user_id: str = None) ->
6574
message_type=WebsocketMessageType.AGENT_TOOL_MESSAGE,
6675
)
6776
)
68-
logging.info(f"Function call: {final_message}")
77+
logging.info(f"📤 Tool message sent via WebSocket for user: {user_id}")
6978
elif message.items and message.items[0].content_type == "function_result":
79+
# Log function results for debugging
80+
logger.info(f"📥 Function result received from agent: {agent_name}")
81+
for item in message.items:
82+
if item.content_type == "function_result":
83+
result_content = str(item.result)[:300] if hasattr(item, 'result') else "No result"
84+
logger.info(f"🔍 Function result: {result_content}...")
7085
# skip returning these results for now - agent will return in a later message
7186
pass
7287
else:
88+
logger.info(f"💬 Text message from agent: {agent_name}")
7389
final_message = AgentMessage(
7490
agent_name=agent_name,
7591
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.debug("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
@@ -171,15 +171,23 @@ async def _after_open(self) -> None:
171171

172172
# Add MCP plugins if available
173173
plugins = [self.mcp_plugin] if self.mcp_plugin else []
174+
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}")
174180

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}")
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: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,31 @@ def __init__(self, user_id: str, *args, **kwargs):
5353
# Remove any custom kwargs before passing to parent
5454

5555
plan_append = """
56-
IMPORTANT: Never ask the user for information or clarification until all agents on the team have been asked first.
56+
57+
CRITICAL DOMAIN CHECK: Examine team agents first - if request doesn't match team domain, reject immediately:
58+
- CustomerDataAgent/OrderDataAgent = RETAIL team (reject HR/employee requests)
59+
- HRHelperAgent = HR team (reject non-HR requests)
60+
- ProductAgent/MarketingAgent = MARKETING team (reject non-marketing requests)
61+
62+
- **ProxyAgent** to politely inform the user that this request does not match this team’s domain and should be redirected to the appropriate team. No clarifications or follow-up questions should be asked.
5763
64+
65+
IMPORTANT: Never ask the user for information or clarification until all agents on the team have been asked first.
66+
5867
EXAMPLE: If the user request involves product information, first ask all agents on the team to provide the information.
5968
Do not ask the user unless all agents have been consulted and the information is still missing.
60-
69+
6170
Plan steps should always include a bullet point, followed by an agent name, followed by a description of the action
6271
to be taken. If a step involves multiple actions, separate them into distinct steps with an agent included in each step.
6372
If the step is taken by an agent that is not part of the team, such as the MagenticManager, please always list the MagenticManager as the agent for that step. At any time, if more information is needed from the user, use the ProxyAgent to request this information.
64-
73+
6574
Here is an example of a well-structured plan:
6675
- **EnhancedResearchAgent** to gather authoritative data on the latest industry trends and best practices in employee onboarding
6776
- **EnhancedResearchAgent** to gather authoritative data on Innovative onboarding techniques that enhance new hire engagement and retention.
6877
- **DocumentCreationAgent** to draft a comprehensive onboarding plan that includes a detailed schedule of onboarding activities and milestones.
6978
- **DocumentCreationAgent** to draft a comprehensive onboarding plan that includes a checklist of resources and materials needed for effective onboarding.
7079
- **ProxyAgent** to review the drafted onboarding plan for clarity and completeness.
7180
- **MagenticManager** to finalize the onboarding plan and prepare it for presentation to stakeholders.
72-
7381
"""
7482

7583
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)