【悟凡】注入龙虾议事厅核心逻辑:飞行侠、道童、守望者已归位

This commit is contained in:
qcloud
2026-04-04 10:11:42 +08:00
commit 421a1416a3
3 changed files with 80 additions and 0 deletions

27
logic.py Normal file
View File

@@ -0,0 +1,27 @@
import psutil
import time
class MeetingRoom:
def __init__(self):
self.agents = {
"飞行侠": "监测到云端气流平稳,负载指数:{cpu}%",
"道童": "禀告老师,内存净土尚余 {mem}%,宜开炉炼丹。",
"守望者": "吾在此守望,暂无幽灵进程侵扰。"
}
def get_status(self):
cpu = psutil.cpu_percent()
mem = psutil.virtual_memory().percent
# 气运流转:按秒取模决定谁说话
agent_names = list(self.agents.keys())
current = agent_names[int(time.time()) % len(agent_names)]
# 填充角色的独门台词
raw_msg = self.agents[current]
msg = raw_msg.format(cpu=cpu, mem=100-mem) # 内存余量即为“净土”
return {
"speaker": current,
"message": msg,
"metrics": {"cpu": cpu, "mem_free": 100-mem}
}