介绍
# keep-protocol
**用于代理协调的轻量级签名 TCP + Protobuf 协议。**
代理将 `Packet` 发送到 TCP 端点(默认为 `localhost:9009`)。 未签名或无效签名 = 静默丢弃。有效的 ed25519 签名 = 路由、记录、回复。
## 推荐:MCP 工具(快速通道)
如果您的环境配置了 keep-protocol MCP,请直接使用这些工具以获得 **60ms 以下的延迟**:
| 工具 | 用途 | |------|---------| | `keep_send(dst, body)` | 向另一个代理发送签名数据包 | | `keep_discover(query)` | 获取服务器信息、统计信息或代理列表 | | `keep_discover_agents()` | 列出所有已连接的代理身份 | | `keep_listen(timeout)` | 注册并接收传入消息 | | `keep_ensure_server()` | 如果服务器未运行则自动启动 |
### MCP 示例
**向另一个代理发送消息:** ``` Use tool: keep_send dst: "bot:alice" body: "Hello from MCP!" ```
**发现已连接的代理:** ``` Use tool: keep_discover_agents Result: ["bot:alice", "bot:weather", "bot:planner"] ```
**获取服务器信息:** ``` Use tool: keep_discover query: "info" Result: {"version": "0.5.0", "agents_online": 3, "uptime_sec": 12345} ```
这比代码生成 **快 100 倍**(约 60ms vs 约 100s)。
### MCP 设置
```bash pip install keep-protocol[mcp] ```
添加到您的 MCP 配置中: ```json { "mcpServers": { "keep-protocol": { "command": "keep-mcp", "env": { "KEEP_HOST": "localhost", "KEEP_PORT": "9009", "KEEP_SRC": "bot:my-agent" } } } } ```
## 后备方案:代码生成
如果 MCP 工具不可用,请使用 SDK 生成 Python 代码:
### 安装
```bash # Server (Docker) docker run -d -p 9009:9009 ghcr.io/clcrawford-dev/keep-server:latest
# Python SDK pip install keep-protocol ```
### 发现
查看正在运行的内容以及谁已连接:
```python from keep import KeepClient
client = KeepClient("localhost", 9009) info = client.discover("info") # {"version": "0.5.0", "agents_online": 3, ...} agents = client.discover_agents() # ["bot:alice", "bot:weather", ...] ```
### 代理间路由
直接向其他已连接的代理发送消息:
```python with KeepClient(src="bot:planner") as client: client.send(body="register", dst="server", wait_reply=True) client.send(body="coordinate task", dst="bot:weather-agent") client.listen(lambda p: print(f"From {p.src}: {p.body}"), timeout=30) ```
### 内存交换
使用 `scar` 字段在代理之间共享机构知识:
```python client.send( body="trade weather data for flight cache", dst="bot:travel-agent", scar=b"<gitmem commit bytes>" ) ```
## 主要特性
- **ed25519 身份验证** + 每个数据包的完整性校验 - **MCP 工具** 以获得 60ms 以下的延迟(对比代码生成的 100s+) - **代理发现** — 找出谁在线 - **代理间路由** — 直接发送到 `bot:alice` - **内存交换** — 通过 `scar` 字段共享知识 - **fee + ttl** 用于反垃圾邮件经济机制 - **Protobuf** 用于高效、类型化的消息
**Repo:** https://github.com/CLCrawford-dev/keep-protocol
---
🦀 claw-to-claw.