治理·自动化
回归检测集成
与 Evaluation Framework 连接
使用 AIDLC Evaluation Framework 中定义的 Golden Dataset,在新版本部署前检测回归。
工作流:
Baseline vs New 统计比较
指标:
- 准确率:Exact Match, F1, BLEU(翻译)
- 质量:LLM-as-Judge 分数(0-1)
- 延迟:P50, P99
- 成本:token 使用量
统计检验:
from scipy.stats import ttest_ind
# baseline: 旧版本 100 个样本的 Exact Match 分数
baseline_scores = [...] # 例:平均 0.82
# new: 新版本 100 个样本
new_scores = [...] # 例:平均 0.85
t_stat, p_value = ttest_ind(baseline_scores, new_scores)
if p_value < 0.05 and mean(new_scores) > mean(baseline_scores):
print("新版本统计显著优于旧版本 → 批准部署")
elif mean(new_scores) < mean(baseline_scores) * 0.95:
print("新版本下降超过 5% → 回滚")
else:
print("无显著差异 → 需要额外验证")
自动回滚触发器
条件:
- 准确率绝对下降:
new_exact_match < baseline_exact_match - 0.05 - 延迟回归:
new_p99_latency > baseline_p99_latency * 1.5 - 错误率增加:
new_error_rate > 5% - 用户反馈:
thumbs_down_rate > 20%
实现:
# Prometheus Alert
- alert: PromptRegressionDetected
expr: |
langfuse_eval_exact_match{prompt_version="6"}
< langfuse_eval_exact_match{prompt_version="5"} - 0.05
for: 30m
annotations:
summary: "提示词 v6 准确率下降 → 自动回滚"
# Webhook → Lambda → Langfuse API (将 production 标签恢复到 v5)
运营治理
变更审批工作流
应用 AIDLC Checkpoints:
| 阶段 | Checkpoint | 审批人 | 标准 |
|---|---|---|---|
| 1. 提示词变更提案 | [Answer]: | 领域专家 | 明确意图和风险评估 |
| 2. Staging 评估结果 | 通过回归检测 | Lead Engineer | Exact Match ≥ 基线 - 2% |
| 3. Canary 5% 部署 | 实时指标审查 | SRE | 错误率 < 1%, P99 latency ≤ 1.2x |
| 4. Prod 100% 切换 | 最终批准 | Product Owner | 确认业务指标改善 |
审批自动化(GitHub Actions + Langfuse):
# .github/workflows/prompt-approval.yml
name: Prompt Approval
on:
pull_request:
paths:
- 'prompts/**'
jobs:
evaluate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run Golden Dataset Eval
run: |
python scripts/eval_prompt.py --new-version ${{ github.sha }}
- name: Post Results
uses: actions/github-script@v7
with:
script: |
const results = require('./eval_results.json');
if (results.exact_match < results.baseline - 0.02) {
core.setFailed('检测到回归:Exact Match 下降');
}
github.rest.issues.createComment({
issue_number: context.issue.number,
body: `### 评估结果\n- Baseline: ${results.baseline}\n- New: ${results.exact_match}\n- 判定: ${results.pass ? '✅ 批准' : '❌ 拒绝'}`
});
变更记录(Audit Log)
Langfuse:所有提示词变更自动记录到版本历史。另外:
# 变更时记录元数据
client.create_prompt(
name="financial-analysis",
prompt="...",
labels=["production"],
metadata={
"changed_by": "jane@example.com",
"jira_ticket": "AIDLC-1234",
"approval": "approved_by_john_2026-04-17",
"rollback_plan": "revert to v5 if error_rate > 5%"
}
)
AWS CloudTrail:使用 Bedrock Prompt Management 时
{
"eventName": "UpdatePromptAlias",
"userIdentity": {
"principalId": "AIDAI...",
"arn": "arn:aws:iam::123456789012:user/jane"
},
"requestParameters": {
"promptIdentifier": "fin-analysis",
"aliasIdentifier": "PROD",
"promptVersion": "6"
},
"eventTime": "2026-04-17T14:30:00Z"
}