LeoYeAI/agent-master-skills / skills/agent-comm-hub
agent-comm-hub
Flagged多智能体协同通信基础设施——基于 MCP+SSE 的实时消息、任务调度、记忆共享与进化引擎。支持 WorkBuddy、Hermes、QClaw 及任意 MCP 兼容 Agent 接入。53 个 MCP 工具、4 级权限、零外部依赖 Python SDK。触发词:agent通信、智能体通信、hub通信、多智能体、跨agent通信、任务调度、assign_task、send_message、hermes通信、workbuddy通信、agent hub、通信hub、mcp通信、记忆共享、进化引擎、策略共享、经验分享、共享记忆,共同进化
src/sse.js
View on GitHubimport { logger } from "./logger.js";
// 在线 Agent 连接池
const clients = new Map();
// ─── 客户端去重:per-connection 递增 event_id ─────────────
const clientEventCounters = new Map();
function nextEventId(agentId) {
const current = clientEventCounters.get(agentId) ?? 0;
const next = current + 1;
clientEventCounters.set(agentId, next);
return next;
}
/**
* 获取下一个 event_id(不递增,预览用)
*/
export function peekNextEventId(agentId) {
return (clientEventCounters.get(agentId) ?? 0) + 1;
}
/**
* 注册 Agent 的 SSE 连接
*/
export function registerClient(agentId, res) {
// 如果已有旧连接,先关掉(Agent 重启场景)
const existing = clients.get(agentId);
if (existing) {
try {
existing.end();
}
catch (_) { }
}
clients.set(agentId, res);
// 重置 event counter
clientEventCounters.set(agentId, 0);
logger.info("sse_client_connected", { module: "sse", agent_id: agentId, total: clients.size });
}
/**
* 移除 Agent 连接(断线时调用)
*/
export function removeClient(agentId) {
clients.delete(agentId);
clientEventCounters.delete(agentId);
logger.info("sse_client_disconnected", { module: "sse", agent_id: agentId, total: clients.size });
}
/**
* 向指定 Agent 推送事件
*
* 每个推送附加递增的 event_id,客户端可据此实现去重:
* - event_id 是严格递增的
* - 客户端保存 last_seen_event_id,忽略 ≤ last_seen 的消息
*
* @param agentId 目标 Agent
* @param event 事件数据(会被序列化为 JSON)
* @param dedupId 可选的去重标识(如 msg_hash),附加到事件中供客户端验证
* @returns true = 在线已推送;false = 离线,消息已持久化等待补发
*/
export function pushToAgent(agentId, event, dedupId) {
const res = clients.get(agentId);
if (!res)
return false;
try {
const eventId = nextEventId(agentId);
const payload = {
...event,
_hub_event_id: eventId,
...(dedupId ? { _hub_dedup_id: dedupId } : {}),
};
// SSE 事件格式:id + event + data
res.write(`id: ${eventId}\n`);
res.write(`event: message\n`);
res.write(`data: ${JSON.stringify(payload)}\n\n`);
return true;
}
catch (err) {
// 连接异常,移除
removeClient(agentId);
return false;
}
}
/**
* 广播给多个 Agent
*/
export function broadcast(agentIds, event) {
const results = {};
for (const id of agentIds) {
results[id] = pushToAgent(id, event);
}
return results;
}
/**
* 查询哪些 Agent 在线
*/
export function onlineAgents() {
return [...clients.keys()];
}
/**
* Phase 5b: 优雅关闭时 drain 所有 SSE 连接
* 向每个客户端发送 close 事件后关闭连接
*/
export function drainAllClients() {
for (const [agentId, res] of clients.entries()) {
try {
const eventId = nextEventId(agentId);
res.write(`id: ${eventId}\n`);
res.write(`event: hub_shutdown\n`);
res.write(`data: {"message":"Server shutting down"}\n\n`);
res.end();
}
catch { }
}
clients.clear();
clientEventCounters.clear();
}
//# sourceMappingURL=sse.js.mapRelated skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |