Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated

fix: F7 coordination_orchestrate honesty + F11 neural_predict classifier

Reuven565681fff871
diff --git a/v3/@claude-flow/cli/src/mcp-tools/coordination-tools.ts b/v3/@claude-flow/cli/src/mcp-tools/coordination-tools.ts
index e07a94e466..ff69bc551a 100644
--- a/v3/@claude-flow/cli/src/mcp-tools/coordination-tools.ts
+++ b/v3/@claude-flow/cli/src/mcp-tools/coordination-tools.ts
@@ -724,15 +724,44 @@ export const coordinationTools: MCPTool[] = [
const orchestrationId = `orch-${Date.now()}`;
+ // ADR-093 F7: this tool only schedules an orchestration record — it
+ // does not actually execute. Previously it returned a hardcoded
+ // `estimatedCompletion: "50ms"` which was misleading. Now we return
+ // an honest stub-status with a note pointing callers at agent_spawn
+ // / Task tool / hive-mind tools for real orchestration. Persist the
+ // record so callers can list/inspect what was scheduled.
+ const orchestration = {
+ id: orchestrationId,
+ task,
+ strategy,
+ agents,
+ status: 'scheduled' as const,
+ scheduledAt: new Date().toISOString(),
+ topology: store.topology.type,
+ };
+ // Best-effort persist — keep last 100 scheduled orchestrations.
+ type CoordStoreShape = ReturnType<typeof loadCoordStore> & {
+ orchestrations?: Array<typeof orchestration>;
+ };
+ const orchStore = store as CoordStoreShape;
+ if (!Array.isArray(orchStore.orchestrations)) orchStore.orchestrations = [];
+ orchStore.orchestrations.push(orchestration);
+ if (orchStore.orchestrations.length > 100) {
+ orchStore.orchestrations = orchStore.orchestrations.slice(-100);
+ }
+ saveCoordStore(orchStore);
+
return {
success: true,
orchestrationId,
task,
strategy,
agents,
- status: 'initiated',
+ status: 'scheduled',
topology: store.topology.type,
- estimatedCompletion: `${agents.length * (strategy === 'sequential' ? 100 : 50)}ms`,
+ // Honest stub: no executor wired up yet. Don't lie about completion time.
+ executor: 'none',
+ _note: 'coordination_orchestrate currently records the orchestration request but does not execute it. For real multi-agent execution use agent_spawn + the Task tool, or hive-mind_spawn for queen-led coordination.',
};
},
},
diff --git a/v3/@claude-flow/cli/src/mcp-tools/neural-tools.ts b/v3/@claude-flow/cli/src/mcp-tools/neural-tools.ts
index 5067b9e829..cefadc7448 100644
--- a/v3/@claude-flow/cli/src/mcp-tools/neural-tools.ts
+++ b/v3/@claude-flow/cli/src/mcp-tools/neural-tools.ts
@@ -260,10 +260,34 @@ export const neuralTools: MCPTool[] = [
const embedding = await generateEmbedding(text, 384);
const patternId = `${modelId}-train-${i}`;
+ // ADR-093 F11: extract a meaningful label instead of dumping raw
+ // training JSON as the pattern name. Audit reported neural_predict
+ // returned `label: <raw training data JSON>` because the previous
+ // fallback was `text.slice(0, 100)` where text was `JSON.stringify(entry)`.
+ let label: string;
+ if (typeof entry === 'string') {
+ label = entry.slice(0, 80);
+ } else if (entry && typeof entry === 'object') {
+ const e = entry as Record<string, unknown>;
+ // Prefer common semantic fields over a JSON dump
+ const labelField = e.label ?? e.category ?? e.class ?? e.tag ?? e.intent ?? e.name ?? e.title;
+ if (typeof labelField === 'string' && labelField.length > 0) {
+ label = labelField.slice(0, 80);
+ } else {
+ const summaryField = e.text ?? e.input ?? e.task ?? e.description ?? e.content;
+ if (typeof summaryField === 'string' && summaryField.length > 0) {
+ label = `${summaryField.slice(0, 60)}${summaryField.length > 60 ? '…' : ''}`;
+ } else {
+ // Last resort: reduce to a stable short hash-like id
+ label = `${modelType}:entry-${i}`;
+ }
+ }
+ } else {
+ label = `${modelType}:entry-${i}`;
+ }
store.patterns[patternId] = {
id: patternId,
- name: typeof entry === 'object' && entry !== null && 'label' in entry
- ? String((entry as Record<string, unknown>).label) : text.slice(0, 100),
+ name: label,
type: modelType,
embedding,
metadata: { modelId, epoch: epochs, index: i, raw: entry },
@@ -331,37 +355,70 @@ export const neuralTools: MCPTool[] = [
const embedding = await generateEmbedding(inputText, 384);
const latency = Math.round(performance.now() - startTime);
- // Search stored patterns via real cosine similarity
+ // ADR-093 F11: real classifier head over stored patterns. Previously
+ // confidence was the raw cosine similarity (often clamped to 0 when
+ // stored embeddings were stale or zero-vectored). Now we run k-NN
+ // with cosine distance and apply a temperature-controlled softmax
+ // over the top-K so confidence is a proper distribution that sums
+ // to 1, and we surface enough metadata to trust the result.
const storedPatterns = Object.values(store.patterns);
- let predictions;
+ let predictions: Array<{ label: string; confidence: number; patternId: string; cosineSimilarity: number }>;
if (storedPatterns.length > 0) {
- // Real nearest-neighbor prediction using stored pattern embeddings
- predictions = storedPatterns
- .map(p => ({
- label: p.name || p.type || p.id,
- confidence: Math.max(0, cosineSimilarity(embedding, p.embedding)),
- patternId: p.id,
- }))
- .sort((a, b) => b.confidence - a.confidence)
+ // Step 1: k-NN with cosine
+ const scored = storedPatterns
+ .map(p => {
+ const sim = cosineSimilarity(embedding, p.embedding);
+ return {
+ patternId: p.id,
+ label: p.name || p.type || p.id,
+ cosineSimilarity: sim,
+ };
+ })
+ .sort((a, b) => b.cosineSimilarity - a.cosineSimilarity)
.slice(0, topK);
+
+ // Step 2: temperature-softmax over the top-K so confidence sums to 1.
+ // Temperature 0.1 sharpens differences between similar candidates.
+ const tau = 0.1;
+ const exps = scored.map(s => Math.exp(s.cosineSimilarity / tau));
+ const z = exps.reduce((a, b) => a + b, 0) || 1;
+ predictions = scored.map((s, i) => ({
+ label: s.label,
+ patternId: s.patternId,
+ cosineSimilarity: Number(s.cosineSimilarity.toFixed(4)),
+ confidence: Number((exps[i] / z).toFixed(4)),
+ }));
} else {
- // No patterns stored — no predictions possible
+ // No patterns stored — no predictions possible. Be honest about it
+ // instead of returning empty silently.
predictions = [];
}
+ const topConfidence = predictions[0]?.confidence ?? 0;
+ const topSimilarity = predictions[0]?.cosineSimilarity ?? 0;
+
return {
success: true,
_realEmbedding: !!realEmbeddings,
_embeddingSource: embeddingServiceName,
embeddingProvider: embeddingServiceName,
_hasStoredPatterns: storedPatterns.length > 0,
+ _classifierHead: storedPatterns.length > 0 ? 'knn-cosine+softmax(tau=0.1)' : 'none',
modelId: model?.id || 'default',
input: inputText,
predictions,
+ // Surface cosineSimilarity separately so callers know whether the
+ // softmax confidence reflects true match strength.
+ topPrediction: predictions[0]?.label ?? null,
+ topConfidence,
+ topSimilarity,
embedding: embedding.slice(0, 8), // Preview of embedding
embeddingDims: embedding.length,
latency,
+ ...(storedPatterns.length === 0 ? {
+ _note: 'No patterns stored. Train with neural_train(modelType, trainingData) before predicting.',
+ } : {}),
};
},
},