|
1 | 1 | import asyncio |
| 2 | +from datetime import UTC, datetime |
2 | 3 | from typing import Any |
3 | 4 |
|
4 | | -from sas.cosmosdb.sql.repository import RepositoryBase |
5 | | - |
6 | 5 | from routers.models.process_agent_activities import ( |
7 | 6 | AgentStatus, |
8 | 7 | ProcessStatus, |
9 | 8 | ProcessStatusSnapshot, |
10 | 9 | ) |
11 | | - |
12 | | -from datetime import datetime, UTC |
| 10 | +from sas.cosmosdb.sql.repository import RepositoryBase |
13 | 11 |
|
14 | 12 |
|
15 | 13 | def calculate_activity_duration(activity_start: str) -> tuple[int, str]: |
@@ -142,7 +140,7 @@ async def get_process_status_by_process_id( |
142 | 140 | ) |
143 | 141 |
|
144 | 142 | status = await self.get_async(process_id) |
145 | | - if status != None: |
| 143 | + if status is not None: |
146 | 144 | return ProcessStatusSnapshot( |
147 | 145 | process_id=status.id, # Fix: use process_id instead of id |
148 | 146 | step=status.step, |
@@ -305,26 +303,7 @@ async def render_agent_status(self, process_id: str) -> dict: |
305 | 303 | formatted_lines = [] |
306 | 304 | agent_metrics = {} |
307 | 305 |
|
308 | | - # Check if process failed early (before agents really started working) |
309 | 306 | process_failed = getattr(process_data, "status", "") == "failed" |
310 | | - process_duration_seconds = 0 |
311 | | - if hasattr(process_data, "started_at_time") and hasattr( |
312 | | - process_data, "last_update_time" |
313 | | - ): |
314 | | - try: |
315 | | - start = datetime.fromisoformat( |
316 | | - process_data.started_at_time.replace(" UTC", "+00:00") |
317 | | - ) |
318 | | - end = datetime.fromisoformat( |
319 | | - process_data.last_update_time.replace(" UTC", "+00:00") |
320 | | - ) |
321 | | - process_duration_seconds = int((end - start).total_seconds()) |
322 | | - except Exception: |
323 | | - pass |
324 | | - |
325 | | - early_failure = ( |
326 | | - process_failed and process_duration_seconds < 30 |
327 | | - ) # Failed in less than 30 seconds |
328 | 307 |
|
329 | 308 | # Analyze each agent with enhanced insights |
330 | 309 | for agent_name, agent_data in agents_data.items(): |
@@ -413,6 +392,23 @@ async def render_agent_status(self, process_id: str) -> dict: |
413 | 392 | if is_active and duration_seconds > 30: |
414 | 393 | message_parts.append(f"({duration_str})") |
415 | 394 |
|
| 395 | + # Add tool usage from recent activity history |
| 396 | + recent_tools = [] |
| 397 | + for h in activity_history[-5:]: |
| 398 | + tool = h.get("tool_used", "") |
| 399 | + if tool and tool not in recent_tools: |
| 400 | + recent_tools.append(tool) |
| 401 | + if recent_tools: |
| 402 | + tool_names = ", ".join( |
| 403 | + recent_tools[-3:] |
| 404 | + ) # Show last 3 unique tools |
| 405 | + message_parts.append(f"🔧 {tool_names}") |
| 406 | + |
| 407 | + # Add activity count |
| 408 | + total_activities = len(activity_history) |
| 409 | + if total_activities > 0: |
| 410 | + message_parts.append(f"📊 {total_activities} actions") |
| 411 | + |
416 | 412 | # Add relationship indicators |
417 | 413 | if relationships["waiting_for"]: |
418 | 414 | waiting_names = [ |
@@ -496,6 +492,25 @@ async def render_agent_status(self, process_id: str) -> dict: |
496 | 492 | "bottleneck_score": total_blocking, |
497 | 493 | "fast_agents": fast_agents, |
498 | 494 | "failed_agents": failed_agents, |
| 495 | + # NEW: Structured agent activities for rich frontend display |
| 496 | + "agent_activities": agents_data, |
| 497 | + # NEW: Step timing data |
| 498 | + "step_timings": { |
| 499 | + k: v |
| 500 | + for k, v in ( |
| 501 | + getattr(process_data, "step_timings", {}) or {} |
| 502 | + ).items() |
| 503 | + }, |
| 504 | + # NEW: Step results and metrics |
| 505 | + "step_results": { |
| 506 | + k: v |
| 507 | + for k, v in ( |
| 508 | + getattr(process_data, "step_results", {}) or {} |
| 509 | + ).items() |
| 510 | + }, |
| 511 | + "generated_files": getattr(process_data, "generated_files", []) or [], |
| 512 | + "conversion_metrics": getattr(process_data, "conversion_metrics", {}) |
| 513 | + or {}, |
499 | 514 | } |
500 | 515 |
|
501 | 516 | async def render_agent_status_old(self, process_id: str) -> dict: |
|
0 commit comments