fix: Resolve real-time agent progress update issues
- Modify StreamHandler to send current agent statuses immediately upon WebSocket connection - Switch AnalysisService to use asynchronous graph streaming (astream) to prevent event loop blocking - Clean up debug logging in frontend and backend
This commit is contained in:
parent
b4c0d46681
commit
9fad42ad76
|
|
@ -143,7 +143,7 @@ class AnalysisService:
|
||||||
|
|
||||||
# Stream the analysis
|
# Stream the analysis
|
||||||
trace = []
|
trace = []
|
||||||
for chunk in graph.graph.stream(init_agent_state, **args):
|
async for chunk in graph.graph.astream(init_agent_state, **args):
|
||||||
if update_callback:
|
if update_callback:
|
||||||
await self._process_chunk(chunk, update_callback, analysis_id, request.analysts)
|
await self._process_chunk(chunk, update_callback, analysis_id, request.analysts)
|
||||||
trace.append(chunk)
|
trace.append(chunk)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import json
|
import json
|
||||||
|
from datetime import datetime
|
||||||
from typing import Dict, Set
|
from typing import Dict, Set
|
||||||
from fastapi import WebSocket, WebSocketDisconnect
|
from fastapi import WebSocket, WebSocketDisconnect
|
||||||
from ..models.schemas import StreamUpdate
|
from ..models.schemas import StreamUpdate
|
||||||
|
|
@ -64,6 +65,15 @@ class StreamHandler:
|
||||||
"timestamp": ""
|
"timestamp": ""
|
||||||
})
|
})
|
||||||
|
|
||||||
|
# Send current agent statuses
|
||||||
|
current_statuses = self.analysis_service.agent_statuses.get(analysis_id, {})
|
||||||
|
for agent, status in current_statuses.items():
|
||||||
|
await websocket.send_json({
|
||||||
|
"type": "agent_status",
|
||||||
|
"data": {"agent": agent, "status": status},
|
||||||
|
"timestamp": datetime.now().isoformat()
|
||||||
|
})
|
||||||
|
|
||||||
# Keep connection alive and forward updates
|
# Keep connection alive and forward updates
|
||||||
while True:
|
while True:
|
||||||
# Wait for any incoming messages (ping/pong or close)
|
# Wait for any incoming messages (ping/pong or close)
|
||||||
|
|
|
||||||
|
|
@ -94,16 +94,14 @@ export default function AnalysisPage() {
|
||||||
Analysis: {statusData?.ticker || "Loading..."} - {statusData?.analysis_date || ""}
|
Analysis: {statusData?.ticker || "Loading..."} - {statusData?.analysis_date || ""}
|
||||||
</h1>
|
</h1>
|
||||||
<div className="flex items-center space-x-4">
|
<div className="flex items-center space-x-4">
|
||||||
<span className={`px-3 py-1 rounded-full text-sm ${
|
<span className={`px-3 py-1 rounded-full text-sm ${status === "completed" ? "bg-green-100 text-green-800" :
|
||||||
status === "completed" ? "bg-green-100 text-green-800" :
|
|
||||||
status === "running" ? "bg-blue-100 text-blue-800" :
|
status === "running" ? "bg-blue-100 text-blue-800" :
|
||||||
"bg-gray-100 text-gray-800"
|
"bg-gray-100 text-gray-800"
|
||||||
}`}>
|
}`}>
|
||||||
{status}
|
{status}
|
||||||
</span>
|
</span>
|
||||||
<span className={`px-3 py-1 rounded-full text-sm ${
|
<span className={`px-3 py-1 rounded-full text-sm ${isConnected ? "bg-green-100 text-green-800" : "bg-red-100 text-red-800"
|
||||||
isConnected ? "bg-green-100 text-green-800" : "bg-red-100 text-red-800"
|
}`}>
|
||||||
}`}>
|
|
||||||
{isConnected ? "Connected" : "Disconnected"}
|
{isConnected ? "Connected" : "Disconnected"}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue