@sparkleideas/integration 3.0.2 → 3.0.4
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/package.json +2 -2
- package/src/__tests__/agent-adapter.test.ts +5 -5
- package/src/__tests__/token-optimizer.test.ts +3 -3
- package/src/agent-adapter.ts +33 -33
- package/src/agentic-flow-agent.ts +34 -34
- package/src/agentic-flow-bridge.ts +39 -39
- package/src/attention-coordinator.ts +14 -14
- package/src/index.ts +6 -6
- package/src/long-running-worker.ts +1 -1
- package/src/multi-model-router.ts +1 -1
- package/src/provider-adapter.ts +1 -1
- package/src/sdk-bridge.ts +7 -7
- package/src/sona-adapter.ts +21 -21
- package/src/specialized-worker.ts +1 -1
- package/src/swarm-adapter.ts +36 -36
- package/src/token-optimizer.ts +7 -7
- package/src/types.ts +5 -5
- package/src/worker-base.ts +3 -3
- package/src/worker-pool.ts +1 -1
package/src/swarm-adapter.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* SwarmAdapter - Bridge between V3 Swarm and
|
|
2
|
+
* SwarmAdapter - Bridge between V3 Swarm and agentic-flow@alpha Patterns
|
|
3
3
|
*
|
|
4
4
|
* Provides bidirectional conversion and delegation patterns between:
|
|
5
5
|
* - Claude Flow v3 UnifiedSwarmCoordinator
|
|
6
|
-
* -
|
|
6
|
+
* - agentic-flow's AttentionCoordinator, SwarmTopology, and Expert routing
|
|
7
7
|
*
|
|
8
|
-
* This implements ADR-001: Adopt
|
|
9
|
-
* by aligning V3 swarm patterns with
|
|
8
|
+
* This implements ADR-001: Adopt agentic-flow as Core Foundation
|
|
9
|
+
* by aligning V3 swarm patterns with agentic-flow's coordination mechanisms.
|
|
10
10
|
*
|
|
11
11
|
* Key Alignments:
|
|
12
12
|
* - Topology: mesh, hierarchical, ring, star (maps V3's centralized -> star)
|
|
@@ -22,17 +22,17 @@
|
|
|
22
22
|
import { EventEmitter } from 'events';
|
|
23
23
|
|
|
24
24
|
// ============================================================================
|
|
25
|
-
//
|
|
25
|
+
// agentic-flow Pattern Types (Target Interface)
|
|
26
26
|
// ============================================================================
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
29
|
+
* agentic-flow SwarmTopology types
|
|
30
30
|
* V3's 'centralized' maps to 'star', 'hybrid' is represented as 'mesh' with hierarchical overlay
|
|
31
31
|
*/
|
|
32
32
|
export type AgenticFlowTopology = 'mesh' | 'hierarchical' | 'ring' | 'star';
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
35
|
+
* agentic-flow Attention mechanism types
|
|
36
36
|
*/
|
|
37
37
|
export type AgenticFlowAttentionMechanism =
|
|
38
38
|
| 'flash' // Flash Attention - fastest, 75% memory reduction
|
|
@@ -42,8 +42,8 @@ export type AgenticFlowAttentionMechanism =
|
|
|
42
42
|
| 'multi-head'; // Standard multi-head attention
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
|
-
*
|
|
46
|
-
* This is the expected output format from agents in
|
|
45
|
+
* agentic-flow AgentOutput interface
|
|
46
|
+
* This is the expected output format from agents in agentic-flow swarms
|
|
47
47
|
*/
|
|
48
48
|
export interface AgenticFlowAgentOutput {
|
|
49
49
|
/** Agent identifier */
|
|
@@ -61,7 +61,7 @@ export interface AgenticFlowAgentOutput {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
|
-
*
|
|
64
|
+
* agentic-flow SpecializedAgent interface
|
|
65
65
|
* Represents an expert agent with specific capabilities
|
|
66
66
|
*/
|
|
67
67
|
export interface AgenticFlowSpecializedAgent {
|
|
@@ -82,7 +82,7 @@ export interface AgenticFlowSpecializedAgent {
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
/**
|
|
85
|
-
*
|
|
85
|
+
* agentic-flow Expert routing result
|
|
86
86
|
*/
|
|
87
87
|
export interface AgenticFlowExpertRoute {
|
|
88
88
|
/** Selected expert IDs */
|
|
@@ -96,7 +96,7 @@ export interface AgenticFlowExpertRoute {
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
/**
|
|
99
|
-
*
|
|
99
|
+
* agentic-flow Attention coordination result
|
|
100
100
|
*/
|
|
101
101
|
export interface AgenticFlowAttentionResult {
|
|
102
102
|
/** Consensus output */
|
|
@@ -212,7 +212,7 @@ export interface SwarmAdapterConfig {
|
|
|
212
212
|
moeTopK: number;
|
|
213
213
|
/** GraphRoPE dimension */
|
|
214
214
|
ropeDimension: number;
|
|
215
|
-
/** Enable delegation to
|
|
215
|
+
/** Enable delegation to agentic-flow when available */
|
|
216
216
|
enableDelegation: boolean;
|
|
217
217
|
/** Fallback on delegation failure */
|
|
218
218
|
fallbackOnError: boolean;
|
|
@@ -240,10 +240,10 @@ const DEFAULT_CONFIG: SwarmAdapterConfig = {
|
|
|
240
240
|
// ============================================================================
|
|
241
241
|
|
|
242
242
|
/**
|
|
243
|
-
* SwarmAdapter - Bridges V3 Swarm with
|
|
243
|
+
* SwarmAdapter - Bridges V3 Swarm with agentic-flow patterns
|
|
244
244
|
*
|
|
245
245
|
* Key Features:
|
|
246
|
-
* - Topology conversion (V3 <->
|
|
246
|
+
* - Topology conversion (V3 <-> agentic-flow)
|
|
247
247
|
* - Agent output format conversion
|
|
248
248
|
* - Specialized agent wrapping
|
|
249
249
|
* - MoE expert routing integration
|
|
@@ -259,7 +259,7 @@ const DEFAULT_CONFIG: SwarmAdapterConfig = {
|
|
|
259
259
|
* enableMoERouting: true,
|
|
260
260
|
* });
|
|
261
261
|
*
|
|
262
|
-
* // Convert V3 agents to
|
|
262
|
+
* // Convert V3 agents to agentic-flow format
|
|
263
263
|
* const specializedAgents = adapter.toSpecializedAgents(v3Agents);
|
|
264
264
|
*
|
|
265
265
|
* // Route task to experts using MoE
|
|
@@ -274,12 +274,12 @@ export class SwarmAdapter extends EventEmitter {
|
|
|
274
274
|
private initialized: boolean = false;
|
|
275
275
|
|
|
276
276
|
/**
|
|
277
|
-
* Reference to
|
|
277
|
+
* Reference to agentic-flow core for delegation
|
|
278
278
|
*/
|
|
279
279
|
private agenticFlowCore: any = null;
|
|
280
280
|
|
|
281
281
|
/**
|
|
282
|
-
* Reference to
|
|
282
|
+
* Reference to agentic-flow AttentionCoordinator
|
|
283
283
|
*/
|
|
284
284
|
private attentionCoordinator: any = null;
|
|
285
285
|
|
|
@@ -313,7 +313,7 @@ export class SwarmAdapter extends EventEmitter {
|
|
|
313
313
|
this.emit('initializing');
|
|
314
314
|
|
|
315
315
|
try {
|
|
316
|
-
// Attempt to connect to
|
|
316
|
+
// Attempt to connect to agentic-flow for delegation
|
|
317
317
|
if (this.config.enableDelegation) {
|
|
318
318
|
await this.connectToAgenticFlow();
|
|
319
319
|
}
|
|
@@ -356,12 +356,12 @@ export class SwarmAdapter extends EventEmitter {
|
|
|
356
356
|
// ==========================================================================
|
|
357
357
|
|
|
358
358
|
/**
|
|
359
|
-
* Convert V3 topology type to
|
|
359
|
+
* Convert V3 topology type to agentic-flow topology
|
|
360
360
|
*
|
|
361
361
|
* Mapping:
|
|
362
362
|
* - mesh -> mesh
|
|
363
363
|
* - hierarchical -> hierarchical
|
|
364
|
-
* - centralized -> star (
|
|
364
|
+
* - centralized -> star (agentic-flow uses 'star' for central coordinator pattern)
|
|
365
365
|
* - hybrid -> mesh (treated as mesh with additional hierarchical overlay)
|
|
366
366
|
*/
|
|
367
367
|
convertTopology(v3Topology: V3TopologyType): AgenticFlowTopology {
|
|
@@ -376,7 +376,7 @@ export class SwarmAdapter extends EventEmitter {
|
|
|
376
376
|
}
|
|
377
377
|
|
|
378
378
|
/**
|
|
379
|
-
* Convert
|
|
379
|
+
* Convert agentic-flow topology to V3 topology type
|
|
380
380
|
*/
|
|
381
381
|
convertTopologyFromAgenticFlow(topology: AgenticFlowTopology): V3TopologyType {
|
|
382
382
|
const mapping: Record<AgenticFlowTopology, V3TopologyType> = {
|
|
@@ -394,10 +394,10 @@ export class SwarmAdapter extends EventEmitter {
|
|
|
394
394
|
// ==========================================================================
|
|
395
395
|
|
|
396
396
|
/**
|
|
397
|
-
* Convert V3 Agent to
|
|
397
|
+
* Convert V3 Agent to agentic-flow AgentOutput format
|
|
398
398
|
*
|
|
399
399
|
* Creates the embedding from agent capabilities and produces
|
|
400
|
-
* the standardized AgentOutput interface expected by
|
|
400
|
+
* the standardized AgentOutput interface expected by agentic-flow.
|
|
401
401
|
*/
|
|
402
402
|
toAgentOutput(
|
|
403
403
|
agent: V3AgentState,
|
|
@@ -427,7 +427,7 @@ export class SwarmAdapter extends EventEmitter {
|
|
|
427
427
|
}
|
|
428
428
|
|
|
429
429
|
/**
|
|
430
|
-
* Convert V3 Agent to
|
|
430
|
+
* Convert V3 Agent to agentic-flow SpecializedAgent format
|
|
431
431
|
*
|
|
432
432
|
* Creates an expert representation suitable for MoE routing
|
|
433
433
|
*/
|
|
@@ -459,7 +459,7 @@ export class SwarmAdapter extends EventEmitter {
|
|
|
459
459
|
}
|
|
460
460
|
|
|
461
461
|
/**
|
|
462
|
-
* Convert
|
|
462
|
+
* Convert agentic-flow SpecializedAgent back to partial V3 format
|
|
463
463
|
* (for updates/sync)
|
|
464
464
|
*/
|
|
465
465
|
fromSpecializedAgent(
|
|
@@ -503,7 +503,7 @@ export class SwarmAdapter extends EventEmitter {
|
|
|
503
503
|
/**
|
|
504
504
|
* Route a task to the best experts using MoE attention
|
|
505
505
|
*
|
|
506
|
-
* Implements
|
|
506
|
+
* Implements agentic-flow's expert routing pattern for task assignment.
|
|
507
507
|
* Uses cosine similarity with load balancing for optimal routing.
|
|
508
508
|
*/
|
|
509
509
|
async routeToExperts(
|
|
@@ -515,7 +515,7 @@ export class SwarmAdapter extends EventEmitter {
|
|
|
515
515
|
const startTime = performance.now();
|
|
516
516
|
const k = topK ?? this.config.moeTopK;
|
|
517
517
|
|
|
518
|
-
// If delegation is available and enabled, use
|
|
518
|
+
// If delegation is available and enabled, use agentic-flow's MoE
|
|
519
519
|
if (this.config.enableMoERouting && this.agenticFlowCore?.moe) {
|
|
520
520
|
try {
|
|
521
521
|
const result = await this.agenticFlowCore.moe.route({
|
|
@@ -589,7 +589,7 @@ export class SwarmAdapter extends EventEmitter {
|
|
|
589
589
|
/**
|
|
590
590
|
* Coordinate agent outputs using attention mechanisms
|
|
591
591
|
*
|
|
592
|
-
* Implements
|
|
592
|
+
* Implements agentic-flow's attention-based consensus pattern
|
|
593
593
|
* for multi-agent coordination.
|
|
594
594
|
*/
|
|
595
595
|
async coordinateWithAttention(
|
|
@@ -600,7 +600,7 @@ export class SwarmAdapter extends EventEmitter {
|
|
|
600
600
|
const startTime = performance.now();
|
|
601
601
|
const useMechanism = mechanism ?? this.config.defaultAttentionMechanism;
|
|
602
602
|
|
|
603
|
-
// If delegation is available, use
|
|
603
|
+
// If delegation is available, use agentic-flow's AttentionCoordinator
|
|
604
604
|
if (
|
|
605
605
|
this.config.enableAttentionCoordination &&
|
|
606
606
|
this.attentionCoordinator
|
|
@@ -772,7 +772,7 @@ export class SwarmAdapter extends EventEmitter {
|
|
|
772
772
|
// ==========================================================================
|
|
773
773
|
|
|
774
774
|
/**
|
|
775
|
-
* Map V3 domain to
|
|
775
|
+
* Map V3 domain to agentic-flow specialization
|
|
776
776
|
*/
|
|
777
777
|
mapDomainToSpecialization(domain: V3AgentDomain): string {
|
|
778
778
|
const mapping: Record<V3AgentDomain, string> = {
|
|
@@ -787,7 +787,7 @@ export class SwarmAdapter extends EventEmitter {
|
|
|
787
787
|
}
|
|
788
788
|
|
|
789
789
|
/**
|
|
790
|
-
* Map
|
|
790
|
+
* Map agentic-flow specialization to V3 domain
|
|
791
791
|
*/
|
|
792
792
|
mapSpecializationToDomain(specialization: string): V3AgentDomain {
|
|
793
793
|
const lower = specialization.toLowerCase();
|
|
@@ -820,7 +820,7 @@ export class SwarmAdapter extends EventEmitter {
|
|
|
820
820
|
// ==========================================================================
|
|
821
821
|
|
|
822
822
|
/**
|
|
823
|
-
* Check if delegation to
|
|
823
|
+
* Check if delegation to agentic-flow is available
|
|
824
824
|
*/
|
|
825
825
|
isDelegationAvailable(): boolean {
|
|
826
826
|
return this.agenticFlowCore !== null;
|
|
@@ -848,7 +848,7 @@ export class SwarmAdapter extends EventEmitter {
|
|
|
848
848
|
private async connectToAgenticFlow(): Promise<void> {
|
|
849
849
|
try {
|
|
850
850
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
851
|
-
const agenticFlowModule: any = await import('
|
|
851
|
+
const agenticFlowModule: any = await import('agentic-flow').catch(() => null);
|
|
852
852
|
|
|
853
853
|
if (
|
|
854
854
|
agenticFlowModule &&
|
|
@@ -867,7 +867,7 @@ export class SwarmAdapter extends EventEmitter {
|
|
|
867
867
|
hasMoE: !!this.agenticFlowCore.moe,
|
|
868
868
|
});
|
|
869
869
|
|
|
870
|
-
this.logDebug('Connected to
|
|
870
|
+
this.logDebug('Connected to agentic-flow', {
|
|
871
871
|
version: this.agenticFlowCore.version,
|
|
872
872
|
});
|
|
873
873
|
} else {
|
|
@@ -886,7 +886,7 @@ export class SwarmAdapter extends EventEmitter {
|
|
|
886
886
|
|
|
887
887
|
private generateAgentEmbedding(agent: V3AgentState): number[] {
|
|
888
888
|
// Generate hash-based embedding from agent properties
|
|
889
|
-
// For ML embeddings, use: import('
|
|
889
|
+
// For ML embeddings, use: import('agentic-flow').computeEmbedding
|
|
890
890
|
const embedding = new Array(128).fill(0);
|
|
891
891
|
|
|
892
892
|
// Encode agent type
|
package/src/token-optimizer.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Token Optimizer - Integrates
|
|
2
|
+
* Token Optimizer - Integrates agentic-flow Agent Booster capabilities
|
|
3
3
|
*
|
|
4
4
|
* Combines:
|
|
5
5
|
* - Agent Booster (352x code edit speedup)
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
import { EventEmitter } from 'events';
|
|
13
13
|
|
|
14
|
-
// Types for
|
|
14
|
+
// Types for agentic-flow integration
|
|
15
15
|
interface TokenStats {
|
|
16
16
|
saved: number;
|
|
17
17
|
baseline: number;
|
|
@@ -42,7 +42,7 @@ async function safeImport<T>(modulePath: string): Promise<T | null> {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
|
-
* Token Optimizer - Reduces token usage via
|
|
45
|
+
* Token Optimizer - Reduces token usage via agentic-flow integration
|
|
46
46
|
*/
|
|
47
47
|
export class TokenOptimizer extends EventEmitter {
|
|
48
48
|
private stats = {
|
|
@@ -61,20 +61,20 @@ export class TokenOptimizer extends EventEmitter {
|
|
|
61
61
|
|
|
62
62
|
async initialize(): Promise<void> {
|
|
63
63
|
try {
|
|
64
|
-
// Dynamic import of
|
|
65
|
-
const af = await safeImport<any>('
|
|
64
|
+
// Dynamic import of agentic-flow main module
|
|
65
|
+
const af = await safeImport<any>('agentic-flow');
|
|
66
66
|
|
|
67
67
|
if (af) {
|
|
68
68
|
this.agenticFlowAvailable = true;
|
|
69
69
|
|
|
70
70
|
// Load ReasoningBank (exported path)
|
|
71
|
-
const rb = await safeImport<any>('
|
|
71
|
+
const rb = await safeImport<any>('agentic-flow/reasoningbank');
|
|
72
72
|
if (rb && rb.retrieveMemories) {
|
|
73
73
|
this.reasoningBank = rb;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
// Load Agent Booster (exported path)
|
|
77
|
-
const ab = await safeImport<any>('
|
|
77
|
+
const ab = await safeImport<any>('agentic-flow/agent-booster');
|
|
78
78
|
if (ab) {
|
|
79
79
|
// Agent booster may export different API
|
|
80
80
|
this.agentBooster = ab.agentBooster || ab.AgentBooster || ab;
|
package/src/types.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* V3 Integration Module Types
|
|
3
3
|
*
|
|
4
|
-
* Type definitions for deep integration with
|
|
5
|
-
* Implements ADR-001: Adopt
|
|
4
|
+
* Type definitions for deep integration with agentic-flow@alpha.
|
|
5
|
+
* Implements ADR-001: Adopt agentic-flow as Core Foundation
|
|
6
6
|
*
|
|
7
7
|
* @module v3/integration/types
|
|
8
8
|
* @version 3.0.0-alpha.1
|
|
@@ -117,7 +117,7 @@ export interface SONALearningStats {
|
|
|
117
117
|
// ===== Flash Attention Types =====
|
|
118
118
|
|
|
119
119
|
/**
|
|
120
|
-
* Attention mechanism types supported by
|
|
120
|
+
* Attention mechanism types supported by agentic-flow.
|
|
121
121
|
* Flash Attention provides 2.49x-7.47x speedup with 50-75% memory reduction.
|
|
122
122
|
*/
|
|
123
123
|
export type AttentionMechanism =
|
|
@@ -260,7 +260,7 @@ export interface IntegrationConfig {
|
|
|
260
260
|
/** Attention configuration */
|
|
261
261
|
attention: Partial<AttentionConfiguration>;
|
|
262
262
|
/** AgentDB configuration */
|
|
263
|
-
|
|
263
|
+
agentdb: Partial<AgentDBConfiguration>;
|
|
264
264
|
/** Feature flags */
|
|
265
265
|
features: FeatureFlags;
|
|
266
266
|
/** Runtime preference (auto-detection order) */
|
|
@@ -486,7 +486,7 @@ export const DEFAULT_FEATURE_FLAGS: FeatureFlags = {
|
|
|
486
486
|
export const DEFAULT_INTEGRATION_CONFIG: IntegrationConfig = {
|
|
487
487
|
sona: DEFAULT_SONA_CONFIG,
|
|
488
488
|
attention: DEFAULT_ATTENTION_CONFIG,
|
|
489
|
-
|
|
489
|
+
agentdb: DEFAULT_AGENTDB_CONFIG,
|
|
490
490
|
features: DEFAULT_FEATURE_FLAGS,
|
|
491
491
|
runtimePreference: ['napi', 'wasm', 'js'],
|
|
492
492
|
lazyLoad: true,
|
package/src/worker-base.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* WorkerBase - Abstract Base Worker Class
|
|
3
3
|
*
|
|
4
4
|
* Provides the foundation for all worker patterns in Claude Flow v3,
|
|
5
|
-
* aligned with
|
|
5
|
+
* aligned with agentic-flow@alpha's worker architecture.
|
|
6
6
|
*
|
|
7
7
|
* Key Features:
|
|
8
8
|
* - Specialization embeddings for intelligent task routing
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* - Capability-based task matching
|
|
11
11
|
* - Memory and coordination integration
|
|
12
12
|
*
|
|
13
|
-
* This implements ADR-001 by building on
|
|
13
|
+
* This implements ADR-001 by building on agentic-flow patterns
|
|
14
14
|
* while providing Claude Flow-specific extensions.
|
|
15
15
|
*
|
|
16
16
|
* @module v3/integration/worker-base
|
|
@@ -110,7 +110,7 @@ export interface WorkerProviderConfig {
|
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
/**
|
|
113
|
-
* Agent output interface (compatible with
|
|
113
|
+
* Agent output interface (compatible with agentic-flow)
|
|
114
114
|
*/
|
|
115
115
|
export interface AgentOutput {
|
|
116
116
|
/** Output content */
|
package/src/worker-pool.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* - Health monitoring and auto-recovery
|
|
12
12
|
* - Type-safe worker registry
|
|
13
13
|
*
|
|
14
|
-
* Compatible with
|
|
14
|
+
* Compatible with agentic-flow's worker pool patterns.
|
|
15
15
|
*
|
|
16
16
|
* @module v3/integration/worker-pool
|
|
17
17
|
* @version 3.0.0-alpha.1
|