feat(openclaw): patrol/exploration skill with loop-based skill sync

This commit is contained in:
sinohqb 2026-08-04 01:32:13 +08:00
parent 3c97e6e1ba
commit fc167a8e4e
3 changed files with 150 additions and 9 deletions

View File

@ -32,7 +32,17 @@
部署脚本(`scripts/deploy-t480.sh`)会自动把它同步到 OpenClaw 工作区:
`data/openclaw/workspace/skills/agenteval-run/SKILL.md`
### 方式二Python Skill 封装
### 方式二agenteval-patrol 巡检技能探索式评测v0.9
`skills/agenteval-patrol/SKILL.md` 指导 AI 助手作为常驻巡检代理完成探索闭环:
调巡检 API`GET /api/exploration/patrol`)→ 研判新结果与预算余量 → 决定是否派发
探索会话 → 以虚拟用户身份驱动会话对话 → 提交体验记录关闭会话。说明书内含收到
409 时的收敛行为与衍生变体的种子回溯(`seed_ref`)要求。
部署脚本会把 `backend/plugins/openclaw/skills/` 下的每个技能同步到
`data/openclaw/workspace/skills/<skill-name>/SKILL.md`
### 方式三Python Skill 封装
参考 `agenteval_skill.py`httpx 调 API在 OpenClaw 中注册技能时传入配置:
@ -60,6 +70,21 @@ config:
report_format: "json"
```
### 常驻巡检作业(探索式评测)
巡检代理需注册为全局常驻作业,默认节拍 1 小时;调度状态由 OpenClaw 自身持久化,
重启后不丢:
```yaml
skill: agenteval-patrol
schedule: "0 * * * *" # 每小时整点巡检一次
config:
api_base_url: "http://agenteval:8000"
```
巡检 API 自带水位(`last_patrolled_at`),每个节拍只报增量结果,重复触发不会
重复上报;预算与间隔护栏在服务端强制执行,代理收到 409 即收敛。
## API 速查
| 操作 | 请求 |
@ -67,6 +92,10 @@ config:
| 启动评测 | `POST /api/runs` body: `{"target_id", "scenario_id", "triggered_by": "ai_assistant"}` |
| 查询状态 | `GET /api/runs/{run_id}`(轮询至 completed/failed |
| 获取报告 | `GET /api/reports/{run_id}` |
| 巡检探索 | `GET /api/exploration/patrol`(无参数,报增量新结果与预算余量) |
| 派发探索会话 | `POST /api/exploration/sessions` body: `{"campaign_id", "persona", "goal", "seed_ref?", "triggered_by"}` |
| 驱动会话对话 | `POST /api/exploration/sessions/{session_id}/messages` body: `{"content"}` |
| 提交体验记录 | `POST /api/exploration/sessions/{session_id}/close` body: `{"experience"}` |
如果平台设置了 `AGENTEVAL_API_KEY`,所有请求需带 `X-API-Key` 头。

View File

@ -0,0 +1,110 @@
---
name: agenteval-patrol
description: 常驻巡检:巡检 AgentEvalTool 评测活动,研判新结果与预算余量,自主派发并驱动探索式评测会话
---
你是平台的常驻巡检代理。本 skill 指导你按「巡检 → 研判 → 派发 → 驱动 → 提交」的闭环行动。
所有操作必须走 AgentEvalTool 标准 HTTP API禁止直接调 CLI 或操作数据库)。
平台可能启用了 API Key 鉴权。每次执行命令前先读取密钥(文件不存在则为空,不影响未启用鉴权的环境):
```bash
KEY=$(cat ~/.openclaw/agenteval-api-key 2>/dev/null)
```
以下所有 curl 命令都必须带 `-H "X-API-Key: $KEY"`
## 巡检(闭环第一步)
```bash
curl -s -H "X-API-Key: $KEY" http://agenteval:8000/api/exploration/patrol | python3 -m json.tool
```
返回所有参与探索的进行中正式线活动。每个活动包含:
- `new_results`自上次巡检以来的新评测结果null 表示无新增)。有值时先消化它——通过率下滑的能力项是本次探索的优先方向。
- `budget`:探索预算台账。`remaining_sessions` 为剩余可派发会话数;`seconds_since_last_session` 与 `min_interval_seconds` 用于判断会话间隔是否已满足。
- 该接口自带水位:每次调用只报增量,无需自己记录上次结果。
## 研判与派发决策
对每个活动,按以下规则决定是否派发探索会话:
1. `remaining_sessions` 为 0 → 不派发(预算耗尽)。
2. `seconds_since_last_session` 非 null 且小于 `min_interval_seconds` → 不派发(间隔未到,等下个节拍)。
3. 其余情况可派发一个会话。persona 与 goal 必须取自活动的种子集:
```bash
curl -s -H "X-API-Key: $KEY" http://agenteval:8000/api/campaigns/<campaign_id> | python3 -m json.tool
```
读取响应中的 `exploration_seeds.personas``exploration_seeds.goals`,各取其一组合。允许在种子上做衍生变体(如把「查账单」衍生为「查账单并开发票」),但必须在 `seed_ref` 里回溯来源。
## 派发探索会话
```bash
curl -s -X POST http://agenteval:8000/api/exploration/sessions \
-H "X-API-Key: $KEY" \
-H "Content-Type: application/json" \
-d '{
"campaign_id": "<campaign_id>",
"persona": {"name": "<人设名>", "traits": ["<特质1>", "<特质2>"]},
"goal": "<探索目标>",
"seed_ref": {"persona_seed": "<所用 persona 种子原文>", "goal_seed": "<所用 goal 种子原文>", "derived": false},
"triggered_by": "auto"
}'
```
- 直接使用种子时 `derived` 为 false衍生变体时为 true并追加 `"derived_from": "<原种子>"``"variant": "<变异点说明>"`——留痕是探索数据可回溯的底线。
- 响应中的 `id` 即 session_id后续所有步骤都要用它。
## 驱动会话对话
以 persona 的身份向目标推进 goal每轮发送一条用户消息并同步收到回复
```bash
curl -s -X POST http://agenteval:8000/api/exploration/sessions/<session_id>/messages \
-H "X-API-Key: $KEY" \
-H "Content-Type: application/json" \
-d '{"content": "<本轮用户消息>"}'
```
- 根据 `reply` 决定下一轮:追问、纠正、换路径,直到目标达成或确认走不通。
- 单会话默认最多 12 轮,以 patrol 返回的 `budget.max_turns` 为准,接近上限时尽快收尾。
- 502 表示通道异常;连续两次 502 就结束会话,把异常写进体验记录备注。
## 提交体验记录(闭环收尾)
会话必须显式关闭,提交第一人称体验记录——这是探索证据链的源头,务必如实:
```bash
curl -s -X POST http://agenteval:8000/api/exploration/sessions/<session_id>/close \
-H "X-API-Key: $KEY" \
-H "Content-Type: application/json" \
-d '{
"experience": {
"goal_achieved": true,
"blockers": ["<遇到的障碍逐条列出>"],
"misled": ["<被误导的经历回答把你带偏的地方>"],
"emotion": "positive",
"notes": "<整体体验简述>"
}
}'
```
- `emotion` 只能是 positive / neutral / confused / frustrated 之一,按真实体感选择。
- `blockers``misled` 写具体事实(如「让我重复提供订单号三次」),不写空泛评价。
## 收到 409 的收敛行为
409 是平台账本的明确拒绝,一律停止当前动作、不重试:
- 创建会话 409预算耗尽 / 间隔不足 / 活动非进行中)→ 本活动本轮放弃派发,记录原因,等下个巡检节拍。
- 发消息 409会话不在进行中 / 轮数超限)→ 立即走关闭流程提交已有体验记录;若关闭也返回 409说明会话已被平台收口如活动终态结算放弃并记录原因。
- 404活动或会话不存在→ 对象已消失,跳过。
## 汇报要求
每个巡检节拍结束后向用户汇报:巡检到的活动数、派发的会话数(含被 409 拦截的原因)、关闭的会话及其目标达成情况与关键问题。
请将 <campaign_id><session_id> 等占位符替换为实际值。

View File

@ -93,14 +93,16 @@ run rsync -az --delete \
./ "$HOST:$REMOTE_DIR/"
# ── OpenClaw skill sync ────────────────────────────────────────────────
# The agenteval-run skill lives in the openclaw workspace volume (data/),
# which rsync excludes. Sync the versioned copy explicitly so the AI
# assistant always follows the standard HTTP API flow.
SKILL_SRC="backend/plugins/openclaw/skills/agenteval-run/SKILL.md"
SKILL_DST="$REMOTE_DIR/data/openclaw/workspace/skills/agenteval-run/SKILL.md"
# OpenClaw skills live in the openclaw workspace volume (data/), which
# rsync excludes. Sync every versioned skill explicitly so the AI
# assistant always follows the standard HTTP API flows.
for SKILL_SRC in backend/plugins/openclaw/skills/*/SKILL.md; do
SKILL_NAME=$(basename "$(dirname "$SKILL_SRC")")
SKILL_DST="$REMOTE_DIR/data/openclaw/workspace/skills/$SKILL_NAME/SKILL.md"
log "sync OpenClaw skill → $SKILL_DST"
run ssh "$HOST" "mkdir -p $(dirname "$SKILL_DST")"
run rsync -az "$SKILL_SRC" "$HOST:$SKILL_DST"
done
# Provision the API key file the skill reads (~/.openclaw/agenteval-api-key in
# the openclaw container = data/openclaw/agenteval-api-key on the host). Sourced