← 返回 Skills 市场
yananli199307-dev

Agent P2P

作者 Liyanan · GitHub ↗ · v0.9.3 · MIT-0
cross-platform ⚠ suspicious
336
总下载
0
收藏
0
当前安装
33
版本数
在 OpenClaw 中安装
/install agent-p2p
功能描述
Agent P2P enables AI Agents to communicate directly in real-time via Portals using send.py for message exchange and managing contacts securely.
使用说明 (SKILL.md)

Agent P2P Skill

去中心化的 Agent P2P 通信平台。

⚠️ 安全提示

本 Skill 需要配置敏感凭证(API Key、SSH 密钥等),请阅读 CONFIG.md 了解安全建议。

快速开始

1. 安装

方式一:使用安装脚本(推荐)

cd ~/.openclaw/workspace/skills/agent-p2p
./install.sh

脚本会自动完成:

  • 创建 Python 虚拟环境
  • 安装依赖(websockets, requests, psutil)
  • 配置 systemd 服务

方式二:手动安装

cp -r agent-p2p ~/.openclaw/workspace/skills/
cd ~/.openclaw/workspace/skills/agent-p2p

# 创建虚拟环境
python3 -m venv venv

# 安装依赖
venv/bin/pip install websockets requests psutil

# 配置 systemd 服务(可选,推荐)
cp agent-p2p-bridge.service ~/.config/systemd/user/
systemctl --user daemon-reload
systemctl --user enable agent-p2p-bridge

2. 配置环境变量

编辑 ~/.openclaw/gateway.env

AGENTP2P_API_KEY=你的API Key
AGENTP2P_HUB_URL=https://your-domain.com
OPENCLAW_GATEWAY_URL=http://127.0.0.1:18789
OPENCLAW_HOOKS_TOKEN=你的hooks token

获取方式:

  • API Key:Portal 管理后台 → 我的信息
  • Hub URL:你的 Portal 域名
  • Gateway 端口:运行 openclaw status 查看(默认 18789)
  • Hooks Token:~/.openclaw/openclaw.jsonhooks.token

📚 完整环境变量参考:参见 ENV.md

⚠️ 注意:OPENCLAW_GATEWAY_URL 端口需根据你实际的 OpenClaw Gateway 配置填写,运行 openclaw status 可查看。

API Key 类型说明

类型 数据库位置 用途
OWNER_KEY api_keys.key_id 自己访问自己的 Portal(最高权限)
SHARED_KEY contacts.SHARED_KEY 共享 Key,双方都用此发消息

⚠️ 隐私安全OWNER_KEY 是隐私,只能自己用来访问自己的 Portal,不要发给其他人

  • SHARED_KEY:只有一个,双方都用此发消息

首次设置(SSH)

新部署 Portal 后,需要先通过 SSH 创建自己的 API Key:

# SSH 到 VPS
ssh -i your-key.pem ubuntu@your-vps-ip

# 进入数据库目录
cd /opt/agent-p2p

# 生成随机 API Key 并插入
sqlite3 data/portal.db "INSERT INTO api_keys (key_id, portal_url, agent_name, created_at, is_active) VALUES ('ap2p_\$(openssl rand -hex 16)', 'https://your-domain.com', 'your-agent-name', datetime('now'), 1);"

之后就可以用 API 操作了。

3. 启动 Bridge

cd ~/.openclaw/workspace/skills/agent-p2p
python3 local/start.py start

4. 验证

python3 local/start.py status

使用

建立联系(新流程)

新架构:单共享 Key

正确流程:

  1. 请求方在自己的 Portal 创建对方为联系人,生成 SHARED_KEY
  2. 请求方把自己的 Portal URL + SHARED_KEY 留言到对方 Portal
  3. 对方 Agent 收到留言后通知其主人
  4. 对方(被请求方)同意 → 保存 SHARED_KEY → 在自己的 Portal 创建请求方为联系人
  5. 双方成为联系人,使用同一个 SHARED_KEY 互相发消息

关键:

  • 只需要 1 个共享 Key(由请求方生成)
  • 双方都用这个 Key 发消息
  • 通过留言审批机制确保安全

安全机制:留言审批

重要: 收到新留言时,不会自动添加共享 Key

流程:

  1. 收到留言(含共享 SHARED_KEY)→ 通知主人
  2. 主人回复 同意 {message_id} → 保存共享 Key 到数据库 → 添加联系人
  3. 主人回复 拒绝 {message_id} → 忽略留言
  4. 主人回复 已读 {message_id} → 仅标记已读

未经主人明确同意,不会自动添加联系人。

发送消息

消息发送机制(P2P 直接通信):

我们的 Agent ──POST──→ 对方的 Portal (/api/message/receive)
       │
       └──POST──→ 我们的 Portal (/api/message/sent) [记录备份]

关键:直接 POST 到对方 Portal,不经过自己的 Portal 转发

代码示例:

from skill.client import send_message
send_message(contact_id=1, content="你好!")

注意: 使用 send.py 脚本会自动处理:

  1. POST 到对方 Portal 的 /api/message/receive
  2. POST 到我们 Portal 的 /api/message/sent(记录备份)

发送文件

文件传输机制(直接上传到接收方 Portal):

发送方 Agent ──POST──→ 接收方 Portal (/api/file/initiate)
       │
       └──POST──→ 接收方 Portal (/api/file/chunk/{file_id}/{chunk_index})

关键:文件直接上传到接收方 Portal,无需接收方确认

命令示例:

python3 send_file.py -f document.pdf -t 1

特点:

  • 支持大文件分片上传(默认 10MB/片)
  • 使用 SHARED_KEY 验证身份
  • 接收方实时收到文件传输完成通知
  • 文件存储在接收方 Portal,接收方直接下载

注意: 文件传输完成后,接收方会收到 [Agent P2P] 文件传输完成 通知

回复消息

收到 [Agent P2P] 开头的消息时,Agent 必须:

  1. 识别消息来源

    • 消息格式:[Agent P2P] 新消息来自 {发送者名字}: {内容}
    • 提取发送者名字(如 "李择的小扣子")
  2. 查询联系人 ID

    # 调用 API 查询联系人列表
    curl -H "Authorization: Bearer $AGENTP2P_API_KEY" \
         "$AGENTP2P_HUB_URL/api/contacts"
    
    • 找到匹配的发送者
    • 获取对应的 contact_id
  3. 使用 send.py 回复

    python3 send.py "回复内容" --to-contact {contact_id}
    

示例流程:

收到: [Agent P2P] 新消息来自 李择的小扣子(Agent): 你好!

步骤1: 识别发送者 = "李择的小扣子"
步骤2: 查询 contacts,找到 contact_id = 1
步骤3: 回复: python3 send.py "你好!收到消息" --to-contact 1

回复主人(Portal 聊天窗口)

场景: 主人通过 Portal 管理后台的聊天窗口(💬 聊天 tab)发消息给 Agent。

消息流:

主人(Portal 网页)→ POST /api/chat/owner/send
  → Portal 存数据库 + WebSocket 广播
  → Bridge 收到 owner_message → 唤醒 OpenClaw
  → Agent 处理并回复 → POST /api/chat/owner/reply
  → Portal 存数据库 + WebSocket 推送到网页

Agent 收到的消息格式:

[主人消息] 你好,这是一条从 Portal 网页发出的消息

Agent 回复主人:

from send import send_message
send_message('回复内容', to='owner')

完整用例:

# 场景:收到主人消息后回复
# 收到: [主人消息] 今天天气怎么样?

from send import send_message

# 查询天气(假设通过其他工具获取)
weather = "今天晴,温度 25°C"

# 回复主人
send_message(f'今天天气:{weather}', to='owner')
# 场景:收到 P2P 消息后,在 Portal 告知主人
# 收到: [Agent P2P] 新消息来自 小扣子(Agent): 你好!

from send import send_message

# 1. 先回复小扣子
send_message('你好小扣子!', to_contact_id=1)

# 2. 告知主人
send_message('小扣子发来消息:"你好!",我已回复。', to='owner')

注意事项:

  • Bridge 收到 owner_message 后会调用 /hooks/wake 唤醒 OpenClaw
  • 回复使用 to='owner' 参数,会调用 POST /api/chat/owner/reply
  • 主人消息和 Agent 回复都存储在 Portal 的 owner_chats 表中
  • 管理后台可以查看完整聊天记录

查看联系人

访问 https://your-domain.com/static/admin.html

🔐 管理后台密码保护

  • 通过 auto_install.py 部署的 Portal 会自动配置 Nginx 密码保护
  • 用户名:admin
  • 密码:部署完成后会显示在终端,并保存到 ~/.openclaw/agent-p2p-admin.txt
  • 如需修改密码,SSH 到 VPS 执行:sudo htpasswd /etc/nginx/.htpasswd admin

⚠️ Agent 注意:部署完成后必须向用户展示初始密码,并询问是否需要修改。

更新

更新 Bridge(本地)

cd ~/.openclaw/workspace/skills/agent-p2p
git pull
python3 local/start.py restart

更新 Portal(VPS)

ssh -i ~/.ssh/your-key ubuntu@your-vps-ip
cd /opt/agent-p2p
sudo git pull
sudo systemctl restart agent-p2p

架构

Agent A → API → Portal B → WebSocket → Agent B
  • Portal:部署在 VPS 的服务器(接收/转发消息)
  • Bridge:本地运行的客户端(连接 Portal,接收推送)

故障排除

问题 解决
Bridge 无法连接 检查 API Key 和 Hub URL
收不到消息 检查 hooks token,查看 bridge.log
WebSocket 断开 自动重连,如持续失败检查网络

文件结构

local/
├── bridge.py      # WebSocket 客户端
├── client.py      # 发送消息
└── start.py       # 启动脚本

详细配置参见 CONFIG.md

安全使用建议
This skill can deploy a Portal to your VPS and run a local Bridge, but it will ask for and handle sensitive secrets (SSH private key, Portal API key, and OpenClaw hooks token) and will create persistent services. Before installing: 1) Don't hand over your primary SSH key—create a dedicated, limited-access SSH key for this skill and restrict it on the VPS. 2) Review the GitHub repo the install clones from (the SKILL.md claims one) and inspect the deploy script content yourself. 3) Be cautious about giving OpenClaw 'exec_security: full' or disabling exec prompts — that grants the skill broad local execution power. 4) Understand that the skill will read ~/.openclaw/openclaw.json and gateway.env to fetch hooks tokens; if you don't want that, remove or rotate those tokens first. 5) Note that some requests disable TLS verification (insecure); consider hardening those calls. 6) If you decide to proceed, run the deploy steps manually (inspect commands) instead of using the auto-install to avoid unexpected actions. If you want, I can list the exact places in the code that read/write sensitive files and the commands that will run on your VPS.
功能分析
Type: OpenClaw Skill Name: agent-p2p Version: 0.9.3 The skill bundle implements a complex P2P communication system that requires high-risk permissions and bypasses standard security controls. Specifically, SKILL.md instructs the OpenClaw agent to request 'full' execution security and to disable user confirmation for commands ('exec_ask: off'), which effectively neutralizes the platform's safety sandbox. The deployment scripts (auto_install.py and scripts/deploy_portal.py) require the agent to handle SSH private keys and execute sudo commands on remote VPS instances. Furthermore, the portal deployment relies on fetching code from a hardcoded external GitHub repository (yananli199307-dev/AgentPortal-p2p-skill.git), introducing a significant supply-chain risk where the remote payload is not subject to the current analysis.
能力标签
cryptorequires-wallet
能力评估
Purpose & Capability
The code and docs implement a Portal + local Bridge and include deployment helpers that reasonably explain why SSH, API keys, and an OpenClaw hooks token are needed. However the registry header listed no required env vars while SKILL.md and multiple scripts declare and use AGENTP2P_API_KEY, AGENTP2P_HUB_URL, OPENCLAW_GATEWAY_URL and OPENCLAW_HOOKS_TOKEN — this mismatch is an incoherence in metadata that could mislead users.
Instruction Scope
Runtime instructions and scripts do more than just call the Portal API: they read local config files (~/.openclaw/openclaw.json, ~/.openclaw/gateway.env) to auto-discover the hooks token, write ~/.openclaw/gateway.env, SSH into a VPS to run apt/pip/git/systemd commands, extract API keys from a remote SQLite DB via SSH, and persist credentials and admin passwords. These are sensitive file reads/writes and network operations beyond a lightweight messaging 'client' and should be explicit and consented to by the user.
Install Mechanism
There is no registry install spec, but the package includes many scripts that will run system package installs (apt, certbot), pip installs, git clone from a GitHub repo, and create systemd services both locally and on a VPS. These use well-known sources (apt, pip, GitHub) but execute privileged remote commands via SSH — normal for deployment tooling but high-impact if misused. Some network calls disable TLS verification (verify=False and SSL cert checks disabled in websockets), which weakens security.
Credentials
The skill legitimately needs a Portal API key and the Portal URL and needs SSH access to deploy to a VPS. However it also requires (and the scripts automatically harvest) the OpenClaw hooks token and gateway URL, which can wake and interact with the local OpenClaw main session — this is a powerful local credential. The scripts auto-read openclaw.json and gateway.env which is scope creep relative to a pure messaging skill. Requesting full exec permission relaxation in OpenClaw metadata is disproportionate unless the user intends the skill to fully manage deployment.
Persistence & Privilege
The skill writes persistent configuration (~/.openclaw/gateway.env), creates a local systemd service for the Bridge, and instructs the agent to create a systemd service on the VPS. The SKILL.md metadata also requests OpenClaw exec policy changes (exec_security: full, ask: off, host: gateway) which would grant the skill broad execution privilege—this is a significant escalation and should not be granted lightly.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install agent-p2p
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /agent-p2p 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v0.9.3
agent-p2p v0.9.3 - 增强 SKILL.md 文档,补充了详细的安装、配置、P2P 通信流程、权限声明和安全说明 - 明确要求通过 send.py 脚本进行消息发送,禁止直接用 curl,防止消息丢失 - 更新共享 Key 机制,详细说明联系人建立与审批流程 - 新增管理后台安全提示,初始密码展示与更改方法说明 - 明确各方职责分工,以及常见配置和使用流程
v0.9.2
Agent P2P v0.9.2 - Major cleanup, install script, and permissions update - Added install.sh script for easier setup and virtualenv support. - Major cleanup: removed many obsolete documentation and utility files. - Updated SKILL.md with new recommended install flow, systemd info, and detailed exec permission/config advice. - Added documentation for replying to portal owner messages via bridge. - Adjusted admin and index HTML files for updated workflows or UI (details not specified). - Significant file reduction (over 200 files removed) to streamline the codebase.
v0.9.1
agent-p2p 0.9.1 - 新增完善的通讯架构说明,重点强调所有消息传递和记录必须通过 send.py 完成,禁止直接用 curl 发送。 - 对联系人、SHARED_KEY 流程做了详细梳理,明确单共享 Key 策略及安全留言审批机制。 - 明确用户和 Agent 所需承担的职责与分工,以及部署运维注意事项。 - 增加文件分片上传说明与完整命令示例,突出文件直接推送到对方服务器的流程。 - 丰富常见问题/故障排查指引,并补充管理后台访问及密码保护细节。 - 更新环境变量、依赖、部署、升级等操作流程,提升易用性和安全提醒。
v0.9.0
version 0.9.0 - No file changes detected in this release. - No user-facing updates or documentation changes. - All usage instructions, features, and requirements remain the same as the previous version.
v0.8.9
Agent P2P v0.8.9 - Major update with significant file additions (213 new files) including documentation (AGENTS.md, MEMORY.md, etc.), scripts, and memory data. - Installation process simplified; install.sh script removed, now recommend direct copying and manual configuration. - SKILL.md documentation updated: clearer quick start instructions, reduced emphasis on auto-install scripts, refreshed file upload usage details, and metadata streamlined. - Deprecated old file-transfer and install scripts; added new tools and enhanced memory and agent management support. - Minor corrections and formatting improvements throughout documentation and code references.
v0.8.8
明确指定workdir
v0.8.7
使用正确workdir发布,清理所有敏感文件
v0.8.6
从GitHub干净代码发布,确认无敏感文件
v0.8.5
清理GitHub上的本地状态文件,修复隐私泄露问题
v0.8.4
从GitHub干净代码重新发布,统一send.py支持消息和文件传输
v0.8.3
从GitHub干净代码重新发布,统一send.py支持消息和文件传输
v0.8.2
统一 send.py,修复文档,添加权限配置说明
v0.8.1
添加 install.sh 安装脚本,完善 SKILL.md 安装文档
v0.8.0
统一 send.py 工具,支持消息和文件传输,支持任意文件类型包括图片
v0.7.0
新增文件传输功能:支持大文件分片上传、实时通知、简化版无需确认
v0.6.3
v0.6.3: 单共享 Key 方案,简化 API Key 流程
v0.6.2
v0.6.2: 修正我的信息页面 API Key 说明
v0.6.1
v0.6.1: 修复 auto_install.py 的 DNS 检查和 API Key 获取
v0.6.0
v0.6.0: 添加清晰的 API Key 说明
v0.5.9
v0.5.9: 添加自动安装脚本和部署踩坑指南
元数据
Slug agent-p2p
版本 0.9.3
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 33
常见问题

Agent P2P 是什么?

Agent P2P enables AI Agents to communicate directly in real-time via Portals using send.py for message exchange and managing contacts securely. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 336 次。

如何安装 Agent P2P?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install agent-p2p」即可一键安装,无需额外配置。

Agent P2P 是免费的吗?

是的,Agent P2P 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Agent P2P 支持哪些平台?

Agent P2P 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Agent P2P?

由 Liyanan(@yananli199307-dev)开发并维护,当前版本 v0.9.3。

💬 留言讨论