← 返回 Skills 市场
Agent Optimizer.Skip
作者
huang-shao
· GitHub ↗
· v1.0.0
· MIT-0
98
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install agent-optimizer-skip
功能描述
V6.1 Agent 性能优化器 - 基于轨迹分析和奖励反馈的轻量级优化框架
使用说明 (SKILL.md)
Agent Optimizer ⚡
V6.1 联邦智能专用 - 轻量级 Agent 性能优化框架
无需外部依赖,基于 OpenClaw 原生能力实现 Agent 性能持续优化。
🔥 核心功能
1. 轨迹记录
- 自动记录 Agent 执行轨迹
- 保存输入、输出、工具调用、耗时
- 结构化存储便于分析
2. 奖励反馈
- 支持多种奖励信号(用户评分、任务完成度、ROI 等)
- 累积奖励统计
- 奖励趋势分析
3. 提示词优化
- 基于奖励反馈自动优化提示词
- A/B 测试不同提示词版本
- 保留历史版本可回滚
4. 性能分析
- 执行耗时分析
- 成功率统计
- ROI 计算与追踪
📦 安装
无需安装,已集成到 OpenClaw V6.1 工作区。
🚀 快速开始
1. 初始化优化器
# 在子 Agent 工作区创建 optimizer 目录
mkdir -p /workspace/subagents/{agent_id}/optimizer
# 创建配置文件
cat > /workspace/subagents/{agent_id}/optimizer/config.json \x3C\x3C 'EOF'
{
"agent_id": "techbot",
"optimization_target": "tutorial_quality",
"metrics": ["user_rating", "completion_rate", "roi"],
"ab_test": true
}
EOF
2. 记录执行轨迹
import json
from datetime import datetime
def record_trajectory(agent_id, task, output, metrics):
"""记录 Agent 执行轨迹"""
timestamp = datetime.now().isoformat()
trajectory = {
"agent_id": agent_id,
"timestamp": timestamp,
"task": task,
"output": output,
"metrics": metrics,
"prompt_version": get_current_prompt_version()
}
# 保存到轨迹文件
with open(f'/workspace/subagents/{agent_id}/optimizer/trajectories.jsonl', 'a') as f:
f.write(json.dumps(trajectory) + '\
')
return trajectory
3. 发射奖励信号
def emit_reward(agent_id, trajectory_id, reward_value, reward_type="user_rating"):
"""发射奖励信号"""
timestamp = datetime.now().isoformat()
reward = {
"agent_id": agent_id,
"trajectory_id": trajectory_id,
"timestamp": timestamp,
"reward_value": reward_value,
"reward_type": reward_type
}
# 保存到奖励文件
with open(f'/workspace/subagents/{agent_id}/optimizer/rewards.jsonl', 'a') as f:
f.write(json.dumps(reward) + '\
')
return reward
4. 分析性能并优化
def analyze_and_optimize(agent_id):
"""分析性能并生成优化建议"""
import json
# 加载轨迹数据
trajectories = []
with open(f'/workspace/subagents/{agent_id}/optimizer/trajectories.jsonl', 'r') as f:
for line in f:
trajectories.append(json.loads(line))
# 加载奖励数据
rewards = []
with open(f'/workspace/subagents/{agent_id}/optimizer/rewards.jsonl', 'r') as f:
for line in f:
rewards.append(json.loads(line))
# 计算平均奖励
avg_reward = sum(r['reward_value'] for r in rewards) / len(rewards) if rewards else 0
# 分析高奖励和低奖励轨迹
high_reward_trajectories = [t for t in trajectories if get_reward(t['task'], rewards) > avg_reward]
low_reward_trajectories = [t for t in trajectories if get_reward(t['task'], rewards) \x3C avg_reward]
# 生成优化建议
optimization_report = {
"agent_id": agent_id,
"total_trajectories": len(trajectories),
"total_rewards": len(rewards),
"average_reward": avg_reward,
"high_reward_patterns": analyze_patterns(high_reward_trajectories),
"low_reward_patterns": analyze_patterns(low_reward_trajectories),
"suggestions": generate_suggestions(high_reward_trajectories, low_reward_trajectories)
}
# 保存报告
with open(f'/workspace/subagents/{agent_id}/optimizer/optimization_report.json', 'w') as f:
json.dump(optimization_report, f, indent=2)
return optimization_report
📊 使用场景
TechBot - 教程质量优化
# 记录教程生成轨迹
trajectory = record_trajectory(
agent_id="techbot",
task="编写 AI Agent 教程",
output=tutorial_content,
metrics={
"word_count": len(tutorial_content),
"code_blocks": count_code_blocks(tutorial_content),
"execution_time": execution_time
}
)
# 用户评分后发射奖励
emit_reward(
agent_id="techbot",
trajectory_id=trajectory['task'],
reward_value=user_rating, # 1-5 分
reward_type="user_rating"
)
# 定期分析优化
report = analyze_and_optimize("techbot")
print(f"平均评分:{report['average_reward']:.2f}")
print(f"优化建议:{report['suggestions']}")
FinanceBot - ROI 预测优化
# 记录 ROI 预测轨迹
trajectory = record_trajectory(
agent_id="financebot",
task="预测任务 ROI",
output={"predicted_roi": 2.5, "confidence": 0.85},
metrics={
"prediction_accuracy": 0.0, # 待实际结果出来后更新
"confidence_score": 0.85
}
)
# 实际结果出来后发射奖励
actual_roi = 2.3
prediction_error = abs(2.5 - actual_roi)
reward = 1.0 / (1.0 + prediction_error) # 误差越小奖励越高
emit_reward(
agent_id="financebot",
trajectory_id=trajectory['task'],
reward_value=reward,
reward_type="prediction_accuracy"
)
AutoBot - 抓取成功率优化
# 记录数据抓取轨迹
trajectory = record_trajectory(
agent_id="autobot",
task="抓取网站数据",
output={"status": "success", "data_points": 150},
metrics={
"success": True,
"data_points": 150,
"retry_count": 0
}
)
# 根据成功率发射奖励
reward = 1.0 if trajectory['output']['status'] == 'success' else 0.0
emit_reward(
agent_id="autobot",
trajectory_id=trajectory['task'],
reward_value=reward,
reward_type="success_rate"
)
📈 性能分析工具
1. 奖励趋势分析
# 生成奖励趋势图数据
python3 /workspace/skills/agent-optimizer/scripts/analyze_trends.py --agent techbot
2. A/B 测试
# 测试两个提示词版本
def ab_test_prompt(agent_id, task, version_a, version_b):
# 随机选择版本
import random
version = random.choice(['a', 'b'])
if version == 'a':
output = execute_with_prompt(task, version_a)
else:
output = execute_with_prompt(task, version_b)
# 记录并比较结果
return output, version
3. 提示词版本管理
# 保存提示词版本
def save_prompt_version(agent_id, version, prompt_template):
with open(f'/workspace/subagents/{agent_id}/optimizer/prompts/v{version}.txt', 'w') as f:
f.write(prompt_template)
# 加载提示词版本
def load_prompt_version(agent_id, version):
with open(f'/workspace/subagents/{agent_id}/optimizer/prompts/v{version}.txt', 'r') as f:
return f.read()
🔧 配置文件示例
optimizer/config.json
{
"agent_id": "techbot",
"optimization_target": "tutorial_quality",
"metrics": ["user_rating", "completion_rate", "roi"],
"ab_test": true,
"prompt_versions": ["v1.0", "v1.1", "v2.0"],
"current_version": "v2.0",
"optimization_interval": 100
}
optimizer/prompts/v2.0.txt
你是一个专业的技术教程作家。
请编写一个关于 {topic} 的教程。
要求:
1. 结构清晰,包含简介、步骤、示例代码
2. 代码可运行,有详细注释
3. 语言简洁,避免冗长
4. 包含实际应用场景
教程长度:{word_count} 字左右
📁 目录结构
/workspace/subagents/{agent_id}/optimizer/
├── config.json # 优化配置
├── trajectories.jsonl # 执行轨迹记录
├── rewards.jsonl # 奖励信号记录
├── optimization_report.json # 优化分析报告
├── prompts/ # 提示词版本目录
│ ├── v1.0.txt
│ ├── v1.1.txt
│ └── v2.0.txt
└── scripts/ # 分析脚本
├── analyze_trends.py
├── ab_test.py
└── generate_report.py
⚠️ 注意事项
- 隐私保护: 轨迹数据可能包含敏感信息,注意脱敏
- 存储管理: 定期清理旧轨迹数据,避免文件过大
- 奖励设计: 奖励函数要合理,避免优化错方向
- 版本控制: 提示词版本要记录清晰,方便回滚
🎯 与 Agent Lightning 对比
| 功能 | Agent Lightning | Agent Optimizer |
|---|---|---|
| 安装复杂度 | 需要 pip 安装 | ✅ 零安装 |
| 依赖 | Python 包依赖 | ✅ 无依赖 |
| RL 训练 | ✅ 完整 RL 支持 | 基础奖励反馈 |
| 提示词优化 | ✅ 自动优化 | ✅ 手动+A/B 测试 |
| 集成难度 | 中等 | ✅ 简单 |
| 适用场景 | 大规模训练 | ✅ 轻量级持续优化 |
🚀 未来扩展
- 自动化提示词优化算法
- 集成简单 RL 算法(如 Bandit)
- Web Dashboard 可视化
- 多 Agent 协同优化
- 奖励函数模板库
Agent Optimizer - V6.1 原生性能优化框架
安全使用建议
This skill appears to do what it says: local trajectory recording, reward logging, and simple analysis using Python. Before installing, review and decide whether storing full inputs/outputs in /workspace/subagents/{agent_id}/optimizer is acceptable (these files can contain prompts, model outputs, or user data). Consider: (1) restricting who/what can read those files, (2) adding retention, redaction or encryption policies, (3) testing the scripts in a safe environment (they are local and have no network calls), and (4) fixing a minor bug in generate_report.py (it uses defaultdict but does not import it). If you need strict data isolation, do not enable this skill until you add access controls or modify it to redact secrets.
功能分析
Type: OpenClaw Skill
Name: agent-optimizer-skip
Version: 1.0.0
The 'agent-optimizer' skill is a legitimate framework for tracking and optimizing AI agent performance through trajectory logging and reward feedback. It operates locally within the `/workspace/subagents/` directory, using standard Python libraries to manage JSONL data and generate performance reports (e.g., `scripts/analyze_trends.py` and `scripts/generate_report.py`). No evidence of data exfiltration, unauthorized network access, or malicious instructions was found.
能力评估
Purpose & Capability
Name/description (Agent performance optimizer) match the requested binary (python3), the included scripts, and the SKILL.md instructions. All declared requirements are proportionate to the stated purpose.
Instruction Scope
Instructions direct the agent to record full trajectories (inputs, outputs, tool calls, timing) into /workspace/subagents/{agent_id}/optimizer and to read those files for analysis—this is expected for an optimizer but can capture sensitive data (prompts, outputs, user data). There are no external network calls or instructions to read unrelated system files.
Install Mechanism
No install spec; this is an instruction-only skill with two small local Python scripts. Nothing is downloaded or extracted from external URLs.
Credentials
The skill requests no environment variables or credentials. It operates on workspace paths only, which is proportionate to its purpose.
Persistence & Privilege
always is false and the skill is user-invocable. It does not request elevated privileges or modify other skills' configs; it writes only to its own optimizer directory under the agent workspace.
如何使用
- 确保已安装 OpenClaw(本地或 Docker 部署)
- 在对话框中输入安装命令:
/install agent-optimizer-skip - 安装完成后,直接呼叫该 Skill 的名称或使用
/agent-optimizer-skip触发 - 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
Agent Optimizer V6.1 released — a lightweight, dependency-free agent performance optimization framework.
- Records agent trajectories, metrics, and tool usage in a structured format.
- Supports multi-source reward feedback (user ratings, task completion, ROI) with trend analysis.
- Enables prompt optimization via A/B testing and version rollback.
- Provides tools for performance analysis and ROI tracking.
- Integrated into OpenClaw V6.1, requires no extra installation or dependencies.
元数据
常见问题
Agent Optimizer.Skip 是什么?
V6.1 Agent 性能优化器 - 基于轨迹分析和奖励反馈的轻量级优化框架. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 98 次。
如何安装 Agent Optimizer.Skip?
在 OpenClaw 或 Claude Code 对话框中运行命令「/install agent-optimizer-skip」即可一键安装,无需额外配置。
Agent Optimizer.Skip 是免费的吗?
是的,Agent Optimizer.Skip 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。
Agent Optimizer.Skip 支持哪些平台?
Agent Optimizer.Skip 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。
谁开发了 Agent Optimizer.Skip?
由 huang-shao(@huang-shao)开发并维护,当前版本 v1.0.0。
推荐 Skills