feat(topology): template builders + evolution/QD search (P5)
ci / gates (push) Has been cancelled
ci / rust (push) Has been cancelled
ci / sandbox-k8s (push) Has been cancelled
ci / frontend (push) Has been cancelled
ci / e2e (push) Has been cancelled

cm-topology::build(kind, roles) instantiates a canonical graph for any of the 12
kinds from a role list (the template catalog + the search generator).

cm-orchestrator::evolve searches a (kinds × team-size) grid using the comparison
machinery as fitness: build a candidate per cell, run the task, score it, and
keep a MAP-Elites-style archive of per-cell elites + a quality/cost Pareto front
and the global best. evolve_all() covers every kind at full size. This is the
bridge toward Autonomous Organizational Evolution on a safe substrate — every
candidate still executes via safe turns (§15 invariant holds).

Demoed in topology_bench (auto-picks the best topology + Pareto kinds).
cm-topology 20 tests; cm-orchestrator 17 (--features provider); clippy clean.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
Omar Sobh
2026-06-15 21:36:01 -07:00
co-authored by Claude Opus 4.8
parent bd982943b8
commit b0c122b88d
5 changed files with 320 additions and 1 deletions
@@ -15,7 +15,7 @@
use std::sync::Arc;
use cm_llm::LlmProvider;
use cm_orchestrator::{compare, run_workflow, ProviderExecutor, RunRecord, Scorer};
use cm_orchestrator::{compare, evolve_all, run_workflow, ProviderExecutor, RunRecord, Scorer};
use cm_topology::{Edge, EdgeKind, Node, TopologyGraph, TopologyKind};
/// Deterministic quality proxy: richer (longer) output scores higher.
@@ -142,4 +142,25 @@ async fn main() {
wf.totals.turns,
wf.totals.tokens
);
// Evolution: search every topology kind for the best fit for this task.
let roles = ["coordinator", "researcher", "analyst", "writer"];
let ev = evolve_all(&roles, task, &executor, &LengthScorer)
.await
.expect("evolution failed");
println!("\nevolution: searched {} topologies", ev.evaluated);
if let Some(i) = ev.best {
let b = &ev.archive[i];
println!(
" best: {:?} (size {}) quality {:.2} tokens {}",
b.kind, b.size, b.quality, b.tokens
);
}
let pareto: Vec<String> = ev
.archive
.iter()
.filter(|c| c.on_pareto)
.map(|c| format!("{:?}", c.kind))
.collect();
println!(" pareto-optimal: {}", pareto.join(", "));
}