@cogitator-ai/swarms 0.1.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/LICENSE +21 -0
- package/README.md +90 -0
- package/dist/communication/blackboard.d.ts +24 -0
- package/dist/communication/blackboard.d.ts.map +1 -0
- package/dist/communication/blackboard.js +135 -0
- package/dist/communication/blackboard.js.map +1 -0
- package/dist/communication/event-emitter.d.ts +20 -0
- package/dist/communication/event-emitter.d.ts.map +1 -0
- package/dist/communication/event-emitter.js +87 -0
- package/dist/communication/event-emitter.js.map +1 -0
- package/dist/communication/index.d.ts +7 -0
- package/dist/communication/index.d.ts.map +1 -0
- package/dist/communication/index.js +7 -0
- package/dist/communication/index.js.map +1 -0
- package/dist/communication/message-bus.d.ts +23 -0
- package/dist/communication/message-bus.d.ts.map +1 -0
- package/dist/communication/message-bus.js +128 -0
- package/dist/communication/message-bus.js.map +1 -0
- package/dist/coordinator.d.ts +44 -0
- package/dist/coordinator.d.ts.map +1 -0
- package/dist/coordinator.js +283 -0
- package/dist/coordinator.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/resources/circuit-breaker.d.ts +29 -0
- package/dist/resources/circuit-breaker.d.ts.map +1 -0
- package/dist/resources/circuit-breaker.js +82 -0
- package/dist/resources/circuit-breaker.js.map +1 -0
- package/dist/resources/index.d.ts +7 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +6 -0
- package/dist/resources/index.js.map +1 -0
- package/dist/resources/tracker.d.ts +30 -0
- package/dist/resources/tracker.d.ts.map +1 -0
- package/dist/resources/tracker.js +84 -0
- package/dist/resources/tracker.js.map +1 -0
- package/dist/strategies/auction.d.ts +17 -0
- package/dist/strategies/auction.d.ts.map +1 -0
- package/dist/strategies/auction.js +204 -0
- package/dist/strategies/auction.js.map +1 -0
- package/dist/strategies/base.d.ts +34 -0
- package/dist/strategies/base.d.ts.map +1 -0
- package/dist/strategies/base.js +74 -0
- package/dist/strategies/base.js.map +1 -0
- package/dist/strategies/consensus.d.ts +20 -0
- package/dist/strategies/consensus.d.ts.map +1 -0
- package/dist/strategies/consensus.js +328 -0
- package/dist/strategies/consensus.js.map +1 -0
- package/dist/strategies/debate.d.ts +15 -0
- package/dist/strategies/debate.d.ts.map +1 -0
- package/dist/strategies/debate.js +171 -0
- package/dist/strategies/debate.js.map +1 -0
- package/dist/strategies/hierarchical.d.ts +13 -0
- package/dist/strategies/hierarchical.d.ts.map +1 -0
- package/dist/strategies/hierarchical.js +86 -0
- package/dist/strategies/hierarchical.js.map +1 -0
- package/dist/strategies/index.d.ts +28 -0
- package/dist/strategies/index.d.ts.map +1 -0
- package/dist/strategies/index.js +106 -0
- package/dist/strategies/index.js.map +1 -0
- package/dist/strategies/pipeline.d.ts +16 -0
- package/dist/strategies/pipeline.d.ts.map +1 -0
- package/dist/strategies/pipeline.js +180 -0
- package/dist/strategies/pipeline.js.map +1 -0
- package/dist/strategies/round-robin.d.ts +27 -0
- package/dist/strategies/round-robin.d.ts.map +1 -0
- package/dist/strategies/round-robin.js +98 -0
- package/dist/strategies/round-robin.js.map +1 -0
- package/dist/swarm.d.ts +113 -0
- package/dist/swarm.d.ts.map +1 -0
- package/dist/swarm.js +280 -0
- package/dist/swarm.js.map +1 -0
- package/dist/tools/blackboard.d.ts +71 -0
- package/dist/tools/blackboard.d.ts.map +1 -0
- package/dist/tools/blackboard.js +149 -0
- package/dist/tools/blackboard.js.map +1 -0
- package/dist/tools/delegation.d.ts +120 -0
- package/dist/tools/delegation.d.ts.map +1 -0
- package/dist/tools/delegation.js +257 -0
- package/dist/tools/delegation.js.map +1 -0
- package/dist/tools/index.d.ts +26 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +65 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/messaging.d.ts +73 -0
- package/dist/tools/messaging.d.ts.map +1 -0
- package/dist/tools/messaging.js +146 -0
- package/dist/tools/messaging.js.map +1 -0
- package/dist/tools/voting.d.ts +110 -0
- package/dist/tools/voting.d.ts.map +1 -0
- package/dist/tools/voting.js +201 -0
- package/dist/tools/voting.js.map +1 -0
- package/dist/workflow/swarm-node.d.ts +43 -0
- package/dist/workflow/swarm-node.d.ts.map +1 -0
- package/dist/workflow/swarm-node.js +111 -0
- package/dist/workflow/swarm-node.js.map +1 -0
- package/package.json +45 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hierarchical.js","sourceRoot":"","sources":["../../src/strategies/hierarchical.ts"],"names":[],"mappings":"AAAA;;GAEG;AAQH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGtC,MAAM,OAAO,oBAAqB,SAAQ,YAAY;IAC5C,MAAM,CAAqB;IAEnC,YAAY,WAA6B,EAAE,MAA2B;QACpE,KAAK,CAAC,WAAW,CAAC,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG;YACZ,kBAAkB,EAAE,CAAC;YACrB,mBAAmB,EAAE,KAAK;YAC1B,YAAY,EAAE,YAAY;YAC1B,UAAU,EAAE,MAAM;YAClB,GAAG,MAAM;SACV,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,OAAwB;QACpC,MAAM,YAAY,GAAG,IAAI,GAAG,EAAqB,CAAC;QAElD,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,CAAC,MAAM,CACrD,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,KAAK,YAAY,CACxC,CAAC;QACF,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;QACvE,CAAC;QACD,MAAM,UAAU,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;QAElC,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,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,OAAO,EAAE,CAAC;YAC7B,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;gBACtB,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;YACzD,CAAC;QACH,CAAC;QAED,OAAO;YACL,MAAM,EAAE,gBAAgB,CAAC,MAAM;YAC/B,UAAU,EAAE,gBAAgB,CAAC,UAAU;YACvC,YAAY;SACb,CAAC;IACJ,CAAC;IAEO,2BAA2B,CACjC,UAAwE;QAExE,MAAM,UAAU,GAAG,UAAU;aAC1B,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YACT,MAAM,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;YAC1F,OAAO,KAAK,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,WAAW,GAAG,SAAS,EAAE,CAAC;QACrD,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC,CAAC;QAEd,OAAO;;;;EAIT,UAAU;;;;;;;;;;;;;;;;;;CAkBX,CAAC,IAAI,EAAE,CAAC;IACP,CAAC;CACF"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strategy exports and factory
|
|
3
|
+
*/
|
|
4
|
+
import type { SwarmConfig, SwarmStrategy, IStrategy, HierarchicalConfig, RoundRobinConfig, ConsensusConfig, AuctionConfig, PipelineConfig, DebateConfig } from '@cogitator-ai/types';
|
|
5
|
+
import type { SwarmCoordinator } from '../coordinator';
|
|
6
|
+
export { BaseStrategy } from './base';
|
|
7
|
+
export { HierarchicalStrategy } from './hierarchical';
|
|
8
|
+
export { RoundRobinStrategy } from './round-robin';
|
|
9
|
+
export { ConsensusStrategy } from './consensus';
|
|
10
|
+
export { AuctionStrategy } from './auction';
|
|
11
|
+
export { PipelineStrategy } from './pipeline';
|
|
12
|
+
export { DebateStrategy } from './debate';
|
|
13
|
+
/**
|
|
14
|
+
* Create a strategy instance based on configuration
|
|
15
|
+
*/
|
|
16
|
+
export declare function createStrategy(coordinator: SwarmCoordinator, config: SwarmConfig): IStrategy;
|
|
17
|
+
/**
|
|
18
|
+
* Get default configuration for a strategy
|
|
19
|
+
*/
|
|
20
|
+
export declare function getDefaultStrategyConfig(strategy: SwarmStrategy): {
|
|
21
|
+
hierarchical?: HierarchicalConfig;
|
|
22
|
+
roundRobin?: RoundRobinConfig;
|
|
23
|
+
consensus?: ConsensusConfig;
|
|
24
|
+
auction?: AuctionConfig;
|
|
25
|
+
pipeline?: PipelineConfig;
|
|
26
|
+
debate?: DebateConfig;
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/strategies/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,aAAa,EACb,SAAS,EACT,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,cAAc,EACd,YAAY,EACb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAS1C;;GAEG;AACH,wBAAgB,cAAc,CAC5B,WAAW,EAAE,gBAAgB,EAC7B,MAAM,EAAE,WAAW,GAClB,SAAS,CAqCX;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,aAAa,GAAG;IACjE,YAAY,CAAC,EAAE,kBAAkB,CAAC;IAClC,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAC9B,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,MAAM,CAAC,EAAE,YAAY,CAAC;CACvB,CAyDA"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strategy exports and factory
|
|
3
|
+
*/
|
|
4
|
+
export { BaseStrategy } from './base';
|
|
5
|
+
export { HierarchicalStrategy } from './hierarchical';
|
|
6
|
+
export { RoundRobinStrategy } from './round-robin';
|
|
7
|
+
export { ConsensusStrategy } from './consensus';
|
|
8
|
+
export { AuctionStrategy } from './auction';
|
|
9
|
+
export { PipelineStrategy } from './pipeline';
|
|
10
|
+
export { DebateStrategy } from './debate';
|
|
11
|
+
import { HierarchicalStrategy } from './hierarchical';
|
|
12
|
+
import { RoundRobinStrategy } from './round-robin';
|
|
13
|
+
import { ConsensusStrategy } from './consensus';
|
|
14
|
+
import { AuctionStrategy } from './auction';
|
|
15
|
+
import { PipelineStrategy } from './pipeline';
|
|
16
|
+
import { DebateStrategy } from './debate';
|
|
17
|
+
/**
|
|
18
|
+
* Create a strategy instance based on configuration
|
|
19
|
+
*/
|
|
20
|
+
export function createStrategy(coordinator, config) {
|
|
21
|
+
const strategy = config.strategy;
|
|
22
|
+
switch (strategy) {
|
|
23
|
+
case 'hierarchical':
|
|
24
|
+
return new HierarchicalStrategy(coordinator, config.hierarchical);
|
|
25
|
+
case 'round-robin':
|
|
26
|
+
return new RoundRobinStrategy(coordinator, config.roundRobin);
|
|
27
|
+
case 'consensus':
|
|
28
|
+
if (!config.consensus) {
|
|
29
|
+
throw new Error('Consensus strategy requires consensus configuration');
|
|
30
|
+
}
|
|
31
|
+
return new ConsensusStrategy(coordinator, config.consensus);
|
|
32
|
+
case 'auction':
|
|
33
|
+
if (!config.auction) {
|
|
34
|
+
throw new Error('Auction strategy requires auction configuration');
|
|
35
|
+
}
|
|
36
|
+
return new AuctionStrategy(coordinator, config.auction);
|
|
37
|
+
case 'pipeline':
|
|
38
|
+
if (!config.pipeline) {
|
|
39
|
+
throw new Error('Pipeline strategy requires pipeline configuration');
|
|
40
|
+
}
|
|
41
|
+
return new PipelineStrategy(coordinator, config.pipeline);
|
|
42
|
+
case 'debate':
|
|
43
|
+
if (!config.debate) {
|
|
44
|
+
throw new Error('Debate strategy requires debate configuration');
|
|
45
|
+
}
|
|
46
|
+
return new DebateStrategy(coordinator, config.debate);
|
|
47
|
+
default:
|
|
48
|
+
throw new Error(`Unknown swarm strategy: ${strategy}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get default configuration for a strategy
|
|
53
|
+
*/
|
|
54
|
+
export function getDefaultStrategyConfig(strategy) {
|
|
55
|
+
switch (strategy) {
|
|
56
|
+
case 'hierarchical':
|
|
57
|
+
return {
|
|
58
|
+
hierarchical: {
|
|
59
|
+
maxDelegationDepth: 3,
|
|
60
|
+
workerCommunication: false,
|
|
61
|
+
routeThrough: 'supervisor',
|
|
62
|
+
visibility: 'full',
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
case 'round-robin':
|
|
66
|
+
return {
|
|
67
|
+
roundRobin: {
|
|
68
|
+
sticky: false,
|
|
69
|
+
rotation: 'sequential',
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
case 'consensus':
|
|
73
|
+
return {
|
|
74
|
+
consensus: {
|
|
75
|
+
threshold: 0.5,
|
|
76
|
+
maxRounds: 3,
|
|
77
|
+
resolution: 'majority',
|
|
78
|
+
onNoConsensus: 'fail',
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
case 'auction':
|
|
82
|
+
return {
|
|
83
|
+
auction: {
|
|
84
|
+
bidding: 'capability-match',
|
|
85
|
+
selection: 'highest-bid',
|
|
86
|
+
minBid: 0,
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
case 'pipeline':
|
|
90
|
+
return {
|
|
91
|
+
pipeline: {
|
|
92
|
+
stages: [],
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
case 'debate':
|
|
96
|
+
return {
|
|
97
|
+
debate: {
|
|
98
|
+
rounds: 3,
|
|
99
|
+
format: 'structured',
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
default:
|
|
103
|
+
return {};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/strategies/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAeH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C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AA2B,QAAQ,EAAE,CAAC,CAAC;IAC3D,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,wBAAwB,CAAC,QAAuB;IAQ9D,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,cAAc;YACjB,OAAO;gBACL,YAAY,EAAE;oBACZ,kBAAkB,EAAE,CAAC;oBACrB,mBAAmB,EAAE,KAAK;oBAC1B,YAAY,EAAE,YAAY;oBAC1B,UAAU,EAAE,MAAM;iBACnB;aACF,CAAC;QAEJ,KAAK,aAAa;YAChB,OAAO;gBACL,UAAU,EAAE;oBACV,MAAM,EAAE,KAAK;oBACb,QAAQ,EAAE,YAAY;iBACvB;aACF,CAAC;QAEJ,KAAK,WAAW;YACd,OAAO;gBACL,SAAS,EAAE;oBACT,SAAS,EAAE,GAAG;oBACd,SAAS,EAAE,CAAC;oBACZ,UAAU,EAAE,UAAU;oBACtB,aAAa,EAAE,MAAM;iBACtB;aACF,CAAC;QAEJ,KAAK,SAAS;YACZ,OAAO;gBACL,OAAO,EAAE;oBACP,OAAO,EAAE,kBAAkB;oBAC3B,SAAS,EAAE,aAAa;oBACxB,MAAM,EAAE,CAAC;iBACV;aACF,CAAC;QAEJ,KAAK,UAAU;YACb,OAAO;gBACL,QAAQ,EAAE;oBACR,MAAM,EAAE,EAAE;iBACX;aACF,CAAC;QAEJ,KAAK,QAAQ;YACX,OAAO;gBACL,MAAM,EAAE;oBACN,MAAM,EAAE,CAAC;oBACT,MAAM,EAAE,YAAY;iBACrB;aACF,CAAC;QAEJ;YACE,OAAO,EAAE,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pipeline strategy - Sequential stages with optional gates
|
|
3
|
+
*/
|
|
4
|
+
import type { SwarmRunOptions, StrategyResult, PipelineConfig } from '@cogitator-ai/types';
|
|
5
|
+
import { BaseStrategy } from './base';
|
|
6
|
+
import type { SwarmCoordinator } from '../coordinator';
|
|
7
|
+
export declare class PipelineStrategy extends BaseStrategy {
|
|
8
|
+
private config;
|
|
9
|
+
constructor(coordinator: SwarmCoordinator, config: PipelineConfig);
|
|
10
|
+
execute(options: SwarmRunOptions): Promise<StrategyResult>;
|
|
11
|
+
private buildDefaultStageInput;
|
|
12
|
+
private buildStageInstructions;
|
|
13
|
+
private checkGate;
|
|
14
|
+
private getRetryCount;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=pipeline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../../src/strategies/pipeline.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACd,cAAc,EAIf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,qBAAa,gBAAiB,SAAQ,YAAY;IAChD,OAAO,CAAC,MAAM,CAAiB;gBAEnB,WAAW,EAAE,gBAAgB,EAAE,MAAM,EAAE,cAAc;IAS3D,OAAO,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;IA6HhE,OAAO,CAAC,sBAAsB;IAY9B,OAAO,CAAC,sBAAsB;YAahB,SAAS;IA4EvB,OAAO,CAAC,aAAa;CAStB"}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pipeline strategy - Sequential stages with optional gates
|
|
3
|
+
*/
|
|
4
|
+
import { BaseStrategy } from './base';
|
|
5
|
+
export class PipelineStrategy extends BaseStrategy {
|
|
6
|
+
config;
|
|
7
|
+
constructor(coordinator, config) {
|
|
8
|
+
super(coordinator);
|
|
9
|
+
this.config = config;
|
|
10
|
+
if (!config.stages || config.stages.length === 0) {
|
|
11
|
+
throw new Error('Pipeline strategy requires at least one stage');
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
async execute(options) {
|
|
15
|
+
const agentResults = new Map();
|
|
16
|
+
const stageOutputs = new Map();
|
|
17
|
+
this.coordinator.blackboard.write('pipeline', {
|
|
18
|
+
stages: this.config.stages.map(s => s.name),
|
|
19
|
+
currentStage: 0,
|
|
20
|
+
completed: [],
|
|
21
|
+
failed: [],
|
|
22
|
+
}, 'system');
|
|
23
|
+
let currentInput = options.input;
|
|
24
|
+
let stageIndex = 0;
|
|
25
|
+
while (stageIndex < this.config.stages.length) {
|
|
26
|
+
const stage = this.config.stages[stageIndex];
|
|
27
|
+
this.coordinator.events.emit('pipeline:stage', {
|
|
28
|
+
index: stageIndex,
|
|
29
|
+
name: stage.name,
|
|
30
|
+
total: this.config.stages.length,
|
|
31
|
+
});
|
|
32
|
+
const pipelineState = this.coordinator.blackboard.read('pipeline');
|
|
33
|
+
this.coordinator.blackboard.write('pipeline', {
|
|
34
|
+
...pipelineState,
|
|
35
|
+
currentStage: stageIndex,
|
|
36
|
+
currentStageName: stage.name,
|
|
37
|
+
}, 'system');
|
|
38
|
+
const pipelineContext = {
|
|
39
|
+
input: options.input,
|
|
40
|
+
stageIndex,
|
|
41
|
+
stageName: stage.name,
|
|
42
|
+
previousOutputs: stageOutputs,
|
|
43
|
+
};
|
|
44
|
+
const stageInput = this.config.stageInput
|
|
45
|
+
? this.config.stageInput(currentInput, stage, pipelineContext)
|
|
46
|
+
: this.buildDefaultStageInput(currentInput, stage, pipelineContext);
|
|
47
|
+
const stageContext = {
|
|
48
|
+
...options.context,
|
|
49
|
+
pipelineContext: {
|
|
50
|
+
stageIndex,
|
|
51
|
+
stageName: stage.name,
|
|
52
|
+
totalStages: this.config.stages.length,
|
|
53
|
+
isFirstStage: stageIndex === 0,
|
|
54
|
+
isLastStage: stageIndex === this.config.stages.length - 1,
|
|
55
|
+
previousOutputs: Object.fromEntries(stageOutputs),
|
|
56
|
+
},
|
|
57
|
+
stageInstructions: this.buildStageInstructions(stage, stageIndex),
|
|
58
|
+
};
|
|
59
|
+
const result = await this.coordinator.runAgent(stage.agent.name, String(stageInput), stageContext);
|
|
60
|
+
agentResults.set(stage.name, result);
|
|
61
|
+
stageOutputs.set(stage.name, result.output);
|
|
62
|
+
currentInput = result.output;
|
|
63
|
+
const updatedState = this.coordinator.blackboard.read('pipeline');
|
|
64
|
+
updatedState.completed.push(stage.name);
|
|
65
|
+
this.coordinator.blackboard.write('pipeline', updatedState, 'system');
|
|
66
|
+
if (stage.gate) {
|
|
67
|
+
const gateResult = await this.checkGate(stage, result, stageIndex, agentResults, options);
|
|
68
|
+
if (gateResult.action === 'abort') {
|
|
69
|
+
throw new Error(`Pipeline aborted at gate '${stage.name}': ${gateResult.reason}`);
|
|
70
|
+
}
|
|
71
|
+
if (gateResult.action === 'retry-previous' && stageIndex > 0) {
|
|
72
|
+
const state = this.coordinator.blackboard.read('pipeline');
|
|
73
|
+
state.failed.push(stage.name);
|
|
74
|
+
state.completed = state.completed.filter(s => s !== stage.name);
|
|
75
|
+
this.coordinator.blackboard.write('pipeline', state, 'system');
|
|
76
|
+
stageIndex = stageIndex - 1;
|
|
77
|
+
currentInput = stageOutputs.get(this.config.stages[stageIndex - 1]?.name) ?? options.input;
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
if (gateResult.action === 'goto' && gateResult.targetStage !== undefined) {
|
|
81
|
+
stageIndex = gateResult.targetStage;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
this.coordinator.events.emit('pipeline:stage:complete', {
|
|
86
|
+
index: stageIndex,
|
|
87
|
+
name: stage.name,
|
|
88
|
+
});
|
|
89
|
+
stageIndex++;
|
|
90
|
+
}
|
|
91
|
+
const lastStageName = this.config.stages[this.config.stages.length - 1].name;
|
|
92
|
+
const finalOutput = stageOutputs.get(lastStageName);
|
|
93
|
+
return {
|
|
94
|
+
output: finalOutput,
|
|
95
|
+
agentResults,
|
|
96
|
+
pipelineOutputs: stageOutputs,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
buildDefaultStageInput(prevOutput, stage, context) {
|
|
100
|
+
if (context.stageIndex === 0) {
|
|
101
|
+
return String(prevOutput);
|
|
102
|
+
}
|
|
103
|
+
return `Previous stage output:\n${prevOutput}\n\nYour task as the ${stage.name} stage: Process and transform this input according to your role.`;
|
|
104
|
+
}
|
|
105
|
+
buildStageInstructions(stage, stageIndex) {
|
|
106
|
+
const isGate = stage.gate ? '\nThis stage acts as a QUALITY GATE. Your output will be validated before proceeding.' : '';
|
|
107
|
+
return `
|
|
108
|
+
You are the "${stage.name}" stage in a processing pipeline.
|
|
109
|
+
Stage ${stageIndex + 1} of ${this.config.stages.length}.
|
|
110
|
+
${isGate}
|
|
111
|
+
|
|
112
|
+
Process the input according to your configured role and pass your output to the next stage.
|
|
113
|
+
Ensure your output is well-structured and ready for the next stage to consume.
|
|
114
|
+
`.trim();
|
|
115
|
+
}
|
|
116
|
+
async checkGate(stage, result, _stageIndex, _agentResults, _options) {
|
|
117
|
+
const gateConfig = this.config.gates?.[stage.name];
|
|
118
|
+
if (!gateConfig) {
|
|
119
|
+
const output = String(result.output).toLowerCase();
|
|
120
|
+
const hasError = output.includes('error') || output.includes('failed') || output.includes('cannot');
|
|
121
|
+
if (hasError) {
|
|
122
|
+
this.coordinator.events.emit('pipeline:gate:fail', {
|
|
123
|
+
stage: stage.name,
|
|
124
|
+
reason: 'Output contains error indicators',
|
|
125
|
+
});
|
|
126
|
+
return { action: 'skip', reason: 'Output contains error indicators' };
|
|
127
|
+
}
|
|
128
|
+
this.coordinator.events.emit('pipeline:gate:pass', { stage: stage.name });
|
|
129
|
+
return { action: 'pass' };
|
|
130
|
+
}
|
|
131
|
+
let passed;
|
|
132
|
+
try {
|
|
133
|
+
passed = gateConfig.condition(result.output);
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
passed = false;
|
|
137
|
+
}
|
|
138
|
+
if (passed) {
|
|
139
|
+
this.coordinator.events.emit('pipeline:gate:pass', { stage: stage.name });
|
|
140
|
+
return { action: 'pass' };
|
|
141
|
+
}
|
|
142
|
+
this.coordinator.events.emit('pipeline:gate:fail', {
|
|
143
|
+
stage: stage.name,
|
|
144
|
+
reason: 'Gate condition failed',
|
|
145
|
+
});
|
|
146
|
+
const onFail = gateConfig.onFail;
|
|
147
|
+
if (onFail === 'abort') {
|
|
148
|
+
return { action: 'abort', reason: 'Gate condition failed' };
|
|
149
|
+
}
|
|
150
|
+
if (onFail === 'skip') {
|
|
151
|
+
return { action: 'skip', reason: 'Gate condition failed, skipping' };
|
|
152
|
+
}
|
|
153
|
+
if (onFail === 'retry-previous') {
|
|
154
|
+
const retryCount = this.getRetryCount(stage.name, _agentResults);
|
|
155
|
+
if (retryCount >= gateConfig.maxRetries) {
|
|
156
|
+
return { action: 'abort', reason: `Max retries (${gateConfig.maxRetries}) exceeded` };
|
|
157
|
+
}
|
|
158
|
+
return { action: 'retry-previous' };
|
|
159
|
+
}
|
|
160
|
+
if (onFail.startsWith('goto:')) {
|
|
161
|
+
const targetStageName = onFail.slice(5);
|
|
162
|
+
const targetIndex = this.config.stages.findIndex(s => s.name === targetStageName);
|
|
163
|
+
if (targetIndex >= 0) {
|
|
164
|
+
return { action: 'goto', targetStage: targetIndex };
|
|
165
|
+
}
|
|
166
|
+
return { action: 'abort', reason: `Target stage '${targetStageName}' not found` };
|
|
167
|
+
}
|
|
168
|
+
return { action: 'pass' };
|
|
169
|
+
}
|
|
170
|
+
getRetryCount(stageName, results) {
|
|
171
|
+
let count = 0;
|
|
172
|
+
for (const key of results.keys()) {
|
|
173
|
+
if (key === stageName || key.startsWith(`${stageName}_retry`)) {
|
|
174
|
+
count++;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return count - 1;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=pipeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline.js","sourceRoot":"","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B,EAAE,CAAC;QACtC,CAAC;QAED,IAAI,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;YAC/B,MAAM,eAAe,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACxC,MAAM,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,eAAe,CAAC,CAAC;YAClF,IAAI,WAAW,IAAI,CAAC,EAAE,CAAC;gBACrB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC;YACtD,CAAC;YACD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,iBAAiB,eAAe,aAAa,EAAE,CAAC;QACpF,CAAC;QAED,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;IAC5B,CAAC;IAEO,aAAa,CAAC,SAAiB,EAAE,OAA+B;QACtE,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;YACjC,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,SAAS,QAAQ,CAAC,EAAE,CAAC;gBAC9D,KAAK,EAAE,CAAC;YACV,CAAC;QACH,CAAC;QACD,OAAO,KAAK,GAAG,CAAC,CAAC;IACnB,CAAC;CACF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Round-robin strategy - Rotate task assignment among agents
|
|
3
|
+
*/
|
|
4
|
+
import type { SwarmRunOptions, StrategyResult, RoundRobinConfig } from '@cogitator-ai/types';
|
|
5
|
+
import { BaseStrategy } from './base';
|
|
6
|
+
import type { SwarmCoordinator } from '../coordinator';
|
|
7
|
+
export declare class RoundRobinStrategy extends BaseStrategy {
|
|
8
|
+
private config;
|
|
9
|
+
private currentIndex;
|
|
10
|
+
private stickyAssignments;
|
|
11
|
+
constructor(coordinator: SwarmCoordinator, config?: RoundRobinConfig);
|
|
12
|
+
execute(options: SwarmRunOptions): Promise<StrategyResult>;
|
|
13
|
+
private selectAgent;
|
|
14
|
+
private getNextAgent;
|
|
15
|
+
/**
|
|
16
|
+
* Reset the rotation index
|
|
17
|
+
*/
|
|
18
|
+
reset(): void;
|
|
19
|
+
/**
|
|
20
|
+
* Get current rotation state
|
|
21
|
+
*/
|
|
22
|
+
getState(): {
|
|
23
|
+
currentIndex: number;
|
|
24
|
+
stickyAssignments: Record<string, string>;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=round-robin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"round-robin.d.ts","sourceRoot":"","sources":["../../src/strategies/round-robin.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACd,gBAAgB,EAGjB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,qBAAa,kBAAmB,SAAQ,YAAY;IAClD,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,iBAAiB,CAA6B;gBAE1C,WAAW,EAAE,gBAAgB,EAAE,MAAM,CAAC,EAAE,gBAAgB;IAS9D,OAAO,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;IAmDhE,OAAO,CAAC,WAAW;IAqBnB,OAAO,CAAC,YAAY;IAWpB;;OAEG;IACH,KAAK,IAAI,IAAI;IAKb;;OAEG;IACH,QAAQ,IAAI;QACV,YAAY,EAAE,MAAM,CAAC;QACrB,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAC3C;CAMF"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Round-robin strategy - Rotate task assignment among agents
|
|
3
|
+
*/
|
|
4
|
+
import { BaseStrategy } from './base';
|
|
5
|
+
export class RoundRobinStrategy extends BaseStrategy {
|
|
6
|
+
config;
|
|
7
|
+
currentIndex = 0;
|
|
8
|
+
stickyAssignments = new Map();
|
|
9
|
+
constructor(coordinator, config) {
|
|
10
|
+
super(coordinator);
|
|
11
|
+
this.config = {
|
|
12
|
+
sticky: false,
|
|
13
|
+
rotation: 'sequential',
|
|
14
|
+
...config,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
async execute(options) {
|
|
18
|
+
const agentResults = new Map();
|
|
19
|
+
const agents = this.coordinator.getAgents();
|
|
20
|
+
if (agents.length === 0) {
|
|
21
|
+
throw new Error('Round-robin strategy requires at least 1 agent');
|
|
22
|
+
}
|
|
23
|
+
const selectedAgent = this.selectAgent(agents, options);
|
|
24
|
+
this.coordinator.events.emit('round-robin:assigned', {
|
|
25
|
+
agent: selectedAgent.agent.name,
|
|
26
|
+
index: this.currentIndex,
|
|
27
|
+
sticky: this.config.sticky,
|
|
28
|
+
});
|
|
29
|
+
this.coordinator.blackboard.write('round-robin', {
|
|
30
|
+
currentAgent: selectedAgent.agent.name,
|
|
31
|
+
currentIndex: this.currentIndex,
|
|
32
|
+
totalAgents: agents.length,
|
|
33
|
+
stickyEnabled: this.config.sticky,
|
|
34
|
+
}, 'system');
|
|
35
|
+
const agentContext = {
|
|
36
|
+
...options.context,
|
|
37
|
+
roundRobinContext: {
|
|
38
|
+
selectedAgent: selectedAgent.agent.name,
|
|
39
|
+
totalAgents: agents.length,
|
|
40
|
+
isSticky: this.config.sticky,
|
|
41
|
+
rotation: this.config.rotation,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
const result = await this.coordinator.runAgent(selectedAgent.agent.name, options.input, agentContext);
|
|
45
|
+
agentResults.set(selectedAgent.agent.name, result);
|
|
46
|
+
if (this.config.rotation === 'sequential' && !this.config.sticky) {
|
|
47
|
+
this.currentIndex = (this.currentIndex + 1) % agents.length;
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
output: result.output,
|
|
51
|
+
structured: result.structured,
|
|
52
|
+
agentResults,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
selectAgent(agents, options) {
|
|
56
|
+
if (this.config.sticky && this.config.stickyKey) {
|
|
57
|
+
const key = this.config.stickyKey(options.input);
|
|
58
|
+
const existingAssignment = this.stickyAssignments.get(key);
|
|
59
|
+
if (existingAssignment) {
|
|
60
|
+
const agent = agents.find(a => a.agent.name === existingAssignment);
|
|
61
|
+
if (agent) {
|
|
62
|
+
return agent;
|
|
63
|
+
}
|
|
64
|
+
this.stickyAssignments.delete(key);
|
|
65
|
+
}
|
|
66
|
+
const selectedAgent = this.getNextAgent(agents);
|
|
67
|
+
this.stickyAssignments.set(key, selectedAgent.agent.name);
|
|
68
|
+
return selectedAgent;
|
|
69
|
+
}
|
|
70
|
+
return this.getNextAgent(agents);
|
|
71
|
+
}
|
|
72
|
+
getNextAgent(agents) {
|
|
73
|
+
if (this.config.rotation === 'random') {
|
|
74
|
+
const randomIndex = Math.floor(Math.random() * agents.length);
|
|
75
|
+
this.currentIndex = randomIndex;
|
|
76
|
+
return agents[randomIndex];
|
|
77
|
+
}
|
|
78
|
+
const agent = agents[this.currentIndex];
|
|
79
|
+
return agent;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Reset the rotation index
|
|
83
|
+
*/
|
|
84
|
+
reset() {
|
|
85
|
+
this.currentIndex = 0;
|
|
86
|
+
this.stickyAssignments.clear();
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get current rotation state
|
|
90
|
+
*/
|
|
91
|
+
getState() {
|
|
92
|
+
return {
|
|
93
|
+
currentIndex: this.currentIndex,
|
|
94
|
+
stickyAssignments: Object.fromEntries(this.stickyAssignments),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=round-robin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"round-robin.js","sourceRoot":"","sources":["../../src/strategies/round-robin.ts"],"names":[],"mappings":"AAAA;;GAEG;AASH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGtC,MAAM,OAAO,kBAAmB,SAAQ,YAAY;IAC1C,MAAM,CAAmB;IACzB,YAAY,GAAG,CAAC,CAAC;IACjB,iBAAiB,GAAG,IAAI,GAAG,EAAkB,CAAC;IAEtD,YAAY,WAA6B,EAAE,MAAyB;QAClE,KAAK,CAAC,WAAW,CAAC,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG;YACZ,MAAM,EAAE,KAAK;YACb,QAAQ,EAAE,YAAY;YACtB,GAAG,MAAM;SACV,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,OAAwB;QACpC,MAAM,YAAY,GAAG,IAAI,GAAG,EAAqB,CAAC;QAClD,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,CAAC;QAE5C,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;QACpE,CAAC;QAED,MAAM,aAAa,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAExD,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,sBAAsB,EAAE;YACnD,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,IAAI;YAC/B,KAAK,EAAE,IAAI,CAAC,YAAY;YACxB,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM;SAC3B,CAAC,CAAC;QAEH,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,KAAK,CAAC,aAAa,EAAE;YAC/C,YAAY,EAAE,aAAa,CAAC,KAAK,CAAC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EAAE,IAAI,CAAC,YAAY;YAC/B,iBAAiB,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,iBAAiB,CAAC;SAC9D,CAAC;IACJ,CAAC;CACF"}
|
package/dist/swarm.d.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Swarm - Main facade for multi-agent swarm coordination
|
|
3
|
+
*/
|
|
4
|
+
import type { Cogitator } from '@cogitator-ai/core';
|
|
5
|
+
import type { SwarmConfig, SwarmRunOptions, StrategyResult, SwarmAgent, SwarmEventEmitter, SwarmEventType, SwarmEventHandler, MessageBus, Blackboard } from '@cogitator-ai/types';
|
|
6
|
+
export declare class Swarm {
|
|
7
|
+
private config;
|
|
8
|
+
private coordinator;
|
|
9
|
+
private strategy;
|
|
10
|
+
constructor(cogitator: Cogitator, config: SwarmConfig);
|
|
11
|
+
/**
|
|
12
|
+
* Swarm name
|
|
13
|
+
*/
|
|
14
|
+
get name(): string;
|
|
15
|
+
/**
|
|
16
|
+
* Swarm ID
|
|
17
|
+
*/
|
|
18
|
+
get id(): string;
|
|
19
|
+
/**
|
|
20
|
+
* Strategy type
|
|
21
|
+
*/
|
|
22
|
+
get strategyType(): string;
|
|
23
|
+
/**
|
|
24
|
+
* Message bus for agent communication
|
|
25
|
+
*/
|
|
26
|
+
get messageBus(): MessageBus;
|
|
27
|
+
/**
|
|
28
|
+
* Shared blackboard
|
|
29
|
+
*/
|
|
30
|
+
get blackboard(): Blackboard;
|
|
31
|
+
/**
|
|
32
|
+
* Event emitter for swarm events
|
|
33
|
+
*/
|
|
34
|
+
get events(): SwarmEventEmitter;
|
|
35
|
+
/**
|
|
36
|
+
* Run the swarm with the configured strategy
|
|
37
|
+
*/
|
|
38
|
+
run(options: SwarmRunOptions): Promise<StrategyResult>;
|
|
39
|
+
/**
|
|
40
|
+
* Get all agents in the swarm
|
|
41
|
+
*/
|
|
42
|
+
getAgents(): SwarmAgent[];
|
|
43
|
+
/**
|
|
44
|
+
* Get a specific agent by name
|
|
45
|
+
*/
|
|
46
|
+
getAgent(name: string): SwarmAgent | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Subscribe to swarm events
|
|
49
|
+
*/
|
|
50
|
+
on(event: SwarmEventType | '*', handler: SwarmEventHandler): () => void;
|
|
51
|
+
/**
|
|
52
|
+
* Subscribe to swarm event once
|
|
53
|
+
*/
|
|
54
|
+
once(event: SwarmEventType | '*', handler: SwarmEventHandler): () => void;
|
|
55
|
+
/**
|
|
56
|
+
* Get resource usage
|
|
57
|
+
*/
|
|
58
|
+
getResourceUsage(): import("@cogitator-ai/types").SwarmResourceUsage;
|
|
59
|
+
/**
|
|
60
|
+
* Pause swarm execution
|
|
61
|
+
*/
|
|
62
|
+
pause(): void;
|
|
63
|
+
/**
|
|
64
|
+
* Resume swarm execution
|
|
65
|
+
*/
|
|
66
|
+
resume(): void;
|
|
67
|
+
/**
|
|
68
|
+
* Abort swarm execution
|
|
69
|
+
*/
|
|
70
|
+
abort(): void;
|
|
71
|
+
/**
|
|
72
|
+
* Check if swarm is paused
|
|
73
|
+
*/
|
|
74
|
+
isPaused(): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Check if swarm is aborted
|
|
77
|
+
*/
|
|
78
|
+
isAborted(): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Reset swarm state for a new run
|
|
81
|
+
*/
|
|
82
|
+
reset(): void;
|
|
83
|
+
private validateConfig;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Create a swarm with fluent configuration
|
|
87
|
+
*/
|
|
88
|
+
export declare class SwarmBuilder {
|
|
89
|
+
private config;
|
|
90
|
+
constructor(name: string);
|
|
91
|
+
strategy(strategy: SwarmConfig['strategy']): this;
|
|
92
|
+
supervisor(agent: SwarmConfig['supervisor']): this;
|
|
93
|
+
workers(agents: SwarmConfig['workers']): this;
|
|
94
|
+
agents(agents: SwarmConfig['agents']): this;
|
|
95
|
+
moderator(agent: SwarmConfig['moderator']): this;
|
|
96
|
+
router(agent: SwarmConfig['router']): this;
|
|
97
|
+
hierarchical(config: SwarmConfig['hierarchical']): this;
|
|
98
|
+
roundRobin(config: SwarmConfig['roundRobin']): this;
|
|
99
|
+
consensus(config: SwarmConfig['consensus']): this;
|
|
100
|
+
auction(config: SwarmConfig['auction']): this;
|
|
101
|
+
pipeline(config: SwarmConfig['pipeline']): this;
|
|
102
|
+
debate(config: SwarmConfig['debate']): this;
|
|
103
|
+
messaging(config: SwarmConfig['messaging']): this;
|
|
104
|
+
blackboardConfig(config: SwarmConfig['blackboard']): this;
|
|
105
|
+
resources(config: SwarmConfig['resources']): this;
|
|
106
|
+
errorHandling(config: SwarmConfig['errorHandling']): this;
|
|
107
|
+
build(cogitator: Cogitator): Swarm;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Create a new swarm builder
|
|
111
|
+
*/
|
|
112
|
+
export declare function swarm(name: string): SwarmBuilder;
|
|
113
|
+
//# sourceMappingURL=swarm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swarm.d.ts","sourceRoot":"","sources":["../src/swarm.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EACV,WAAW,EACX,eAAe,EACf,cAAc,EACd,UAAU,EACV,iBAAiB,EACjB,cAAc,EACd,iBAAiB,EACjB,UAAU,EACV,UAAU,EAEX,MAAM,qBAAqB,CAAC;AAI7B,qBAAa,KAAK;IAChB,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,WAAW,CAAmB;IACtC,OAAO,CAAC,QAAQ,CAAY;gBAEhB,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW;IAMrD;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;OAEG;IACH,IAAI,EAAE,IAAI,MAAM,CAEf;IAED;;OAEG;IACH,IAAI,YAAY,IA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