Skip to content

Commit 4bb825b

Browse files
committed
Refactor agent display logic to show all agents regardless of online status
1 parent 89cf6c4 commit 4bb825b

3 files changed

Lines changed: 83 additions & 6 deletions

File tree

debug_agent_status.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
"""
2+
调试 agent 在线状态问题
3+
"""
4+
import asyncio
5+
import aiohttp
6+
import json
7+
8+
SERVER_URL = "http://127.0.0.1:8000"
9+
10+
async def debug_agent_status():
11+
"""检查 agent API 返回的数据"""
12+
print("=== 调试 Agent 在线状态 ===\n")
13+
14+
async with aiohttp.ClientSession() as session:
15+
# 获取所有 agent
16+
async with session.get(f"{SERVER_URL}/api/agents") as resp:
17+
if resp.status != 200:
18+
print(f"❌ 获取 agent 列表失败: {resp.status}")
19+
return
20+
21+
agents = await resp.json()
22+
print(f"找到 {len(agents)} 个 agent:\n")
23+
24+
for i, agent in enumerate(agents, 1):
25+
print(f"Agent {i}:")
26+
print(f" ID: {agent.get('id')}")
27+
print(f" Name: {agent.get('name')}")
28+
print(f" Display Name: {agent.get('display_name')}")
29+
print(f" is_online: {agent.get('is_online')}")
30+
print(f" last_heartbeat: {agent.get('last_heartbeat')}")
31+
print(f" last_activity: {agent.get('last_activity')}")
32+
print(f" last_activity_time: {agent.get('last_activity_time')}")
33+
34+
# 计算状态
35+
activity_time = agent.get('last_activity_time')
36+
if activity_time:
37+
from datetime import datetime
38+
activity_dt = datetime.fromisoformat(activity_time.replace('Z', '+00:00'))
39+
now = datetime.now()
40+
seconds_ago = (now - activity_dt).total_seconds()
41+
print(f" 距离上次活动: {seconds_ago:.0f} 秒")
42+
43+
# 模拟 getAgentState 逻辑
44+
if agent.get('last_activity') == 'msg_wait' and seconds_ago < 60:
45+
state = 'Waiting'
46+
elif seconds_ago < 30:
47+
state = 'Active'
48+
elif seconds_ago < 300:
49+
state = 'Idle'
50+
else:
51+
state = 'Offline' if not agent.get('is_online') else 'Idle'
52+
else:
53+
state = 'Waiting' if agent.get('is_online') else 'Offline'
54+
55+
print(f" 计算状态: {state}")
56+
print()
57+
58+
# 检查过滤逻辑
59+
print("=== 过滤逻辑测试 ===\n")
60+
offline_agents = [a for a in agents if agent.get('last_activity_time') is None or not agent.get('is_online')]
61+
print(f"可能被过滤为 Offline 的 agent 数量: {len(offline_agents)}")
62+
63+
if offline_agents:
64+
print("\n这些 agent 可能被过滤:")
65+
for agent in offline_agents:
66+
print(f" - {agent.get('display_name') or agent.get('name')} (is_online={agent.get('is_online')}, last_activity_time={agent.get('last_activity_time')})")
67+
68+
async def main():
69+
try:
70+
await debug_agent_status()
71+
except aiohttp.ClientConnectorError:
72+
print("❌ 错误: 无法连接到服务器。请确保服务器正在运行 http://127.0.0.1:8000")
73+
except Exception as e:
74+
print(f"❌ 错误: {e}")
75+
import traceback
76+
traceback.print_exc()
77+
78+
if __name__ == "__main__":
79+
asyncio.run(main())

src/static/index.html

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2509,12 +2509,9 @@
25092509
isThreadMode = participants.length > 0; // Only thread mode if we have participants
25102510
}
25112511

2512-
// If no thread selected or no participants in thread, fall back to showing all non-offline agents
2512+
// If no thread selected or no participants in thread, show all agents
25132513
if (!isThreadMode) {
2514-
participants = allAgents.filter(a => {
2515-
const state = getAgentState(a);
2516-
return state !== 'Offline';
2517-
});
2514+
participants = allAgents;
25182515
isThreadMode = false; // Global mode - no thread context
25192516
}
25202517

src/static/js/shared-agents.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@
170170
}
171171

172172
if (!isThreadMode) {
173-
participants = allAgents.filter((a) => getAgentState(a) !== "Offline");
173+
// Show all agents (both online and offline)
174+
participants = allAgents;
174175
isThreadMode = false;
175176
}
176177

0 commit comments

Comments
 (0)