闲社服务运行正常AI智能体自动化平台
a

Agent性能优化

技能标识:agent-optimizer

V6.1 Agent 性能优化器 - 基于轨迹分析和奖励反馈的轻量级优化框架

作者:admin | 来源记录:ClawHub
登记来源
ClawHub
版本
V 1.0.0
检测标记
后台标记通过
免费
免费获取
0
收藏
来源与检测标记为平台登记信息,并不代表已展示可复核的检测报告。使用前请核对版本、依赖和所需权限,建议先在隔离环境中运行。
概述
安装方式
版本历史

Agent性能优化

Agent Optimizer ⚡

V6.1 联邦智能专用 - 轻量级 Agent 性能优化框架

无需外部依赖,基于 OpenClaw 原生能力实现 Agent 性能持续优化。

🔥 核心功能

1. 轨迹记录

  • - 自动记录 Agent 执行轨迹
  • 保存输入、输出、工具调用、耗时
  • 结构化存储便于分析

2. 奖励反馈

  • - 支持多种奖励信号(用户评分、任务完成度、ROI 等)
  • 累积奖励统计
  • 奖励趋势分析

3. 提示词优化

  • - 基于奖励反馈自动优化提示词
  • A/B 测试不同提示词版本
  • 保留历史版本可回滚

4. 性能分析

  • - 执行耗时分析
  • 成功率统计
  • ROI 计算与追踪

📦 安装

无需安装,已集成到 OpenClaw V6.1 工作区。

🚀 快速开始

1. 初始化优化器

python

在子 Agent 工作区创建 optimizer 目录


mkdir -p /workspace/subagents/{agent_id}/optimizer

创建配置文件

cat > /workspace/subagents/{agent_id}/optimizer/config.json << EOF { agent_id: techbot, optimizationtarget: tutorialquality, metrics: [userrating, completionrate, roi], ab_test: true } EOF

2. 记录执行轨迹

python
import json
from datetime import datetime

def recordtrajectory(agentid, task, output, metrics):
记录 Agent 执行轨迹
timestamp = datetime.now().isoformat()

trajectory = {
agentid: agentid,
timestamp: timestamp,
task: task,
output: output,
metrics: metrics,
promptversion: getcurrentpromptversion()
}

# 保存到轨迹文件
with open(f/workspace/subagents/{agent_id}/optimizer/trajectories.jsonl, a) as f:
f.write(json.dumps(trajectory) + \n)

return trajectory

3. 发射奖励信号

python
def emitreward(agentid, trajectoryid, rewardvalue, rewardtype=userrating):
发射奖励信号
timestamp = datetime.now().isoformat()

reward = {
agentid: agentid,
trajectoryid: trajectoryid,
timestamp: timestamp,
rewardvalue: rewardvalue,
rewardtype: rewardtype
}

# 保存到奖励文件
with open(f/workspace/subagents/{agent_id}/optimizer/rewards.jsonl, a) as f:
f.write(json.dumps(reward) + \n)

return reward

4. 分析性能并优化

python
def analyzeandoptimize(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))

# 计算平均奖励
avgreward = sum(r[rewardvalue] for r in rewards) / len(rewards) if rewards else 0

# 分析高奖励和低奖励轨迹
highrewardtrajectories = [t for t in trajectories if getreward(t[task], rewards) > avgreward]
lowrewardtrajectories = [t for t in trajectories if getreward(t[task], rewards) < avgreward]

# 生成优化建议
optimization_report = {
agentid: agentid,
total_trajectories: len(trajectories),
total_rewards: len(rewards),
averagereward: avgreward,
highrewardpatterns: analyzepatterns(highreward_trajectories),
lowrewardpatterns: analyzepatterns(lowreward_trajectories),
suggestions: generatesuggestions(highrewardtrajectories, lowreward_trajectories)
}

# 保存报告
with open(f/workspace/subagents/{agentid}/optimizer/optimizationreport.json, w) as f:
json.dump(optimization_report, f, indent=2)

return optimization_report

📊 使用场景

TechBot - 教程质量优化

python

记录教程生成轨迹

trajectory = record_trajectory( agent_id=techbot, task=编写 AI Agent 教程, output=tutorial_content, metrics={ wordcount: len(tutorialcontent), codeblocks: countcodeblocks(tutorialcontent), executiontime: executiontime } )

用户评分后发射奖励

emit_reward( agent_id=techbot, trajectory_id=trajectory[task], rewardvalue=userrating, # 1-5 分 rewardtype=userrating )

定期分析优化

report = analyzeandoptimize(techbot) print(f平均评分:{report[average_reward]:.2f}) print(f优化建议:{report[suggestions]})

FinanceBot - ROI 预测优化

python

记录 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 predictionerror = abs(2.5 - actualroi) reward = 1.0 / (1.0 + prediction_error) # 误差越小奖励越高

emit_reward(
agent_id=financebot,
trajectory_id=trajectory[task],
reward_value=reward,
rewardtype=predictionaccuracy
)

AutoBot - 抓取成功率优化

python

记录数据抓取轨迹

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, rewardtype=successrate )

📈 性能分析工具

1. 奖励趋势分析

bash

生成奖励趋势图数据

python3 /workspace/skills/agent-optimizer/scripts/analyze_trends.py --agent techbot

2. A/B 测试

python

测试两个提示词版本

def abtestprompt(agentid, task, versiona, version_b): # 随机选择版本 import random version = random.choice([a, b])

if version == a:
output = executewithprompt(task, version_a)
else:
output = executewithprompt(task, version_b)

# 记录并比较结果
return output, version

3. 提示词版本管理

python

保存提示词版本

def savepromptversion(agentid, version, prompttemplate): with open(f/workspace/subagents/{agent_id}/optimizer/prompts/v{version}.txt, w) as f: f.write(prompt_template)

加载提示词版本

def loadpromptversion(agent_id, version): with open(f/workspace/subagents/{agent_id}/optimizer/prompts/v{version}.txt, r) as f: return f.read()

🔧 配置文件示例

optimizer/config.json

json { agent_id: techbot, optimizationtarget: tutorialquality, metrics: [userrating, completionrate, roi], ab_test: true, prompt_versions: [v1.0, v1.

标签

skill ai

通过对话安装

以下为平台配置的接入选项,并非逐项实测通过。能否安装取决于客户端支持、技能来源和运行环境:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 agent-optimizer-1776292358 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 agent-optimizer-1776292358 技能

通过命令行安装

skillhub install agent-optimizer-1776292358

下载

⬇ 下载 agent-optimizer v1.0.0(免费)

文件大小: 7.27 KB | 发布时间: 2026-4-16 16:32

v1.0.0 最新 2026-4-16 16:32
Agent Optimizer 1.0.0

- Initial public release of Agent Optimizer (V6.1) for OpenClaw workspace.
- Provides trajectory recording, reward feedback, and prompt optimization for agents.
- Enables performance analysis (e.g., timing, success rate, ROI) without external dependencies.
- Supports A/B testing of prompt versions and structured result storage.
- Includes sample code for trajectory logging, reward emission, and optimization analysis.
返回顶部