CMDCSkillEngine.QualityTracker (cmdc_skill_engine v0.2.2)

Copy Markdown View Source

质量追踪器:计算、更新 Skill 质量指标,并在明显劣化时自动停用。

核心指标:

  • applied_rate — 选中后实际应用的比率
  • completion_rate — 应用后任务完成的比率
  • effective_rate — 端到端效率(选中 → 应用 → 完成)
  • fallback_rate — 选中但未应用的比率(不可用信号)

v0.2 新增:自动停用(deactivation)

update_from_analysis/2 每次更新 SkillRecord 后,若满足以下全部条件, 会把 is_active 置为 false(保留档案用于审计):

  1. total_selections >= min_samples(默认 5)
  2. applied_rate < applied_mineffective_rate < effective_min
  3. trend != :improving

参数从 Application 环境读取:

config :cmdc_skill_engine, :quality_gates,
  min_samples: 5,
  applied_min: 0.3,
  effective_min: 0.2,
  trend_window: 10

想在测试里临时覆盖,传 optsupdate_from_analysis/3

Summary

Functions

返回当前有效的 quality_gates 设置(合并 Application + opts 覆盖后)。

只计算是否应该停用,不修改 record。便于外部审查 / debug。

Functions

quality_gates(opts \\ [])

@spec quality_gates(keyword()) :: keyword()

返回当前有效的 quality_gates 设置(合并 Application + opts 覆盖后)。

should_deactivate?(record, opts \\ [])

@spec should_deactivate?(
  CMDCSkillEngine.Types.SkillRecord.t(),
  keyword()
) :: boolean()

只计算是否应该停用,不修改 record。便于外部审查 / debug。

trend(record, window \\ 10)

@spec trend(CMDCSkillEngine.Types.SkillRecord.t(), non_neg_integer()) :: %{
  effective_rate: float(),
  trend: :improving | :stable | :declining
}

update_from_analysis(record, analysis, opts \\ [])