21b-a/arch-optimization/SKILL.md
OpenClaw通信协议架构优化技能包 - 提供高性能、可靠的agent间通信框架。实现大消息59%性能提升,MessagePack 35%体积减少,统一传输层架构,智能路由算法,完整错误恢复和监控体系。
npx skillsauth add openclaw/skills arch-optimizationInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
高性能、生产就绪的agent间通信框架 - 大消息59%性能提升,MessagePack 35%体积减少
| 优化领域 | 改进指标 | 详细数据 | |----------|----------|----------| | 大消息传输 | +59%性能提升 | 10KB消息: 5.40ms → 2.20ms | | 协议层压缩 | -35%体积减少 | MessagePack平均压缩率0.65 | | 架构统一 | 单一API接口 | 取代多个分散的通信API | | 错误恢复 | 自动降级重试 | 3次重试 + 传输方式降级 |
# 方法1: 使用clawhub CLI安装
clawhub install communication-protocol-optimization
# 方法2: 手动安装
# 1. 将本目录复制到 ~/.openclaw/skills/
# 2. 运行集成测试验证功能
// 在您的agent代码中使用统一通信API
const { UnifiedAgentComm } = require('./core/unified-api.js');
// 创建通信实例
const comm = new UnifiedAgentComm({
transport: {
filesystem: { enabled: true },
websocket: { enabled: false },
http: { enabled: false }
},
protocol: {
enableMessagePack: true,
defaultProtocol: 'auto'
}
});
// 发送消息
async function sendMessageExample() {
const result = await comm.send({
to: 'target-agent',
message: {
id: 'msg-' + Date.now(),
type: 'greeting',
content: 'Hello from optimized protocol!',
timestamp: new Date().toISOString()
},
options: {
priority: 'high',
timeout: 5000
}
});
console.log('✅ 消息发送成功:', result);
}
// 请求-响应模式
async function requestResponseExample() {
const response = await comm.request({
to: 'backend-agent',
message: {
action: 'process-data',
data: { /* 您的数据 */ }
},
options: {
timeout: 10000,
retryAttempts: 3
}
});
console.log('📨 收到响应:', response);
}
communication-protocol-optimization-v1.0.0/
├── SKILL.md # 本技能文档
├── README.md # 详细使用指南
├── FINAL_REPORT.md # 项目最终报告
├── core/ # ✅ 核心实现文件
│ ├── transport-layer.js # 统一传输层 (32KB)
│ ├── protocol-layer.js # 多协议支持层 (25KB)
│ ├── unified-api.js # 统一通信API (17KB)
│ ├── smart-transport.js # 智能传输层 (15KB)
│ └── minimal-fast-path.js # 简化快速路径 (11KB)
├── docs/ # 📚 设计文档
│ ├── transport-layer-design.md
│ └── protocol-layer-design.md
├── tests/ # 🧪 测试套件
│ ├── performance-comparison.js
│ ├── quick-minimal-test.js
│ └── test-transport-layer.js
├── examples/ # 💡 使用示例
│ ├── basic-usage.js
│ ├── request-response.js
│ └── broadcast-example.js
└── reports/ # 📊 性能报告
├── performance-comparison-results.json
├── quick-test-results.json
└── minimal-optimization-results.json
┌─────────────────┐
│ 应用层 │ ← UnifiedAgentComm API
├─────────────────┤
│ 协议层 │ ← JSON / MessagePack / Protocol Buffers
├─────────────────┤
│ 传输层 │ ← WebSocket / HTTP / 文件系统
└─────────────────┘
transport-layer.js)protocol-layer.js)unified-api.js)# 进入技能目录
cd ~/.openclaw/skills/communication-protocol-optimization
# 运行完整性能测试
node tests/performance-comparison.js
# 运行快速功能测试
node tests/quick-minimal-test.js
# 运行传输层测试
node tests/test-transport-layer.js
// 1. 引入统一API
const { UnifiedAgentComm } = require('communication-protocol-optimization/core/unified-api.js');
// 2. 创建通信实例
const agentComm = new UnifiedAgentComm({
// 传输配置
transport: {
filesystem: { enabled: true },
websocket: { enabled: false },
http: { enabled: false }
},
// 协议配置
protocol: {
defaultProtocol: 'auto', // 自动选择最佳协议
enableMessagePack: true, // 启用MessagePack压缩
json: { /* JSON协议配置 */ },
msgpack: { /* MessagePack协议配置 */ }
},
// 行为配置
behavior: {
defaultTimeout: 5000,
retryAttempts: 3,
enableBroadcast: true
}
});
// 3. 开始使用
async function communicate() {
// 发送消息
const result = await agentComm.send({
to: 'target-agent',
message: { /* 消息内容 */ },
options: { priority: 'high' }
});
}
transport: {
// 文件系统传输 (默认启用)
filesystem: {
enabled: true,
inboxDir: '~/workspace/agent_comm/inbox',
outboxDir: '~/workspace/agent_comm/outbox',
processedDir: '~/workspace/agent_comm/processed'
},
// WebSocket传输 (可选)
websocket: {
enabled: false,
url: 'ws://localhost:8080',
reconnectInterval: 5000
},
// HTTP传输 (可选)
http: {
enabled: false,
baseUrl: 'http://localhost:3000',
timeout: 10000
}
}
protocol: {
// 默认协议选择策略
defaultProtocol: 'auto', // 'json', 'msgpack', 'auto'
// 启用MessagePack支持
enableMessagePack: true,
// JSON协议配置
json: {
prettyPrint: false,
maxDepth: 50
},
// MessagePack协议配置
msgpack: {
compressionLevel: 1,
useRealMessagePack: true
}
}
behavior: {
// 默认超时时间 (毫秒)
defaultTimeout: 5000,
// 重试次数
retryAttempts: 3,
// 重试延迟 (毫秒)
retryDelay: 1000,
// 启用广播功能
enableBroadcast: true,
// 性能监控
enableMetrics: true,
metricsUpdateInterval: 60000 // 1分钟
}
// 获取性能统计
const metrics = agentComm.getMetrics();
console.log('📊 通信性能统计:');
console.log(' 发送总数:', metrics.sent.total);
console.log(' 成功发送:', metrics.sent.successful);
console.log(' 失败发送:', metrics.sent.failed);
console.log(' 平均延迟:', metrics.latency.average + 'ms');
console.log(' 协议使用:', metrics.protocolUsage);
console.log(' 传输方式:', metrics.transportUsage);
// 实时性能事件监听
agentComm.on('metrics-update', (metrics) => {
console.log('📈 性能指标更新:', {
timestamp: metrics.timestamp,
sentLastMinute: metrics.sentLastMinute,
successRate: metrics.successRate + '%',
avgLatency: metrics.avgLatency + 'ms'
});
});
// 错误事件监听
agentComm.on('error', (error, context) => {
console.error('❌ 通信错误:', {
message: error.message,
context: context,
timestamp: new Date().toISOString()
});
});
// 检查传输层配置
console.log('传输层状态:', agentComm.getTransportStatus());
// 检查文件系统权限
// 确保 ~/workspace/agent_comm/inbox 目录存在且有写入权限
// 启用详细日志
agentComm.setLogLevel('debug');
// 运行性能测试验证
node tests/performance-comparison.js
// 检查消息大小
// 大消息(>1KB)才能看到显著优化效果
// 验证协议选择
console.log('当前协议选择:', agentComm.getProtocolStats());
// 检查依赖
const msgpack = require('@msgpack/msgpack');
console.log('MessagePack版本:', msgpack.version);
// 回退到JSON
const comm = new UnifiedAgentComm({
protocol: {
enableMessagePack: false,
defaultProtocol: 'json'
}
});
# 运行诊断脚本
cd ~/.openclaw/skills/communication-protocol-optimization
node examples/debug-tools.js
# 查看性能报告
cat reports/performance-comparison-results.json | jq '.summary'
docs/ 目录中的设计文档examples/ 目录中的代码示例reports/ 目录中的测试结果// 技能使用问题反馈模板
const feedback = {
skill: 'communication-protocol-optimization',
version: '1.0.0',
issue: '描述您的问题...',
environment: 'OpenClaw版本、Node.js版本等',
reproduction: '重现步骤...'
};
技能状态: ✅ 生产就绪
最后更新: 2026-03-22
兼容性: OpenClaw 1.0+, Node.js 16+
推荐指数: ⭐⭐⭐⭐⭐ (核心通信基础设施)
tools
Use when the user wants to connect to, test, or use the McDonalds service at mcp.mcd.cn, including checking authentication, probing MCP endpoints, listing tools, or calling McDonalds MCP tools through a reusable local CLI.
development
Web scraping platform — Twitter/X data, Vinted marketplace, and general web scraping API
development
SlowMist AI Agent Security Review — comprehensive security framework for skills, repositories, URLs, on-chain addresses, and products (Claude Code version)
data-ai
去除中文文本中的 AI 写作痕迹,使其读起来自然。基于维基百科 AI 写作特征指南,检测 24 种 AI 模式。触发词:humanizer-cn、去除 AI 痕迹、去除 AI 写作痕迹、中文文本人性化。