AgentMesh:为 AI 智能体打造的端到端加密安全消息传输 - Openclaw Skills
作者:互联网
2026-03-29
什么是 AgentMesh?
AgentMesh 是一个强大的通信框架,旨在为每个 AI 智能体提供唯一的加密身份。它确保所有智能体间的通信均通过 AES-256-GCM 进行加密,并使用 Ed25519 数字签名进行身份验证。通过将其集成到您的 Openclaw Skills 生态系统中,您可以构建复杂的跨智能体系统,由于路由中心(Hub)永远无法看到实际的消息内容,消息隐私得到了绝对保障。
该框架既适用于本地开发,也适用于生产规模的网络。它利用 X25519 ECDH 生成临时会话密钥,提供前向安全性,即使长期密钥泄露,也能保护过去的通信记录。这使其成为开发者构建需要防篡改和防重放攻击消息协议的安全自主智能体网络时不可或缺的工具。
下载入口:https://github.com/openclaw/skills/tree/main/skills/cerbug45/agentmesh
安装与下载
1. ClawHub CLI
从源直接安装技能的最快方式。
npx clawhub@latest install agentmesh
2. 手动安装
将技能文件夹复制到以下位置之一
全局模式~/.openclaw/skills/
工作区
/skills/
优先级:工作区 > 本地 > 内置
3. 提示词安装
将此提示词复制到 OpenClaw 即可自动安装。
请帮我使用 Clawhub 安装 agentmesh。如果尚未安装 Clawhub,请先安装(npm i -g clawhub)。
AgentMesh 应用场景
- 在自主 AI 智能体之间建立安全、私密的通信通道。
- 构建对数据机密性有严格要求的跨智能体任务分配系统。
- 创建持久的智能体身份,在系统重启后仍能保持相同的加密指纹。
- 利用安全 TCP 中心在公共网络上实现跨机器的智能体协作。
- 智能体通过唯一 ID 初始化并连接到充当消息路由器的 Hub。
- 系统自动生成由 Ed25519 签名密钥和 X25519 交换密钥组成的加密身份。
- 智能体向 Hub 注册其公钥包,允许其他智能体通过其唯一的指纹进行发现。
- 发送消息时,发送方执行 ECDH 密钥交换以派生共享密钥并建立安全会话。
- 消息负载经过签名并加密成 AEAD 信封后发送至 Hub。
- Hub 将加密信封转发给接收者,在此过程中无法解密内部数据。
- 接收方智能体解密信封,验证发送方签名,并触发注册的消息处理器。
AgentMesh 配置指南
要开始使用此技能,您可以直接从源代码库安装:
pip install git+https://github.com/cerbug45/AgentMesh.git
对于需要修改协议或运行测试套件的开发者:
git clone https://github.com/cerbug45/AgentMesh.git
cd AgentMesh
pip install -e ".[dev]"
pytest
AgentMesh 数据架构与分类体系
AgentMesh 通过结构化的 JSON 和加密包管理身份和消息数据。这种组织方式是 Openclaw Skills 处理安全数据交换的核心部分。
| 组件 | 类型 | 描述 |
|---|---|---|
| 身份文件 | JSON | 存储私有的 Ed25519 和 X25519 密钥;支持持久化智能体指纹。 |
| 公钥包 | Dict | 包含公钥和智能体唯一的十六进制指纹,用于发现。 |
| 消息信封 | Binary/JSON | 包含密文、AEAD 标签和随机数的加密包装。 |
| 负载 | Dict | 解密后的应用数据,包括文本、任务 ID 和自定义元数据。 |
AgentMesh SKILL.md
WhatsApp-style end-to-end encrypted messaging for AI agents. GitHub: https://github.com/cerbug45/AgentMesh | Author: cerbug45
What Is AgentMesh?
AgentMesh gives every AI agent a cryptographic identity and lets agents exchange messages that are:
| Property | Mechanism |
|---|---|
| Encrypted | AES-256-GCM authenticated encryption |
| Authenticated | Ed25519 digital signatures (per message) |
| Forward-secret | X25519 ECDH ephemeral session keys |
| Tamper-proof | AEAD authentication tag |
| Replay-proof | Nonce + counter deduplication |
| Private | The Hub (broker) never sees message contents |
No TLS certificates. No servers required for local use. One pip install.
Installation
Requirements
- Python 3.10 or newer
pip
Option 1 – Install from GitHub (recommended)
pip install git+https://github.com/cerbug45/AgentMesh.git
Option 2 – Clone and install locally
git clone https://github.com/cerbug45/AgentMesh.git
cd AgentMesh
pip install .
Option 3 – Development install (editable, with tests)
git clone https://github.com/cerbug45/AgentMesh.git
cd AgentMesh
pip install -e ".[dev]"
pytest # run all tests
Verify installation
python -c "import agentmesh; print(agentmesh.__version__)"
# → 1.0.0
Quick Start (5 minutes)
from agentmesh import Agent, LocalHub
hub = LocalHub() # in-process broker
alice = Agent("alice", hub=hub) # keys generated automatically
bob = Agent("bob", hub=hub)
@bob.on_message
def handle(msg):
print(f"[{msg.recipient}] ← {msg.sender}: {msg.text}")
alice.send("bob", text="Hello, Bob! This is end-to-end encrypted.")
Output:
[bob] ← alice: Hello, Bob! This is end-to-end encrypted.
Core Concepts
Agent
An Agent is an AI agent with a cryptographic identity (two key pairs):
- Ed25519 identity key – signs every outgoing message
- X25519 exchange key – used for ECDH session establishment
from agentmesh import Agent, LocalHub
hub = LocalHub()
alice = Agent("alice", hub=hub)
# See the agent's fingerprint (share out-of-band to verify identity)
print(alice.fingerprint)
# → a1b2:c3d4:e5f6:g7h8:i9j0:k1l2:m3n4:o5p6
Hub
A Hub is the message router. It stores public key bundles (for discovery) and routes encrypted envelopes. It cannot decrypt messages.
| Hub | Use case |
|---|---|
LocalHub |
Single Python process (demos, tests, notebooks) |
NetworkHub |
Multi-process / multi-machine (production) |
Message
@bob.on_message
def handle(msg):
msg.sender # str – sender agent_id
msg.recipient # str – recipient agent_id
msg.text # str – shortcut for msg.payload["text"]
msg.type # str – shortcut for msg.payload["type"] (default: "message")
msg.payload # dict – full decrypted payload
msg.timestamp # int – milliseconds since epoch
Usage Guide
Sending messages with extra data
alice.send(
"bob",
text = "Run this task",
task_id = 42,
priority = "high",
data = {"key": "value"},
)
All keyword arguments beyond text are included in msg.payload.
Chaining handlers
# Handler as decorator
@alice.on_message
def handler_one(msg):
...
# Handler as lambda
alice.on_message(lambda msg: print(msg.text))
# Multiple handlers – all called in registration order
alice.on_message(log_handler)
alice.on_message(process_handler)
Persistent keys
Save keys to disk so an agent has the same identity across restarts:
alice = Agent("alice", hub=hub, keypair_path=".keys/alice.json")
- File is created on first run (new keys).
- File is loaded on subsequent runs (same keys = same fingerprint).
- Store this file securely – it contains the private key.
Peer discovery
# List all agents registered on the hub
peers = alice.list_peers() # → ["bob", "carol", "dave"]
# Check agent status
print(alice.status())
# {
# "agent_id": "alice",
# "fingerprint": "a1b2:…",
# "active_sessions": ["bob"],
# "known_peers": ["bob"],
# "handlers": 2
# }
Network Mode (multi-machine)
1. Start the hub server
On the broker machine (or in its own terminal):
# Option A – module
python -m agentmesh.hub_server --host 0.0.0.0 --port 7700
# Option B – entry-point (after pip install)
agentmesh-hub --host 0.0.0.0 --port 7700
2. Agents connect from anywhere
# Machine A
from agentmesh import Agent, NetworkHub
hub = NetworkHub(host="192.168.1.10", port=7700)
alice = Agent("alice", hub=hub)
# Machine B (different process / different computer)
from agentmesh import Agent, NetworkHub
hub = NetworkHub(host="192.168.1.10", port=7700)
bob = Agent("bob", hub=hub)
bob.on_message(lambda m: print(m.text))
alice.send("bob", text="Cross-machine encrypted message!")
Network hub architecture
┌──────────────────────────────────────────────────────┐
│ NetworkHubServer │
│ Stores public bundles. Routes encrypted envelopes. │
│ Cannot read message contents. │
└──────────────────────┬───────────────────────────────┘
│ TCP (newline-delimited JSON)
┌───────────┼───────────┐
│ │ │
Agent A Agent B Agent C
(encrypted) (encrypted) (encrypted)
Security Architecture
Cryptographic stack
┌─────────────────────────────────────────────────────┐
│ Application layer (dict payload) │
├─────────────────────────────────────────────────────┤
│ Ed25519 signature (sender authentication) │
├─────────────────────────────────────────────────────┤
│ AES-256-GCM (confidentiality + integrity) │
├─────────────────────────────────────────────────────┤
│ HKDF-SHA256 key derivation (directional keys) │
├─────────────────────────────────────────────────────┤
│ X25519 ECDH (shared secret / forward secrecy) │
└─────────────────────────────────────────────────────┘
Security properties
| Attack | Defence |
|---|---|
| Eavesdropping | AES-256-GCM encryption |
| Message tampering | AES-GCM authentication tag (AEAD) |
| Impersonation | Ed25519 signature on every message |
| Replay attack | Nonce + monotonic counter deduplication |
| Key compromise | X25519 ephemeral sessions (forward secrecy) |
| Hub compromise | Hub stores only public keys; cannot decrypt |
What the Hub can see
- ? Agent IDs (to route messages)
- ? Public key bundles (required for discovery)
- ? Metadata: sender, recipient, timestamp, message counter
- ? Message contents (always encrypted)
- ? Payload data (always encrypted)
Examples
| File | What it shows |
|---|---|
examples/01_simple_chat.py |
Two agents, basic send/receive |
examples/02_multi_agent.py |
Coordinator + 4 workers, task distribution |
examples/03_persistent_keys.py |
Keys saved to disk, identity survives restart |
examples/04_llm_agents.py |
LLM agents (OpenAI / any API) in a pipeline |
Run any example:
python examples/01_simple_chat.py
API Reference
Agent(agent_id, hub=None, keypair_path=None, log_level=WARNING)
| Method | Description |
|---|---|
send(recipient_id, text="", **kwargs) |
Send encrypted message |
send_payload(recipient_id, payload: dict) |
Low-level send |
on_message(handler) |
Register message handler (decorator or call) |
connect(peer_id) |
Pre-establish session (optional, auto-connects) |
connect_with_bundle(bundle) |
P2P: connect using public bundle directly |
list_peers() |
List all peer IDs on the hub |
status() |
Dict with agent state |
fingerprint |
Human-readable hex identity fingerprint |
public_bundle |
Dict with public keys (share with peers) |
LocalHub()
| Method | Description |
|---|---|
register(agent) |
Register an agent (called automatically) |
deliver(envelope) |
Route an encrypted envelope |
get_bundle(agent_id) |
Get a peer's public bundle |
list_agents() |
List all registered agent IDs |
message_count() |
Number of messages routed |
NetworkHub(host, port=7700)
Same interface as LocalHub, but communicates with a NetworkHubServer over TCP.
NetworkHubServer(host="0.0.0.0", port=7700)
| Method | Description |
|---|---|
start(block=True) |
Start listening (block=False for background thread) |
Low-level crypto (advanced)
from agentmesh.crypto import (
AgentKeyPair, # key generation, serialisation, fingerprint
CryptoSession, # encrypt / decrypt
perform_key_exchange,# X25519 ECDH → CryptoSession
seal, # sign + encrypt (high-level)
unseal, # decrypt + verify (high-level)
CryptoError, # raised on any crypto failure
)
Troubleshooting
CryptoError: Replay attack detected
You are sending the same encrypted envelope twice. Each call to send() produces a fresh envelope – do not re-use envelopes.
CryptoError: Authentication tag mismatch
The envelope was modified in transit. Check that your transport does not corrupt binary data (use JSON-safe base64).
ValueError: Peer 'xxx' not found on hub
The recipient has not registered with the hub yet. Ensure both agents are created with the same hub instance (LocalHub) or connected to the same hub server (NetworkHub).
RuntimeError: No hub configured
You created Agent("name") without a hub. Pass hub=LocalHub() or hub=NetworkHub(...) to the constructor.
Contributing
git clone https://github.com/cerbug45/AgentMesh.git
cd AgentMesh
pip install -e ".[dev]"
pytest -v
Issues and PRs welcome at https://github.com/cerbug45/AgentMesh/issues
License
MIT ? cerbug45 – see LICENSE
相关推荐
专题
+ 收藏
+ 收藏
+ 收藏
+ 收藏
+ 收藏
最新数据
相关文章
行动建议器:人工智能驱动的潜客跟进建议 - Openclaw Skills
会话成本追踪器:优化 Token 投资回报率 - Openclaw Skills
Memoria: AI 智能体结构化记忆系统 - Openclaw Skills
Deno 运行时专家:安全 TypeScript 开发 - Openclaw Skills
为 AI 代理部署 Spark Bitcoin L2 代理 - Openclaw Skills
加密货币价格技能:实时市场数据集成 - Openclaw Skills
Happenstance:专业人脉搜索与研究 - Openclaw Skills
飞书日历技能:通过 Openclaw Skills 自动化日程安排
顾问委员会:多人格 AI 加密货币分析 - Openclaw Skills
CRIF:面向 AI Agent 的加密深度研究框架 - Openclaw Skills
AI精选
