🎁 Get the FREE AI Skills Starter GuideSubscribe →
BytesAgainBytesAgain
🦀 ClawHub

Skylv Ai Prompt Optimizer

by @sky-lv

AI 提示词自动优化器。基于 A/B 测试和性能数据,自动优化提示词,提升输出质量和降低 Token 消耗。Triggers: prompt optimizer, improve prompt, prompt engineering, A/B testing, prompt optimization.

Versionv1.0.3
Downloads438
Installs2
TERMINAL
clawhub install skylv-ai-prompt-optimizer

📖 About This Skill


name: ai-prompt-optimizer slug: skylv-ai-prompt-optimizer version: 1.0.2 description: AI prompt auto-optimizer. A/B tests prompts and auto-improves output quality while reducing token costs. Triggers: prompt optimization, prompt engineering, reduce tokens. author: SKY-lv license: MIT tags: [prompt, optimization, ab-testing, engineering, ai] keywords: prompt, optimization, llm, gpt triggers: ai prompt optimizer

AI Prompt Optimizer — 提示词自动优化器

功能说明

基于 A/B 测试和性能数据,自动优化 AI 提示词,提升输出质量并降低 Token 消耗。让提示词工程从"艺术"变成"科学"。

核心能力

1. 提示词分析 (Prompt Analysis)

analysis_dimensions:
  - clarity: 清晰度(指令是否明确)
  - specificity: 具体性(是否有足够细节)
  - structure: 结构化(是否有清晰格式)
  - examples: 示例(是否有 few-shot 示例)
  - constraints: 约束(是否有输出限制)
  - tone: 语气(是否适合场景)

scoring: - overall_score: 0-100 - dimension_scores: 各维度分数 - improvement_areas: 需改进的方面

使用示例:

用户:分析这个提示词的质量
Agent:
  1. 多维度评分
  2. 识别问题点
  3. 提供改进建议

2. A/B 测试 (A/B Testing)

test_setup:
  - variants: 2-5 个提示词变体
  - sample_size: 每个变体 100+ 次测试
  - metrics: 质量评分、Token 消耗、用户满意度
  - duration: 7-14 天

metrics_tracked: - output_quality: 输出质量(1-5 分) - token_efficiency: Token 效率 - user_satisfaction: 用户满意度 - task_completion: 任务完成率

使用示例:

用户:为这个提示词运行 A/B 测试
Agent:
  1. 生成 3 个变体
  2. 分配流量(33% each)
  3. 收集性能数据
  4. 选出最优版本

3. 自动优化 (Auto Optimization)

optimization_techniques:
  - prompt_compression: 压缩冗余内容
  - structure_addition: 添加结构化格式
  - example_injection: 注入 few-shot 示例
  - constraint_refinement: 优化约束条件
  - tone_adjustment: 调整语气风格

expected_improvements: - token_reduction: 30-60% - quality_improvement: 20-40% - consistency: 提升 50%+

使用示例:

用户:优化这个提示词
Agent:
  1. 分析当前版本
  2. 应用优化技术
  3. 输出优化版本
  4. 对比性能数据

4. 提示词库 (Prompt Library)

categories:
  - writing: 写作类
  - coding: 编程类
  - analysis: 分析类
  - creative: 创意类
  - business: 商业类

features: - search: 关键词搜索 - filter: 按类别/评分筛选 - rating: 社区评分 - versioning: 版本历史

优化框架

BEFORE → AFTER 对比

❌ 低效提示词:

帮我写一个 Python 函数,要能处理各种情况,
考虑周全一点,输出要好。

✅ 优化后:

# 角色
Python 高级开发工程师

任务

编写一个数据验证函数

输入

  • data: dict,待验证数据
  • schema: dict,验证规则
  • 输出

  • valid: bool,是否通过验证
  • errors: list,错误列表(如有)
  • 约束

  • 使用 type hints
  • 添加 docstring
  • 包含单元测试示例
  • 处理边界情况
  • 示例

    输入:{"name": "John", "age": 25} 输出:{"valid": True, "errors": []}

    效果对比: | 指标 | Before | After | 提升 | |------|--------|-------|------| | Token 消耗 | 800 | 450 | -44% | | 输出质量 | 3.2/5 | 4.6/5 | +44% | | 一致性 | 60% | 92% | +53% |

    优化技巧清单

    1. 角色定义

  • ❌ "你是一个助手"
  • ✅ "你是拥有 10 年经验的资深 Python 工程师,擅长编写生产级代码"
  • 2. 任务明确

  • ❌ "帮我处理这个"
  • ✅ "分析以下数据,输出 3 个关键洞察,每个洞察包含数据支撑"
  • 3. 输出格式

  • ❌ "输出结果"
  • ✅ "以 JSON 格式输出,包含 keys: summary, insights, recommendations"
  • 4. 添加示例

  • ❌ 无示例
  • ✅ "输入示例:... 期望输出:..."
  • 5. 约束条件

  • ❌ 无约束
  • ✅ "不超过 500 字,使用专业术语,避免口语化"
  • 工具函数

    analyze_prompt

    def analyze_prompt(prompt: str) -> dict:
        """
        提示词分析
        
        Args:
            prompt: 待分析提示词
        
        Returns:
            {
                "overall_score": 65,
                "dimensions": {
                    "clarity": 70,
                    "specificity": 55,
                    "structure": 60,
                    "examples": 40,
                    "constraints": 50
                },
                "issues": [
                    "缺少角色定义",
                    "输出格式不明确",
                    "没有示例"
                ],
                "suggestions": [
                    "添加专业角色定义",
                    "指定 JSON 输出格式",
                    "添加 few-shot 示例"
                ]
            }
        """
    

    optimize_prompt

    def optimize_prompt(prompt: str, goal: str = "quality") -> dict:
        """
        提示词优化
        
        Args:
            prompt: 原始提示词
            goal: 优化目标 (quality|tokens|speed)
        
        Returns:
            {
                "original": {...},
                "optimized": "优化后的提示词",
                "changes": ["添加角色", "结构化", "添加示例"],
                "expected_improvement": {
                    "quality": "+35%",
                    "tokens": "-40%",
                    "consistency": "+50%"
                }
            }
        """
    

    run_ab_test

    def run_ab_test(base_prompt: str, variants: list, iterations: int = 100) -> dict:
        """
        A/B 测试
        
        Args:
            base_prompt: 基础提示词
            variants: 变体列表
            iterations: 测试次数
        
        Returns:
            {
                "winner": "variant_2",
                "results": [
                    {"variant": "base", "score": 3.8, "tokens": 500},
                    {"variant": "v1", "score": 4.1, "tokens": 450},
                    {"variant": "v2", "score": 4.6, "tokens": 420}
                ],
                "statistical_significance": 0.95
            }
        """
    

    generate_variants

    def generate_variants(prompt: str, count: int = 5) -> list:
        """
        生成提示词变体
        
        Args:
            prompt: 原始提示词
            count: 生成数量
        
        Returns:
            [
                {"id": "v1", "prompt": "...", "changes": ["添加角色"]},
                {"id": "v2", "prompt": "...", "changes": ["结构化"]},
                ...
            ]
        """
    

    提示词模板库

    写作类

    template: blog_post
    prompt: |
      # 角色
      资深内容创作者,10 年科技博客经验

    # 任务 撰写一篇关于{主题}的博客文章

    # 要求 - 字数:2000-2500 字 - 结构:引言 + 3-5 个主体段落 + 结论 - 语气:专业但易懂 - 包含:实际案例、数据支撑、行动建议

    # 输出格式 Markdown,包含 H2/H3标题、列表、引用块

    编程类

    template: code_review
    prompt: |
      # 角色
      资深代码审查工程师,精通{语言}

    # 任务 审查以下代码,输出审查报告

    # 审查维度 1. 代码质量(命名、结构、注释) 2. 安全性(OWASP Top 10) 3. 性能(时间/空间复杂度) 4. 可维护性(测试、文档)

    # 输出格式 JSON: { "issues": [{"severity": "high|medium|low", "description": "...", "fix": "..."}], "score": 0-100, "summary": "..." }

    分析类

    template: data_analysis
    prompt: |
      # 角色
      数据科学家,擅长商业洞察

    # 任务 分析以下数据集,输出商业洞察

    # 分析框架 1. 描述性统计(均值、中位数、分布) 2. 趋势分析(同比、环比) 3. 异常检测(离群值、异常模式) 4. 商业建议(可行动洞察)

    # 输出格式 Markdown 报告,包含图表描述、关键数字、行动建议

    相关文件

  • Prompt Engineering Guide
  • OpenAI Best Practices
  • Anthropic Prompt Design
  • 触发词

  • 自动:检测 prompt、optimize、improve、A/B testing 相关关键词
  • 手动:/prompt-optimizer, /optimize-prompt, /ab-test
  • 短语:优化提示词、改进 prompt、A/B 测试
  • Usage

    1. Install the skill 2. Configure as needed 3. Run with OpenClaw

    💡 Examples

    1. Install the skill 2. Configure as needed 3. Run with OpenClaw