steps.js
3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
* Evolution Steps — Phase 2 自然选择循环的每一步
*
* 4 步循环: Evaluate → Select → Reproduce → BenchmarkEvolve
* 所有判断由 Agent (LLM) 完成,无规则降级。
*/
const evolutionQueries = require('./queries').evolutionQueries;
// ═══════════════════════════════════════
// Step 1: Evaluate — Agent 驱动的能力测验
// ═══════════════════════════════════════
/**
* 评估所有存活基因组:
* 1. Arena 场景评估 (选择压力主来源)
* 2. Benchmark 探针评估 (补充维度)
* 3. 6 维适应度汇总
*/
async function stepEvaluate(runId, { log }) {
const { evaluateRunInArena } = require('./arena/arena');
const { evaluateRunWithBenchmarks } = require('./arena/benchmark-executor');
const { evaluateRunFitness } = require('./operators/fitness-calculator');
// 1. Arena 场景评估
log('🏟️ Arena 场景评估...');
const arenaResult = await evaluateRunInArena(runId);
const arenaEvaluated = arenaResult.ranked?.length || 0;
log(` 🏟️ ${arenaEvaluated} 个基因组完成 Arena`);
// 2. Benchmark 探针评估
log('🎯 Benchmark 探针评估...');
const benchResults = await evaluateRunWithBenchmarks(runId);
const benchPassed = benchResults.filter(r => r.passed).length;
// 3. 6 维适应度汇总 → 写 overall_fitness
log('🧮 适应度评估...');
const fitnessResults = await evaluateRunFitness(runId);
return {
arenaEvaluated,
arenaTopScore: arenaResult.ranked?.[0]?.overall || null,
benchmarkPassed: benchPassed,
benchmarkTotal: benchResults.length,
fitnessEvaluated: fitnessResults.length,
avgFitness: fitnessResults.length > 0
? parseFloat((fitnessResults.reduce((s, r) => s + r.overall, 0) / fitnessResults.length).toFixed(4))
: null,
};
}
// ═══════════════════════════════════════
// Step 2: Select — 淘汰低分,保留高分
// ═══════════════════════════════════════
async function stepSelect(runId, { log }) {
const { selectGeneration } = require('./operators/selector');
log('🏆 选择与淘汰...');
const selection = await selectGeneration(runId, { eliteCount: 2, survivalRate: 0.5 });
return { selection };
}
// ═══════════════════════════════════════
// Step 3: Reproduce — 交叉 + 变异 → 下一代
// ═══════════════════════════════════════
async function stepReproduce(runId, { log, generation }) {
const { crossoverGeneration } = require('./operators/crossover');
const { applyMutations } = require('./operators/mutator');
log('🔀 交叉重组...');
const children = await crossoverGeneration(runId, generation);
log('🧬 变异...');
const mutants = await applyMutations(runId, generation);
return { crossoverChildren: children.length, mutants: mutants.length };
}
// ═══════════════════════════════════════
// Step 4: Benchmark 自进化 — 红皇后效应
// ═══════════════════════════════════════
async function stepBenchmarkEvolve(runId, { log }) {
const { evolveAllBenchmarks } = require('./benchmark/evolver');
log('🔄 环境进化...');
await evolveAllBenchmarks(runId);
return {};
}
module.exports = {
stepEvaluate,
stepSelect,
stepReproduce,
stepBenchmarkEvolve,
};