swarm-engine 1.3.0 → 1.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -7
- package/dist/cli/commands/memory.js +117 -0
- package/dist/cli/commands/memory.js.map +1 -1
- package/dist/core/patterns.d.ts +7 -1
- package/dist/core/patterns.d.ts.map +1 -1
- package/dist/core/patterns.js +23 -0
- package/dist/core/patterns.js.map +1 -1
- package/dist/core/types.d.ts +39 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js.map +1 -1
- package/dist/index.d.ts +55 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -1
- package/dist/memory/index.d.ts +37 -0
- package/dist/memory/index.d.ts.map +1 -1
- package/dist/memory/index.js +91 -0
- package/dist/memory/index.js.map +1 -1
- package/dist/runtime/adaptive.d.ts +1 -0
- package/dist/runtime/adaptive.d.ts.map +1 -1
- package/dist/runtime/adaptive.js +18 -4
- package/dist/runtime/adaptive.js.map +1 -1
- package/dist/runtime/agent-runner.d.ts +18 -0
- package/dist/runtime/agent-runner.d.ts.map +1 -1
- package/dist/runtime/agent-runner.js +147 -4
- package/dist/runtime/agent-runner.js.map +1 -1
- package/dist/runtime/backends/claude-session.d.ts +49 -0
- package/dist/runtime/backends/claude-session.d.ts.map +1 -0
- package/dist/runtime/backends/claude-session.js +237 -0
- package/dist/runtime/backends/claude-session.js.map +1 -0
- package/dist/runtime/backends/claude.d.ts.map +1 -1
- package/dist/runtime/backends/claude.js +90 -4
- package/dist/runtime/backends/claude.js.map +1 -1
- package/dist/runtime/backends/types.d.ts +31 -1
- package/dist/runtime/backends/types.d.ts.map +1 -1
- package/dist/runtime/compaction.d.ts +7 -1
- package/dist/runtime/compaction.d.ts.map +1 -1
- package/dist/runtime/compaction.js +12 -2
- package/dist/runtime/compaction.js.map +1 -1
- package/dist/runtime/distiller.d.ts +1 -0
- package/dist/runtime/distiller.d.ts.map +1 -1
- package/dist/runtime/distiller.js +8 -2
- package/dist/runtime/distiller.js.map +1 -1
- package/dist/runtime/engine.d.ts +48 -2
- package/dist/runtime/engine.d.ts.map +1 -1
- package/dist/runtime/engine.js +600 -8
- package/dist/runtime/engine.js.map +1 -1
- package/dist/runtime/execution-graph.d.ts +86 -0
- package/dist/runtime/execution-graph.d.ts.map +1 -0
- package/dist/runtime/execution-graph.js +441 -0
- package/dist/runtime/execution-graph.js.map +1 -0
- package/dist/runtime/executor.d.ts +7 -1
- package/dist/runtime/executor.d.ts.map +1 -1
- package/dist/runtime/executor.js +20 -0
- package/dist/runtime/executor.js.map +1 -1
- package/dist/runtime/graph-adversarial.d.ts +88 -0
- package/dist/runtime/graph-adversarial.d.ts.map +1 -0
- package/dist/runtime/graph-adversarial.js +378 -0
- package/dist/runtime/graph-adversarial.js.map +1 -0
- package/dist/runtime/graph-analyzer.d.ts +106 -0
- package/dist/runtime/graph-analyzer.d.ts.map +1 -0
- package/dist/runtime/graph-analyzer.js +321 -0
- package/dist/runtime/graph-analyzer.js.map +1 -0
- package/dist/runtime/graph-causal.d.ts +91 -0
- package/dist/runtime/graph-causal.d.ts.map +1 -0
- package/dist/runtime/graph-causal.js +292 -0
- package/dist/runtime/graph-causal.js.map +1 -0
- package/dist/runtime/graph-context-router.d.ts +73 -0
- package/dist/runtime/graph-context-router.d.ts.map +1 -0
- package/dist/runtime/graph-context-router.js +162 -0
- package/dist/runtime/graph-context-router.js.map +1 -0
- package/dist/runtime/graph-discovery.d.ts +71 -0
- package/dist/runtime/graph-discovery.d.ts.map +1 -0
- package/dist/runtime/graph-discovery.js +364 -0
- package/dist/runtime/graph-discovery.js.map +1 -0
- package/dist/runtime/graph-dropout.d.ts +59 -0
- package/dist/runtime/graph-dropout.d.ts.map +1 -0
- package/dist/runtime/graph-dropout.js +204 -0
- package/dist/runtime/graph-dropout.js.map +1 -0
- package/dist/runtime/graph-embeddings.d.ts +58 -0
- package/dist/runtime/graph-embeddings.d.ts.map +1 -0
- package/dist/runtime/graph-embeddings.js +299 -0
- package/dist/runtime/graph-embeddings.js.map +1 -0
- package/dist/runtime/graph-feedback.d.ts +30 -0
- package/dist/runtime/graph-feedback.d.ts.map +1 -0
- package/dist/runtime/graph-feedback.js +80 -0
- package/dist/runtime/graph-feedback.js.map +1 -0
- package/dist/runtime/graph-gnn.d.ts +120 -0
- package/dist/runtime/graph-gnn.d.ts.map +1 -0
- package/dist/runtime/graph-gnn.js +524 -0
- package/dist/runtime/graph-gnn.js.map +1 -0
- package/dist/runtime/graph-learner.d.ts +70 -0
- package/dist/runtime/graph-learner.d.ts.map +1 -0
- package/dist/runtime/graph-learner.js +265 -0
- package/dist/runtime/graph-learner.js.map +1 -0
- package/dist/runtime/graph-meta-adversarial.d.ts +113 -0
- package/dist/runtime/graph-meta-adversarial.d.ts.map +1 -0
- package/dist/runtime/graph-meta-adversarial.js +366 -0
- package/dist/runtime/graph-meta-adversarial.js.map +1 -0
- package/dist/runtime/graph-meta.d.ts +115 -0
- package/dist/runtime/graph-meta.d.ts.map +1 -0
- package/dist/runtime/graph-meta.js +465 -0
- package/dist/runtime/graph-meta.js.map +1 -0
- package/dist/runtime/graph-self-evolve.d.ts +92 -0
- package/dist/runtime/graph-self-evolve.d.ts.map +1 -0
- package/dist/runtime/graph-self-evolve.js +422 -0
- package/dist/runtime/graph-self-evolve.js.map +1 -0
- package/dist/runtime/graph-synthesis.d.ts +47 -0
- package/dist/runtime/graph-synthesis.d.ts.map +1 -0
- package/dist/runtime/graph-synthesis.js +232 -0
- package/dist/runtime/graph-synthesis.js.map +1 -0
- package/dist/runtime/graph-trajectory.d.ts +88 -0
- package/dist/runtime/graph-trajectory.d.ts.map +1 -0
- package/dist/runtime/graph-trajectory.js +334 -0
- package/dist/runtime/graph-trajectory.js.map +1 -0
- package/dist/runtime/learning-engine.d.ts +12 -0
- package/dist/runtime/learning-engine.d.ts.map +1 -1
- package/dist/runtime/learning-engine.js +70 -0
- package/dist/runtime/learning-engine.js.map +1 -1
- package/dist/runtime/prompt-compressor.d.ts +16 -0
- package/dist/runtime/prompt-compressor.d.ts.map +1 -0
- package/dist/runtime/prompt-compressor.js +68 -0
- package/dist/runtime/prompt-compressor.js.map +1 -0
- package/dist/runtime/repo-map.d.ts +40 -0
- package/dist/runtime/repo-map.d.ts.map +1 -0
- package/dist/runtime/repo-map.js +358 -0
- package/dist/runtime/repo-map.js.map +1 -0
- package/dist/runtime/sdk-mcp-server.d.ts +44 -0
- package/dist/runtime/sdk-mcp-server.d.ts.map +1 -0
- package/dist/runtime/sdk-mcp-server.js +133 -0
- package/dist/runtime/sdk-mcp-server.js.map +1 -0
- package/dist/runtime/structured-handoff.d.ts +41 -0
- package/dist/runtime/structured-handoff.d.ts.map +1 -0
- package/dist/runtime/structured-handoff.js +279 -0
- package/dist/runtime/structured-handoff.js.map +1 -0
- package/dist/runtime/token-analytics.d.ts +38 -0
- package/dist/runtime/token-analytics.d.ts.map +1 -0
- package/dist/runtime/token-analytics.js +59 -0
- package/dist/runtime/token-analytics.js.map +1 -0
- package/dist/runtime/verifier.d.ts +10 -0
- package/dist/runtime/verifier.d.ts.map +1 -1
- package/dist/runtime/verifier.js +97 -1
- package/dist/runtime/verifier.js.map +1 -1
- package/package.json +2 -2
- package/skills/swarm-output-style/SKILL.md +71 -33
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
// ─── Engine ──────────────────────────────────────────────────────────
|
|
2
|
+
/**
|
|
3
|
+
* Analyzes historical execution traces to propose improved replanning rules,
|
|
4
|
+
* backtests them against historical data, and evolves scoring weights based
|
|
5
|
+
* on user feedback.
|
|
6
|
+
*
|
|
7
|
+
* Rules are persisted as 'heuristic' nodes in the execution graph with id
|
|
8
|
+
* prefix 'rule:'. Feedback adjusts confidence: accepted → +0.1, rejected → -0.15.
|
|
9
|
+
*/
|
|
10
|
+
export class RuleEvolver {
|
|
11
|
+
graph;
|
|
12
|
+
constructor(graph) {
|
|
13
|
+
this.graph = graph;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Analyze historical orchestration traces and propose new replanning rules.
|
|
17
|
+
*
|
|
18
|
+
* 1. Extract features from all orchestrations via BFS.
|
|
19
|
+
* 2. Find patterns in failures: low-confidence phases, high token usage, blockers.
|
|
20
|
+
* 3. Generate candidate rules from observed failure patterns.
|
|
21
|
+
* 4. Backtest each candidate against all historical traces.
|
|
22
|
+
* 5. Return proposals sorted by improvement, filtered by confidence > 0.3.
|
|
23
|
+
*/
|
|
24
|
+
evolveRules(traceCount) {
|
|
25
|
+
const features = this.extractFeatures(traceCount);
|
|
26
|
+
if (features.length === 0)
|
|
27
|
+
return [];
|
|
28
|
+
const candidates = this.generateCandidateRules(features);
|
|
29
|
+
const proposals = [];
|
|
30
|
+
for (const rule of candidates) {
|
|
31
|
+
const result = this.backtestRule(rule);
|
|
32
|
+
if (result.appliedCount === 0)
|
|
33
|
+
continue;
|
|
34
|
+
const confidence = result.appliedCount >= 5 ? 0.7 : result.appliedCount >= 3 ? 0.5 : 0.3;
|
|
35
|
+
if (confidence < 0.3)
|
|
36
|
+
continue;
|
|
37
|
+
proposals.push({
|
|
38
|
+
rule,
|
|
39
|
+
backtestedImprovement: result.improvement,
|
|
40
|
+
confidence,
|
|
41
|
+
evidence: this.formatEvidence(rule, result),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return proposals
|
|
45
|
+
.filter((p) => p.confidence >= 0.3)
|
|
46
|
+
.sort((a, b) => b.backtestedImprovement - a.backtestedImprovement);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Backtest a single rule against all historical orchestrations.
|
|
50
|
+
*
|
|
51
|
+
* For each orchestration, extracts phase features via BFS. If the rule
|
|
52
|
+
* condition matches any phase, simulates the action:
|
|
53
|
+
* - upgradeModel on failed orch → wouldHaveHelped (optimistic)
|
|
54
|
+
* - upgradeModel on successful orch → wouldHaveHurt (false positive)
|
|
55
|
+
* - skipPhase on failed orch → wouldHaveHelped (conservative: saves tokens)
|
|
56
|
+
* - downgradeModel on successful orch → wouldHaveHelped (saves cost)
|
|
57
|
+
* - downgradeModel on failed orch → wouldHaveHurt
|
|
58
|
+
*/
|
|
59
|
+
backtestRule(rule) {
|
|
60
|
+
const features = this.extractFeatures();
|
|
61
|
+
let appliedCount = 0;
|
|
62
|
+
let wouldHaveHelped = 0;
|
|
63
|
+
let wouldHaveHurt = 0;
|
|
64
|
+
for (const orch of features) {
|
|
65
|
+
const matches = this.ruleMatchesOrchestration(rule, orch);
|
|
66
|
+
if (!matches)
|
|
67
|
+
continue;
|
|
68
|
+
appliedCount++;
|
|
69
|
+
const orchFailed = orch.status === 'failed';
|
|
70
|
+
if (rule.action.upgradeModel) {
|
|
71
|
+
// Optimistic: upgrading on failed → helped, upgrading on success → hurt (wasted cost)
|
|
72
|
+
if (orchFailed)
|
|
73
|
+
wouldHaveHelped++;
|
|
74
|
+
else
|
|
75
|
+
wouldHaveHurt++;
|
|
76
|
+
}
|
|
77
|
+
else if (rule.action.downgradeModel) {
|
|
78
|
+
// Conservative: downgrading on success → helped (saved cost), downgrading on failed → hurt
|
|
79
|
+
if (!orchFailed)
|
|
80
|
+
wouldHaveHelped++;
|
|
81
|
+
else
|
|
82
|
+
wouldHaveHurt++;
|
|
83
|
+
}
|
|
84
|
+
else if (rule.action.skipPhase) {
|
|
85
|
+
// Conservative: skipping on success → helped (saved tokens), skipping on failed → neutral
|
|
86
|
+
if (!orchFailed)
|
|
87
|
+
wouldHaveHelped++;
|
|
88
|
+
// Failed orchestrations: skipping is neutral, not counted as hurt
|
|
89
|
+
}
|
|
90
|
+
else if (rule.action.addPhase) {
|
|
91
|
+
// Optimistic: adding a phase on failed → helped, adding on success → hurt (wasted tokens)
|
|
92
|
+
if (orchFailed)
|
|
93
|
+
wouldHaveHelped++;
|
|
94
|
+
else
|
|
95
|
+
wouldHaveHurt++;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const improvement = appliedCount > 0 ? (wouldHaveHelped - wouldHaveHurt) / appliedCount : 0;
|
|
99
|
+
const falsePositiveRate = appliedCount > 0 ? wouldHaveHurt / appliedCount : 0;
|
|
100
|
+
return { improvement, appliedCount, wouldHaveHelped, wouldHaveHurt, falsePositiveRate };
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Record user accept/reject of a rule proposal.
|
|
104
|
+
* Accepted → confidence +0.1 (capped at 1.0)
|
|
105
|
+
* Rejected → confidence -0.15 (floored at 0.0)
|
|
106
|
+
*/
|
|
107
|
+
recordFeedback(ruleId, accepted) {
|
|
108
|
+
const existing = this.graph.getNode(ruleId);
|
|
109
|
+
if (!existing)
|
|
110
|
+
return;
|
|
111
|
+
const props = existing.properties;
|
|
112
|
+
const currentConfidence = props.confidence ?? 0.5;
|
|
113
|
+
const delta = accepted ? 0.1 : -0.15;
|
|
114
|
+
const newConfidence = Math.max(0, Math.min(1, currentConfidence + delta));
|
|
115
|
+
this.graph.addNode({
|
|
116
|
+
id: ruleId,
|
|
117
|
+
type: 'heuristic',
|
|
118
|
+
label: existing.label,
|
|
119
|
+
properties: {
|
|
120
|
+
...props,
|
|
121
|
+
confidence: newConfidence,
|
|
122
|
+
lastFeedback: accepted ? 'accepted' : 'rejected',
|
|
123
|
+
feedbackCount: (props.feedbackCount ?? 0) + 1,
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Get all evolved rules currently stored in the graph.
|
|
129
|
+
* Loads heuristic nodes with id prefix 'rule:' and deserializes them.
|
|
130
|
+
*/
|
|
131
|
+
getActiveRules() {
|
|
132
|
+
return this.loadRules();
|
|
133
|
+
}
|
|
134
|
+
// ─── Feature Extraction ─────────────────────────────────────────
|
|
135
|
+
extractFeatures(traceCount) {
|
|
136
|
+
let orchNodes = this.graph.getNodesByType('orchestration');
|
|
137
|
+
if (traceCount !== undefined && traceCount > 0) {
|
|
138
|
+
orchNodes = orchNodes.slice(-traceCount);
|
|
139
|
+
}
|
|
140
|
+
const results = [];
|
|
141
|
+
for (const orch of orchNodes) {
|
|
142
|
+
const { nodes } = this.graph.bfs(orch.id, 3);
|
|
143
|
+
const phaseNodes = nodes.filter((n) => n.type === 'phase');
|
|
144
|
+
const agentNodes = nodes.filter((n) => n.type === 'agent');
|
|
145
|
+
const phases = [];
|
|
146
|
+
for (const phase of phaseNodes) {
|
|
147
|
+
// Find agents belonging to this phase via spawned edges
|
|
148
|
+
const phaseEdges = this.graph.getEdges(phase.id, 'outgoing');
|
|
149
|
+
const phaseAgentIds = new Set(phaseEdges.filter((e) => e.type === 'spawned').map((e) => e.target));
|
|
150
|
+
const phaseAgents = agentNodes.filter((a) => phaseAgentIds.has(a.id));
|
|
151
|
+
const confidence = this.inferPhaseConfidence(phaseAgents);
|
|
152
|
+
const totalTokens = this.inferPhaseTokens(phase);
|
|
153
|
+
const status = phase.properties.status ?? 'unknown';
|
|
154
|
+
const hasBlockers = phaseAgents.some((a) => a.properties.status === 'error' || a.properties.status === 'timeout');
|
|
155
|
+
phases.push({
|
|
156
|
+
phaseId: phase.id,
|
|
157
|
+
label: phase.label,
|
|
158
|
+
kind: this.inferPhaseKind(phase.label),
|
|
159
|
+
agentCount: phaseAgents.length || phase.properties.agentCount || 0,
|
|
160
|
+
confidence,
|
|
161
|
+
totalTokens,
|
|
162
|
+
status,
|
|
163
|
+
hasBlockers,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
results.push({
|
|
167
|
+
orchId: orch.id,
|
|
168
|
+
status: orch.properties.status ?? 'unknown',
|
|
169
|
+
pattern: orch.properties.pattern ?? 'unknown',
|
|
170
|
+
phases,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
return results;
|
|
174
|
+
}
|
|
175
|
+
inferPhaseConfidence(agents) {
|
|
176
|
+
if (agents.length === 0)
|
|
177
|
+
return 'medium';
|
|
178
|
+
const hasError = agents.some((a) => a.properties.status === 'error' || a.properties.status === 'timeout');
|
|
179
|
+
if (hasError)
|
|
180
|
+
return 'low';
|
|
181
|
+
const allIdle = agents.every((a) => a.properties.status === 'idle');
|
|
182
|
+
if (allIdle)
|
|
183
|
+
return 'high';
|
|
184
|
+
return 'medium';
|
|
185
|
+
}
|
|
186
|
+
inferPhaseTokens(phase) {
|
|
187
|
+
const usage = phase.properties.usage;
|
|
188
|
+
return usage?.totalTokens ?? 0;
|
|
189
|
+
}
|
|
190
|
+
inferPhaseKind(label) {
|
|
191
|
+
const lower = label.toLowerCase();
|
|
192
|
+
if (lower.includes('research') || lower.includes('explore'))
|
|
193
|
+
return 'research';
|
|
194
|
+
if (lower.includes('implement') || lower.includes('build') || lower.includes('code'))
|
|
195
|
+
return 'implement';
|
|
196
|
+
if (lower.includes('review') || lower.includes('check'))
|
|
197
|
+
return 'review';
|
|
198
|
+
if (lower.includes('test') || lower.includes('verify'))
|
|
199
|
+
return 'test';
|
|
200
|
+
if (lower.includes('challenge') || lower.includes('adversar'))
|
|
201
|
+
return 'challenge';
|
|
202
|
+
if (lower.includes('integrate') || lower.includes('merge'))
|
|
203
|
+
return 'integrate';
|
|
204
|
+
return label;
|
|
205
|
+
}
|
|
206
|
+
// ─── Rule Generation ────────────────────────────────────────────
|
|
207
|
+
generateCandidateRules(features) {
|
|
208
|
+
const candidates = [];
|
|
209
|
+
const failed = features.filter((f) => f.status === 'failed');
|
|
210
|
+
const succeeded = features.filter((f) => f.status === 'completed');
|
|
211
|
+
// Pattern 1: Low-confidence phases in failures → upgrade model
|
|
212
|
+
const failedWithLowConf = failed.filter((f) => f.phases.some((p) => p.confidence === 'low'));
|
|
213
|
+
if (failedWithLowConf.length >= 2) {
|
|
214
|
+
// Find which phase kinds are most commonly low-confidence in failures
|
|
215
|
+
const kindCounts = new Map();
|
|
216
|
+
for (const f of failedWithLowConf) {
|
|
217
|
+
for (const p of f.phases) {
|
|
218
|
+
if (p.confidence === 'low') {
|
|
219
|
+
kindCounts.set(p.kind, (kindCounts.get(p.kind) ?? 0) + 1);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
for (const [kind, count] of kindCounts) {
|
|
224
|
+
if (count >= 2) {
|
|
225
|
+
candidates.push({
|
|
226
|
+
id: `rule:upgrade-on-low-conf-${kind}`,
|
|
227
|
+
name: `Upgrade model on low confidence (${kind})`,
|
|
228
|
+
description: `When a ${kind} phase has low confidence, upgrade the model for remaining phases`,
|
|
229
|
+
condition: { phaseKind: kind, confidenceBelow: 0.4 },
|
|
230
|
+
action: { upgradeModel: true },
|
|
231
|
+
confidence: 0.5,
|
|
232
|
+
evidenceCount: count,
|
|
233
|
+
successRate: 0,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
// Also add a generic low-confidence rule if enough evidence
|
|
238
|
+
if (failedWithLowConf.length >= 3) {
|
|
239
|
+
candidates.push({
|
|
240
|
+
id: 'rule:upgrade-on-low-conf',
|
|
241
|
+
name: 'Upgrade model on low confidence',
|
|
242
|
+
description: 'When any phase has low confidence, upgrade the model for remaining phases',
|
|
243
|
+
condition: { confidenceBelow: 0.4 },
|
|
244
|
+
action: { upgradeModel: true },
|
|
245
|
+
confidence: 0.5,
|
|
246
|
+
evidenceCount: failedWithLowConf.length,
|
|
247
|
+
successRate: 0,
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
// Pattern 2: Phases with blockers in failures → upgrade model
|
|
252
|
+
const failedWithBlockers = failed.filter((f) => f.phases.some((p) => p.hasBlockers));
|
|
253
|
+
if (failedWithBlockers.length >= 2) {
|
|
254
|
+
candidates.push({
|
|
255
|
+
id: 'rule:upgrade-on-blockers',
|
|
256
|
+
name: 'Upgrade model when blockers detected',
|
|
257
|
+
description: 'When a phase encounters blockers, upgrade the model for remaining phases',
|
|
258
|
+
condition: { hasBlockers: true },
|
|
259
|
+
action: { upgradeModel: true },
|
|
260
|
+
confidence: 0.5,
|
|
261
|
+
evidenceCount: failedWithBlockers.length,
|
|
262
|
+
successRate: 0,
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
// Pattern 3: High-confidence phases in successes → downgrade model (cost saving)
|
|
266
|
+
const succeededWithHighConf = succeeded.filter((f) => f.phases.every((p) => p.confidence === 'high'));
|
|
267
|
+
if (succeededWithHighConf.length >= 3) {
|
|
268
|
+
candidates.push({
|
|
269
|
+
id: 'rule:downgrade-on-high-conf',
|
|
270
|
+
name: 'Downgrade model on high confidence',
|
|
271
|
+
description: 'When all phases have high confidence, downgrade to save cost',
|
|
272
|
+
condition: { confidenceAbove: 0.8 },
|
|
273
|
+
action: { downgradeModel: true },
|
|
274
|
+
confidence: 0.5,
|
|
275
|
+
evidenceCount: succeededWithHighConf.length,
|
|
276
|
+
successRate: 0,
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
// Pattern 4: High token usage in failures → downgrade to save budget
|
|
280
|
+
const avgTokensSucceeded = this.averageTokens(succeeded);
|
|
281
|
+
if (avgTokensSucceeded > 0) {
|
|
282
|
+
const failedHighTokens = failed.filter((f) => {
|
|
283
|
+
const total = f.phases.reduce((s, p) => s + p.totalTokens, 0);
|
|
284
|
+
return total > avgTokensSucceeded * 2;
|
|
285
|
+
});
|
|
286
|
+
if (failedHighTokens.length >= 2) {
|
|
287
|
+
candidates.push({
|
|
288
|
+
id: 'rule:downgrade-on-high-tokens',
|
|
289
|
+
name: 'Downgrade model on high token usage',
|
|
290
|
+
description: 'When token usage exceeds 2x historical average, downgrade to save budget',
|
|
291
|
+
condition: { tokenRatioAbove: 2.0 },
|
|
292
|
+
action: { downgradeModel: true },
|
|
293
|
+
confidence: 0.4,
|
|
294
|
+
evidenceCount: failedHighTokens.length,
|
|
295
|
+
successRate: 0,
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
// Pattern 5: Budget exhaustion in failures → downgrade when budget low
|
|
300
|
+
// (Only generate if we see phases with usage data)
|
|
301
|
+
const failedLowBudget = failed.filter((f) => f.phases.some((p) => p.totalTokens > 0));
|
|
302
|
+
if (failedLowBudget.length >= 2) {
|
|
303
|
+
candidates.push({
|
|
304
|
+
id: 'rule:downgrade-on-low-budget',
|
|
305
|
+
name: 'Downgrade model when budget is low',
|
|
306
|
+
description: 'When remaining budget drops below 30%, downgrade models to stretch budget',
|
|
307
|
+
condition: { budgetRemainingBelow: 0.3 },
|
|
308
|
+
action: { downgradeModel: true },
|
|
309
|
+
confidence: 0.4,
|
|
310
|
+
evidenceCount: failedLowBudget.length,
|
|
311
|
+
successRate: 0,
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
// Pattern 6: Skip challenge phases in simple successful tasks
|
|
315
|
+
const simpleSuccesses = succeeded.filter((f) => f.phases.length <= 3 && f.phases.every((p) => p.confidence === 'high'));
|
|
316
|
+
if (simpleSuccesses.length >= 3) {
|
|
317
|
+
candidates.push({
|
|
318
|
+
id: 'rule:skip-challenge-on-simple',
|
|
319
|
+
name: 'Skip challenge phase on simple tasks',
|
|
320
|
+
description: 'When task is simple (high confidence, few phases), skip adversarial challenge',
|
|
321
|
+
condition: { phaseKind: 'challenge', confidenceAbove: 0.8 },
|
|
322
|
+
action: { skipPhase: true },
|
|
323
|
+
confidence: 0.4,
|
|
324
|
+
evidenceCount: simpleSuccesses.length,
|
|
325
|
+
successRate: 0,
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
return candidates;
|
|
329
|
+
}
|
|
330
|
+
averageTokens(features) {
|
|
331
|
+
if (features.length === 0)
|
|
332
|
+
return 0;
|
|
333
|
+
const total = features.reduce((s, f) => s + f.phases.reduce((ps, p) => ps + p.totalTokens, 0), 0);
|
|
334
|
+
return total / features.length;
|
|
335
|
+
}
|
|
336
|
+
// ─── Rule Matching ──────────────────────────────────────────────
|
|
337
|
+
ruleMatchesOrchestration(rule, orch) {
|
|
338
|
+
const { condition } = rule;
|
|
339
|
+
for (const phase of orch.phases) {
|
|
340
|
+
let matches = true;
|
|
341
|
+
if (condition.phaseKind !== undefined && phase.kind !== condition.phaseKind) {
|
|
342
|
+
matches = false;
|
|
343
|
+
}
|
|
344
|
+
if (condition.confidenceBelow !== undefined) {
|
|
345
|
+
const confValue = phase.confidence === 'low' ? 0.3 : phase.confidence === 'medium' ? 0.6 : 0.9;
|
|
346
|
+
if (confValue >= condition.confidenceBelow)
|
|
347
|
+
matches = false;
|
|
348
|
+
}
|
|
349
|
+
if (condition.confidenceAbove !== undefined) {
|
|
350
|
+
const confValue = phase.confidence === 'low' ? 0.3 : phase.confidence === 'medium' ? 0.6 : 0.9;
|
|
351
|
+
if (confValue <= condition.confidenceAbove)
|
|
352
|
+
matches = false;
|
|
353
|
+
}
|
|
354
|
+
if (condition.hasBlockers !== undefined && phase.hasBlockers !== condition.hasBlockers) {
|
|
355
|
+
matches = false;
|
|
356
|
+
}
|
|
357
|
+
// tokenRatioAbove: match if this orch's total tokens exceed the ratio × average
|
|
358
|
+
// We can't compute average here per-rule, so we check the ratio against phase tokens
|
|
359
|
+
// This is a simplified check — backtesting handles the full logic
|
|
360
|
+
if (condition.tokenRatioAbove !== undefined) {
|
|
361
|
+
// We'd need historical average; skip this condition in simple matching
|
|
362
|
+
// The rule still matches based on other conditions
|
|
363
|
+
if (Object.keys(condition).length === 1)
|
|
364
|
+
matches = false; // only tokenRatio, can't match
|
|
365
|
+
}
|
|
366
|
+
if (condition.budgetRemainingBelow !== undefined) {
|
|
367
|
+
// Budget information isn't available at phase level in the graph
|
|
368
|
+
// Skip this condition in simple matching
|
|
369
|
+
if (Object.keys(condition).length === 1)
|
|
370
|
+
matches = false;
|
|
371
|
+
}
|
|
372
|
+
if (matches)
|
|
373
|
+
return true;
|
|
374
|
+
}
|
|
375
|
+
return false;
|
|
376
|
+
}
|
|
377
|
+
// ─── Persistence ────────────────────────────────────────────────
|
|
378
|
+
saveRule(rule) {
|
|
379
|
+
this.graph.addNode({
|
|
380
|
+
id: rule.id,
|
|
381
|
+
type: 'heuristic',
|
|
382
|
+
label: rule.name,
|
|
383
|
+
properties: {
|
|
384
|
+
description: rule.description,
|
|
385
|
+
condition: rule.condition,
|
|
386
|
+
action: rule.action,
|
|
387
|
+
confidence: rule.confidence,
|
|
388
|
+
evidenceCount: rule.evidenceCount,
|
|
389
|
+
successRate: rule.successRate,
|
|
390
|
+
},
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
loadRules() {
|
|
394
|
+
const nodes = this.graph.getNodesByType('heuristic');
|
|
395
|
+
const rules = [];
|
|
396
|
+
for (const node of nodes) {
|
|
397
|
+
if (!node.id.startsWith('rule:'))
|
|
398
|
+
continue;
|
|
399
|
+
const props = node.properties;
|
|
400
|
+
rules.push({
|
|
401
|
+
id: node.id,
|
|
402
|
+
name: node.label,
|
|
403
|
+
description: props.description ?? '',
|
|
404
|
+
condition: props.condition ?? {},
|
|
405
|
+
action: props.action ?? {},
|
|
406
|
+
confidence: props.confidence ?? 0.5,
|
|
407
|
+
evidenceCount: props.evidenceCount ?? 0,
|
|
408
|
+
successRate: props.successRate ?? 0,
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
return rules;
|
|
412
|
+
}
|
|
413
|
+
// ─── Helpers ────────────────────────────────────────────────────
|
|
414
|
+
formatEvidence(rule, result) {
|
|
415
|
+
const pct = Math.round(result.improvement * 100);
|
|
416
|
+
const sign = pct >= 0 ? '+' : '';
|
|
417
|
+
return (`${rule.name}: ${sign}${pct}% improvement across ${result.appliedCount} historical traces ` +
|
|
418
|
+
`(helped ${result.wouldHaveHelped}, hurt ${result.wouldHaveHurt}, ` +
|
|
419
|
+
`false positive rate ${Math.round(result.falsePositiveRate * 100)}%)`);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
//# sourceMappingURL=graph-self-evolve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-self-evolve.js","sourceRoot":"","sources":["../../src/runtime/graph-self-evolve.ts"],"names":[],"mappings":"AA+DA,wEAAwE;AAExE;;;;;;;GAOG;AACH,MAAM,OAAO,WAAW;IACF;IAApB,YAAoB,KAAq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AC,IAAiB,EAAE,MAAsB;QAC9D,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,GAAG,GAAG,CAAC,CAAC;QACjD,MAAM,IAAI,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QACjC,OAAO,CACL,GAAG,IAAI,CAAC,IAAI,KAAK,IAAI,GAAG,GAAG,wBAAwB,MAAM,CAAC,YAAY,qBAAqB;YAC3F,WAAW,MAAM,CAAC,eAAe,UAAU,MAAM,CAAC,aAAa,IAAI;YACnE,uBAAuB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,iBAAiB,GAAG,GAAG,CAAC,IAAI,CACtE,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { ExecutionGraph } from './execution-graph.js';
|
|
2
|
+
export interface TopologyInsight {
|
|
3
|
+
feature: string;
|
|
4
|
+
successCorrelation: number;
|
|
5
|
+
sampleSize: number;
|
|
6
|
+
confidence: 'low' | 'medium' | 'high';
|
|
7
|
+
}
|
|
8
|
+
export interface SynthesizedPattern {
|
|
9
|
+
name: string;
|
|
10
|
+
phases: PhaseSpec[];
|
|
11
|
+
confidence: number;
|
|
12
|
+
reasoning: string;
|
|
13
|
+
basedOn: string[];
|
|
14
|
+
}
|
|
15
|
+
export interface PhaseSpec {
|
|
16
|
+
name: string;
|
|
17
|
+
kind: string;
|
|
18
|
+
agentTypes: string[];
|
|
19
|
+
parallel: boolean;
|
|
20
|
+
dependsOn?: string[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Analyzes structural diffs between successful and failed orchestration
|
|
24
|
+
* topologies, then generates novel pattern DAGs based on the insights.
|
|
25
|
+
*/
|
|
26
|
+
export declare class PatternSynthesizer {
|
|
27
|
+
private graph;
|
|
28
|
+
constructor(graph: ExecutionGraph);
|
|
29
|
+
/**
|
|
30
|
+
* Analyze what structural features correlate with success/failure.
|
|
31
|
+
* Splits orchestrations by status, extracts topology features via BFS,
|
|
32
|
+
* then computes success rate deltas per feature.
|
|
33
|
+
*/
|
|
34
|
+
analyzeTopologyDiffs(minSamples?: number): TopologyInsight[];
|
|
35
|
+
/**
|
|
36
|
+
* Generate a novel pattern from topology insights.
|
|
37
|
+
* Starts with a base structure (research → implement → review), then
|
|
38
|
+
* applies positive insights as additions and negative insights as removals.
|
|
39
|
+
*/
|
|
40
|
+
synthesizePattern(taskDescription: string, filePatterns?: string[]): SynthesizedPattern | null;
|
|
41
|
+
/**
|
|
42
|
+
* Extract topology features from a single orchestration via BFS (depth 3).
|
|
43
|
+
* Returns a map of boolean features describing the orchestration's structure.
|
|
44
|
+
*/
|
|
45
|
+
extractTopologyFeatures(orchestrationId: string): Map<string, boolean>;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=graph-synthesis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-synthesis.d.ts","sourceRoot":"","sources":["../../src/runtime/graph-synthesis.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAK3D,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;CACvC;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,SAAS,EAAE,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAID;;;GAGG;AACH,qBAAa,kBAAkB;IACjB,OAAO,CAAC,KAAK;gBAAL,KAAK,EAAE,cAAc;IAEzC;;;;OAIG;IACH,oBAAoB,CAAC,UAAU,SAAI,GAAG,eAAe,EAAE;IAmEvD;;;;OAIG;IACH,iBAAiB,CAAC,eAAe,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,EAAE,GAAG,kBAAkB,GAAG,IAAI;IAiH9F;;;OAGG;IACH,uBAAuB,CAAC,eAAe,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;CAmEvE"}
|