@grc-claw/agent-collaboration 0.8.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.
@@ -0,0 +1,151 @@
1
+ /**
2
+ * AgentCollaboration - Multi-agent orchestration for complex GRC tasks
3
+ *
4
+ * Enables specialized agents (compliance, security, risk, audit) to collaborate
5
+ * on complex tasks that require domain expertise from multiple areas.
6
+ *
7
+ * Features:
8
+ * - Task decomposition and delegation
9
+ * - Inter-agent communication protocol
10
+ * - Consensus building for conflicting recommendations
11
+ * - Parallel execution with result aggregation
12
+ * - Conflict resolution strategies
13
+ * - Agent capability matching
14
+ */
15
+ export interface Agent {
16
+ id: string;
17
+ name: string;
18
+ type: 'compliance' | 'security' | 'risk' | 'audit' | 'evidence' | 'remediation';
19
+ capabilities: string[];
20
+ status: 'idle' | 'busy' | 'offline';
21
+ currentTask?: string;
22
+ trustScore: number;
23
+ lastActive: Date;
24
+ }
25
+ export interface CollaborationTask {
26
+ id: string;
27
+ type: string;
28
+ priority: 'critical' | 'high' | 'medium' | 'low';
29
+ requiredCapabilities: string[];
30
+ input: Record<string, unknown>;
31
+ deadline?: Date;
32
+ maxAgents?: number;
33
+ consensusRequired?: boolean;
34
+ }
35
+ export interface TaskResult {
36
+ taskId: string;
37
+ agentId: string;
38
+ status: 'completed' | 'failed' | 'partial';
39
+ output: Record<string, unknown>;
40
+ confidence: number;
41
+ recommendations: string[];
42
+ timestamp: Date;
43
+ executionTimeMs: number;
44
+ }
45
+ export interface CollaborationSession {
46
+ id: string;
47
+ task: CollaborationTask;
48
+ agents: string[];
49
+ results: TaskResult[];
50
+ consensus?: ConsensusResult;
51
+ status: 'pending' | 'in_progress' | 'completed' | 'failed';
52
+ startedAt: Date;
53
+ completedAt?: Date;
54
+ }
55
+ export interface ConsensusResult {
56
+ achieved: boolean;
57
+ agreementLevel: number;
58
+ finalRecommendation: string;
59
+ dissentingViews: string[];
60
+ resolutionStrategy: 'majority' | 'weighted' | 'expert' | 'compromise';
61
+ }
62
+ export interface AgentMessage {
63
+ id: string;
64
+ from: string;
65
+ to: string | 'broadcast';
66
+ type: 'request' | 'response' | 'update' | 'alert';
67
+ payload: Record<string, unknown>;
68
+ timestamp: Date;
69
+ requiresResponse: boolean;
70
+ }
71
+ export declare class AgentCollaboration {
72
+ private readonly options;
73
+ private agents;
74
+ private sessions;
75
+ private messageQueue;
76
+ private taskQueue;
77
+ constructor(options?: {
78
+ maxConcurrentSessions?: number;
79
+ defaultTimeoutMs?: number;
80
+ consensusThreshold?: number;
81
+ });
82
+ /**
83
+ * Register an agent
84
+ */
85
+ registerAgent(agent: Agent): void;
86
+ /**
87
+ * Update agent status
88
+ */
89
+ updateAgentStatus(id: string, status: Agent['status']): void;
90
+ /**
91
+ * Get available agents for a task
92
+ */
93
+ getAvailableAgents(requiredCapabilities: string[]): Agent[];
94
+ /**
95
+ * Submit a task for collaboration
96
+ */
97
+ submitTask(task: CollaborationTask): string;
98
+ /**
99
+ * Get session status
100
+ */
101
+ getSession(sessionId: string): CollaborationSession | undefined;
102
+ /**
103
+ * Get all active sessions
104
+ */
105
+ getActiveSessions(): CollaborationSession[];
106
+ /**
107
+ * Send a message between agents
108
+ */
109
+ sendMessage(message: AgentMessage): void;
110
+ /**
111
+ * Get message history for an agent
112
+ */
113
+ getAgentMessages(agentId: string): AgentMessage[];
114
+ /**
115
+ * Force consensus on a session
116
+ */
117
+ forceConsensus(sessionId: string): ConsensusResult | null;
118
+ /**
119
+ * Process task queue
120
+ */
121
+ private processTaskQueue;
122
+ /**
123
+ * Start a collaboration session
124
+ */
125
+ private startSession;
126
+ /**
127
+ * Delegate task to agents
128
+ */
129
+ private delegateTask;
130
+ /**
131
+ * Simulate agent response (for demo purposes)
132
+ */
133
+ private simulateAgentResponse;
134
+ /**
135
+ * Add result to session
136
+ */
137
+ private addResult;
138
+ /**
139
+ * Complete a session
140
+ */
141
+ private completeSession;
142
+ /**
143
+ * Build consensus from results
144
+ */
145
+ private buildConsensus;
146
+ /**
147
+ * Process incoming message
148
+ */
149
+ private processMessage;
150
+ }
151
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,WAAW,KAAK;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,YAAY,GAAG,UAAU,GAAG,MAAM,GAAG,OAAO,GAAG,UAAU,GAAG,aAAa,CAAC;IAChF,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IACpC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,IAAI,CAAC;CAClB;AAED,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;IACjD,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,QAAQ,CAAC,EAAE,IAAI,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC;IAC3C,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,SAAS,EAAE,IAAI,CAAC;IAChB,e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E,MAAM,CAAC;KACxB;IAUR;;OAEG;IACH,aAAa,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAIjC;;OAEG;IACH,iBAAiB,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,GAAG,IAAI;IAQ5D;;OAEG;IACH,kBAAkB,CAAC,oBAAoB,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE;IAO3D;;OAEG;IACH,UAAU,CAAC,IAAI,EAAE,iBAAiB,GAAG,MAAM;IAM3C;;OAEG;IACH,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,oBAAoB,GAAG,SAAS;IAI/D;;OAEG;IACH,iBAAiB,IAAI,oBAAoB,EAAE;IAM3C;;OAEG;IACH,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI;IAKxC;;OAEG;IACH,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,EAAE;IAMjD;;OAEG;IACH,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI;IAOzD;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAmBxB;;OAEG;IACH,OAAO,CAAC,YAAY;IAmBpB;;OAEG;IACH,OAAO,CAAC,YAAY;IAQpB;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAyB7B;;OAEG;IACH,OAAO,CAAC,SAAS;IAYjB;;OAEG;IACH,OAAO,CAAC,eAAe;IAgBvB;;OAEG;IACH,OAAO,CAAC,cAAc;IA2BtB;;OAEG;IACH,OAAO,CAAC,cAAc;CAgBvB"}
package/dist/index.js ADDED
@@ -0,0 +1,245 @@
1
+ "use strict";
2
+ /**
3
+ * AgentCollaboration - Multi-agent orchestration for complex GRC tasks
4
+ *
5
+ * Enables specialized agents (compliance, security, risk, audit) to collaborate
6
+ * on complex tasks that require domain expertise from multiple areas.
7
+ *
8
+ * Features:
9
+ * - Task decomposition and delegation
10
+ * - Inter-agent communication protocol
11
+ * - Consensus building for conflicting recommendations
12
+ * - Parallel execution with result aggregation
13
+ * - Conflict resolution strategies
14
+ * - Agent capability matching
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.AgentCollaboration = void 0;
18
+ class AgentCollaboration {
19
+ options;
20
+ agents = new Map();
21
+ sessions = new Map();
22
+ messageQueue = [];
23
+ taskQueue = [];
24
+ constructor(options = {}) {
25
+ this.options = options;
26
+ this.options = {
27
+ maxConcurrentSessions: 10,
28
+ defaultTimeoutMs: 300000, // 5 minutes
29
+ consensusThreshold: 0.7,
30
+ ...options
31
+ };
32
+ }
33
+ /**
34
+ * Register an agent
35
+ */
36
+ registerAgent(agent) {
37
+ this.agents.set(agent.id, agent);
38
+ }
39
+ /**
40
+ * Update agent status
41
+ */
42
+ updateAgentStatus(id, status) {
43
+ const agent = this.agents.get(id);
44
+ if (agent) {
45
+ agent.status = status;
46
+ agent.lastActive = new Date();
47
+ }
48
+ }
49
+ /**
50
+ * Get available agents for a task
51
+ */
52
+ getAvailableAgents(requiredCapabilities) {
53
+ return Array.from(this.agents.values()).filter(agent => agent.status === 'idle' &&
54
+ requiredCapabilities.every(cap => agent.capabilities.includes(cap)));
55
+ }
56
+ /**
57
+ * Submit a task for collaboration
58
+ */
59
+ submitTask(task) {
60
+ this.taskQueue.push(task);
61
+ this.processTaskQueue();
62
+ return task.id;
63
+ }
64
+ /**
65
+ * Get session status
66
+ */
67
+ getSession(sessionId) {
68
+ return this.sessions.get(sessionId);
69
+ }
70
+ /**
71
+ * Get all active sessions
72
+ */
73
+ getActiveSessions() {
74
+ return Array.from(this.sessions.values()).filter(s => s.status === 'in_progress' || s.status === 'pending');
75
+ }
76
+ /**
77
+ * Send a message between agents
78
+ */
79
+ sendMessage(message) {
80
+ this.messageQueue.push(message);
81
+ this.processMessage(message);
82
+ }
83
+ /**
84
+ * Get message history for an agent
85
+ */
86
+ getAgentMessages(agentId) {
87
+ return this.messageQueue.filter(m => m.from === agentId || m.to === agentId || m.to === 'broadcast');
88
+ }
89
+ /**
90
+ * Force consensus on a session
91
+ */
92
+ forceConsensus(sessionId) {
93
+ const session = this.sessions.get(sessionId);
94
+ if (!session || session.results.length === 0)
95
+ return null;
96
+ return this.buildConsensus(session);
97
+ }
98
+ /**
99
+ * Process task queue
100
+ */
101
+ processTaskQueue() {
102
+ const activeSessions = this.getActiveSessions().length;
103
+ if (activeSessions >= this.options.maxConcurrentSessions)
104
+ return;
105
+ const pendingTasks = this.taskQueue.filter(t => !Array.from(this.sessions.values()).some(s => s.task.id === t.id));
106
+ for (const task of pendingTasks) {
107
+ if (activeSessions >= this.options.maxConcurrentSessions)
108
+ break;
109
+ const availableAgents = this.getAvailableAgents(task.requiredCapabilities);
110
+ if (availableAgents.length === 0)
111
+ continue;
112
+ const selectedAgents = availableAgents.slice(0, task.maxAgents || availableAgents.length);
113
+ this.startSession(task, selectedAgents.map(a => a.id));
114
+ }
115
+ }
116
+ /**
117
+ * Start a collaboration session
118
+ */
119
+ startSession(task, agentIds) {
120
+ const session = {
121
+ id: `session-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
122
+ task,
123
+ agents: agentIds,
124
+ results: [],
125
+ status: 'in_progress',
126
+ startedAt: new Date()
127
+ };
128
+ this.sessions.set(session.id, session);
129
+ // Mark agents as busy
130
+ agentIds.forEach(id => this.updateAgentStatus(id, 'busy'));
131
+ // Delegate task to agents
132
+ this.delegateTask(session);
133
+ }
134
+ /**
135
+ * Delegate task to agents
136
+ */
137
+ delegateTask(session) {
138
+ // In a real implementation, this would send messages to agents
139
+ // For now, we'll simulate agent responses
140
+ for (const agentId of session.agents) {
141
+ this.simulateAgentResponse(session, agentId);
142
+ }
143
+ }
144
+ /**
145
+ * Simulate agent response (for demo purposes)
146
+ */
147
+ simulateAgentResponse(session, agentId) {
148
+ const agent = this.agents.get(agentId);
149
+ if (!agent)
150
+ return;
151
+ // Simulate processing time
152
+ setTimeout(() => {
153
+ const result = {
154
+ taskId: session.task.id,
155
+ agentId,
156
+ status: 'completed',
157
+ output: {
158
+ analysis: `${agent.type} analysis complete`,
159
+ findings: [],
160
+ recommendations: [`${agent.type} recommendation`]
161
+ },
162
+ confidence: 0.8 + Math.random() * 0.2,
163
+ recommendations: [`Action from ${agent.name}`],
164
+ timestamp: new Date(),
165
+ executionTimeMs: Math.floor(Math.random() * 5000)
166
+ };
167
+ this.addResult(session.id, result);
168
+ }, Math.random() * 2000);
169
+ }
170
+ /**
171
+ * Add result to session
172
+ */
173
+ addResult(sessionId, result) {
174
+ const session = this.sessions.get(sessionId);
175
+ if (!session)
176
+ return;
177
+ session.results.push(result);
178
+ // Check if all agents have responded
179
+ if (session.results.length === session.agents.length) {
180
+ this.completeSession(session);
181
+ }
182
+ }
183
+ /**
184
+ * Complete a session
185
+ */
186
+ completeSession(session) {
187
+ // Build consensus if required
188
+ if (session.task.consensusRequired) {
189
+ session.consensus = this.buildConsensus(session);
190
+ }
191
+ session.status = 'completed';
192
+ session.completedAt = new Date();
193
+ // Mark agents as idle
194
+ session.agents.forEach(id => this.updateAgentStatus(id, 'idle'));
195
+ // Process next task in queue
196
+ this.processTaskQueue();
197
+ }
198
+ /**
199
+ * Build consensus from results
200
+ */
201
+ buildConsensus(session) {
202
+ const results = session.results;
203
+ // Simple majority voting for recommendations
204
+ const recommendationCounts = new Map();
205
+ results.forEach(r => {
206
+ r.recommendations.forEach(rec => {
207
+ recommendationCounts.set(rec, (recommendationCounts.get(rec) || 0) + 1);
208
+ });
209
+ });
210
+ const sortedRecommendations = Array.from(recommendationCounts.entries())
211
+ .sort((a, b) => b[1] - a[1]);
212
+ const totalVotes = results.length;
213
+ const topRecommendation = sortedRecommendations[0];
214
+ const agreementLevel = topRecommendation ? topRecommendation[1] / totalVotes : 0;
215
+ return {
216
+ achieved: agreementLevel >= this.options.consensusThreshold,
217
+ agreementLevel,
218
+ finalRecommendation: topRecommendation ? topRecommendation[0] : 'No consensus',
219
+ dissentingViews: sortedRecommendations.slice(1).map(r => r[0]),
220
+ resolutionStrategy: 'majority'
221
+ };
222
+ }
223
+ /**
224
+ * Process incoming message
225
+ */
226
+ processMessage(message) {
227
+ if (message.to === 'broadcast') {
228
+ // Broadcast to all agents except sender
229
+ this.agents.forEach((agent, id) => {
230
+ if (id !== message.from) {
231
+ // In real implementation, would deliver to agent
232
+ }
233
+ });
234
+ }
235
+ else {
236
+ // Direct message to specific agent
237
+ const agent = this.agents.get(message.to);
238
+ if (agent) {
239
+ // In real implementation, would deliver to agent
240
+ }
241
+ }
242
+ }
243
+ }
244
+ exports.AgentCollaboration = AgentCollaboration;
245
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;;AAgEH,MAAa,kBAAkB;IAOV;IANX,MAAM,GAAuB,IAAI,GAAG,EAAE,CAAC;IACvC,QAAQ,GAAsC,IAAI,GAAG,EAAE,CAAC;IACxD,YAAY,GAAmB,EAAE,CAAC;IAClC,SAAS,GAAwB,EAAE,CAAC;IAE5C,YACmB,UAIb,EAAE;QAJW,YAAO,GAAP,OAAO,CAIlB;QAEN,IAAI,CAAC,OAAO,GAAG;YACb,qBAAqB,EAAE,EAAE;YACzB,gBAAgB,EAAE,MAAM,EAAE,YAAY;YACtC,kBAAkB,EAAE,GAAG;YACvB,GAAG,OAAO;SACX,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,aAAa,CAAC,KAAY;QACxB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;IACnC,CAAC;IAED;;OAEG;IACH,iBAAiB,CAAC,EAAU,EAAE,MAAuB;QACnD,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAClC,IAAI,KAAK,EAAE,CAAC;YACV,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC;YACtB,KAAK,CAAC,UAAU,GAAG,I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IAAI,CAAC,OAAO,CAAC,kBAAmB;YAC5D,cAAc;YACd,mBAAmB,EAAE,iBAAiB,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,cAAc;YAC9E,eAAe,EAAE,qBAAqB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC9D,kBAAkB,EAAE,UAAU;SAC/B,CAAC;IACJ,CAAC;IAED;;OAEG;IACK,cAAc,CAAC,OAAqB;QAC1C,IAAI,OAAO,CAAC,EAAE,KAAK,WAAW,EAAE,CAAC;YAC/B,wCAAwC;YACxC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE;gBAChC,IAAI,EAAE,KAAK,OAAO,CAAC,IAAI,EAAE,CAAC;oBACxB,iDAAiD;gBACnD,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;aAAM,CAAC;YACN,mCAAmC;YACnC,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YAC1C,IAAI,KAAK,EAAE,CAAC;gBACV,iDAAiD;YACnD,CAAC;QACH,CAAC;IACH,CAAC;CACF;AA3QD,gDA2QC"}
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@grc-claw/agent-collaboration",
3
+ "version": "0.8.0",
4
+ "description": "Multi-agent orchestration for complex GRC tasks",
5
+ "license": "MIT",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "test": "node --test dist/**/*.test.js"
14
+ },
15
+ "dependencies": {},
16
+ "devDependencies": {
17
+ "typescript": "^5.7.0"
18
+ }
19
+ }
package/src/index.ts ADDED
@@ -0,0 +1,345 @@
1
+ /**
2
+ * AgentCollaboration - Multi-agent orchestration for complex GRC tasks
3
+ *
4
+ * Enables specialized agents (compliance, security, risk, audit) to collaborate
5
+ * on complex tasks that require domain expertise from multiple areas.
6
+ *
7
+ * Features:
8
+ * - Task decomposition and delegation
9
+ * - Inter-agent communication protocol
10
+ * - Consensus building for conflicting recommendations
11
+ * - Parallel execution with result aggregation
12
+ * - Conflict resolution strategies
13
+ * - Agent capability matching
14
+ */
15
+
16
+ export interface Agent {
17
+ id: string;
18
+ name: string;
19
+ type: 'compliance' | 'security' | 'risk' | 'audit' | 'evidence' | 'remediation';
20
+ capabilities: string[];
21
+ status: 'idle' | 'busy' | 'offline';
22
+ currentTask?: string;
23
+ trustScore: number;
24
+ lastActive: Date;
25
+ }
26
+
27
+ export interface CollaborationTask {
28
+ id: string;
29
+ type: string;
30
+ priority: 'critical' | 'high' | 'medium' | 'low';
31
+ requiredCapabilities: string[];
32
+ input: Record<string, unknown>;
33
+ deadline?: Date;
34
+ maxAgents?: number;
35
+ consensusRequired?: boolean;
36
+ }
37
+
38
+ export interface TaskResult {
39
+ taskId: string;
40
+ agentId: string;
41
+ status: 'completed' | 'failed' | 'partial';
42
+ output: Record<string, unknown>;
43
+ confidence: number; // 0-1
44
+ recommendations: string[];
45
+ timestamp: Date;
46
+ executionTimeMs: number;
47
+ }
48
+
49
+ export interface CollaborationSession {
50
+ id: string;
51
+ task: CollaborationTask;
52
+ agents: string[];
53
+ results: TaskResult[];
54
+ consensus?: ConsensusResult;
55
+ status: 'pending' | 'in_progress' | 'completed' | 'failed';
56
+ startedAt: Date;
57
+ completedAt?: Date;
58
+ }
59
+
60
+ export interface ConsensusResult {
61
+ achieved: boolean;
62
+ agreementLevel: number; // 0-1
63
+ finalRecommendation: string;
64
+ dissentingViews: string[];
65
+ resolutionStrategy: 'majority' | 'weighted' | 'expert' | 'compromise';
66
+ }
67
+
68
+ export interface AgentMessage {
69
+ id: string;
70
+ from: string;
71
+ to: string | 'broadcast';
72
+ type: 'request' | 'response' | 'update' | 'alert';
73
+ payload: Record<string, unknown>;
74
+ timestamp: Date;
75
+ requiresResponse: boolean;
76
+ }
77
+
78
+ export class AgentCollaboration {
79
+ private agents: Map<string, Agent> = new Map();
80
+ private sessions: Map<string, CollaborationSession> = new Map();
81
+ private messageQueue: AgentMessage[] = [];
82
+ private taskQueue: CollaborationTask[] = [];
83
+
84
+ constructor(
85
+ private readonly options: {
86
+ maxConcurrentSessions?: number;
87
+ defaultTimeoutMs?: number;
88
+ consensusThreshold?: number;
89
+ } = {}
90
+ ) {
91
+ this.options = {
92
+ maxConcurrentSessions: 10,
93
+ defaultTimeoutMs: 300000, // 5 minutes
94
+ consensusThreshold: 0.7,
95
+ ...options
96
+ };
97
+ }
98
+
99
+ /**
100
+ * Register an agent
101
+ */
102
+ registerAgent(agent: Agent): void {
103
+ this.agents.set(agent.id, agent);
104
+ }
105
+
106
+ /**
107
+ * Update agent status
108
+ */
109
+ updateAgentStatus(id: string, status: Agent['status']): void {
110
+ const agent = this.agents.get(id);
111
+ if (agent) {
112
+ agent.status = status;
113
+ agent.lastActive = new Date();
114
+ }
115
+ }
116
+
117
+ /**
118
+ * Get available agents for a task
119
+ */
120
+ getAvailableAgents(requiredCapabilities: string[]): Agent[] {
121
+ return Array.from(this.agents.values()).filter(agent =>
122
+ agent.status === 'idle' &&
123
+ requiredCapabilities.every(cap => agent.capabilities.includes(cap))
124
+ );
125
+ }
126
+
127
+ /**
128
+ * Submit a task for collaboration
129
+ */
130
+ submitTask(task: CollaborationTask): string {
131
+ this.taskQueue.push(task);
132
+ this.processTaskQueue();
133
+ return task.id;
134
+ }
135
+
136
+ /**
137
+ * Get session status
138
+ */
139
+ getSession(sessionId: string): CollaborationSession | undefined {
140
+ return this.sessions.get(sessionId);
141
+ }
142
+
143
+ /**
144
+ * Get all active sessions
145
+ */
146
+ getActiveSessions(): CollaborationSession[] {
147
+ return Array.from(this.sessions.values()).filter(s =>
148
+ s.status === 'in_progress' || s.status === 'pending'
149
+ );
150
+ }
151
+
152
+ /**
153
+ * Send a message between agents
154
+ */
155
+ sendMessage(message: AgentMessage): void {
156
+ this.messageQueue.push(message);
157
+ this.processMessage(message);
158
+ }
159
+
160
+ /**
161
+ * Get message history for an agent
162
+ */
163
+ getAgentMessages(agentId: string): AgentMessage[] {
164
+ return this.messageQueue.filter(m =>
165
+ m.from === agentId || m.to === agentId || m.to === 'broadcast'
166
+ );
167
+ }
168
+
169
+ /**
170
+ * Force consensus on a session
171
+ */
172
+ forceConsensus(sessionId: string): ConsensusResult | null {
173
+ const session = this.sessions.get(sessionId);
174
+ if (!session || session.results.length === 0) return null;
175
+
176
+ return this.buildConsensus(session);
177
+ }
178
+
179
+ /**
180
+ * Process task queue
181
+ */
182
+ private processTaskQueue(): void {
183
+ const activeSessions = this.getActiveSessions().length;
184
+ if (activeSessions >= this.options.maxConcurrentSessions!) return;
185
+
186
+ const pendingTasks = this.taskQueue.filter(t =>
187
+ !Array.from(this.sessions.values()).some(s => s.task.id === t.id)
188
+ );
189
+
190
+ for (const task of pendingTasks) {
191
+ if (activeSessions >= this.options.maxConcurrentSessions!) break;
192
+
193
+ const availableAgents = this.getAvailableAgents(task.requiredCapabilities);
194
+ if (availableAgents.length === 0) continue;
195
+
196
+ const selectedAgents = availableAgents.slice(0, task.maxAgents || availableAgents.length);
197
+ this.startSession(task, selectedAgents.map(a => a.id));
198
+ }
199
+ }
200
+
201
+ /**
202
+ * Start a collaboration session
203
+ */
204
+ private startSession(task: CollaborationTask, agentIds: string[]): void {
205
+ const session: CollaborationSession = {
206
+ id: `session-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
207
+ task,
208
+ agents: agentIds,
209
+ results: [],
210
+ status: 'in_progress',
211
+ startedAt: new Date()
212
+ };
213
+
214
+ this.sessions.set(session.id, session);
215
+
216
+ // Mark agents as busy
217
+ agentIds.forEach(id => this.updateAgentStatus(id, 'busy'));
218
+
219
+ // Delegate task to agents
220
+ this.delegateTask(session);
221
+ }
222
+
223
+ /**
224
+ * Delegate task to agents
225
+ */
226
+ private delegateTask(session: CollaborationSession): void {
227
+ // In a real implementation, this would send messages to agents
228
+ // For now, we'll simulate agent responses
229
+ for (const agentId of session.agents) {
230
+ this.simulateAgentResponse(session, agentId);
231
+ }
232
+ }
233
+
234
+ /**
235
+ * Simulate agent response (for demo purposes)
236
+ */
237
+ private simulateAgentResponse(session: CollaborationSession, agentId: string): void {
238
+ const agent = this.agents.get(agentId);
239
+ if (!agent) return;
240
+
241
+ // Simulate processing time
242
+ setTimeout(() => {
243
+ const result: TaskResult = {
244
+ taskId: session.task.id,
245
+ agentId,
246
+ status: 'completed',
247
+ output: {
248
+ analysis: `${agent.type} analysis complete`,
249
+ findings: [],
250
+ recommendations: [`${agent.type} recommendation`]
251
+ },
252
+ confidence: 0.8 + Math.random() * 0.2,
253
+ recommendations: [`Action from ${agent.name}`],
254
+ timestamp: new Date(),
255
+ executionTimeMs: Math.floor(Math.random() * 5000)
256
+ };
257
+
258
+ this.addResult(session.id, result);
259
+ }, Math.random() * 2000);
260
+ }
261
+
262
+ /**
263
+ * Add result to session
264
+ */
265
+ private addResult(sessionId: string, result: TaskResult): void {
266
+ const session = this.sessions.get(sessionId);
267
+ if (!session) return;
268
+
269
+ session.results.push(result);
270
+
271
+ // Check if all agents have responded
272
+ if (session.results.length === session.agents.length) {
273
+ this.completeSession(session);
274
+ }
275
+ }
276
+
277
+ /**
278
+ * Complete a session
279
+ */
280
+ private completeSession(session: CollaborationSession): void {
281
+ // Build consensus if required
282
+ if (session.task.consensusRequired) {
283
+ session.consensus = this.buildConsensus(session);
284
+ }
285
+
286
+ session.status = 'completed';
287
+ session.completedAt = new Date();
288
+
289
+ // Mark agents as idle
290
+ session.agents.forEach(id => this.updateAgentStatus(id, 'idle'));
291
+
292
+ // Process next task in queue
293
+ this.processTaskQueue();
294
+ }
295
+
296
+ /**
297
+ * Build consensus from results
298
+ */
299
+ private buildConsensus(session: CollaborationSession): ConsensusResult {
300
+ const results = session.results;
301
+
302
+ // Simple majority voting for recommendations
303
+ const recommendationCounts = new Map<string, number>();
304
+ results.forEach(r => {
305
+ r.recommendations.forEach(rec => {
306
+ recommendationCounts.set(rec, (recommendationCounts.get(rec) || 0) + 1);
307
+ });
308
+ });
309
+
310
+ const sortedRecommendations = Array.from(recommendationCounts.entries())
311
+ .sort((a, b) => b[1] - a[1]);
312
+
313
+ const totalVotes = results.length;
314
+ const topRecommendation = sortedRecommendations[0];
315
+ const agreementLevel = topRecommendation ? topRecommendation[1] / totalVotes : 0;
316
+
317
+ return {
318
+ achieved: agreementLevel >= this.options.consensusThreshold!,
319
+ agreementLevel,
320
+ finalRecommendation: topRecommendation ? topRecommendation[0] : 'No consensus',
321
+ dissentingViews: sortedRecommendations.slice(1).map(r => r[0]),
322
+ resolutionStrategy: 'majority'
323
+ };
324
+ }
325
+
326
+ /**
327
+ * Process incoming message
328
+ */
329
+ private processMessage(message: AgentMessage): void {
330
+ if (message.to === 'broadcast') {
331
+ // Broadcast to all agents except sender
332
+ this.agents.forEach((agent, id) => {
333
+ if (id !== message.from) {
334
+ // In real implementation, would deliver to agent
335
+ }
336
+ });
337
+ } else {
338
+ // Direct message to specific agent
339
+ const agent = this.agents.get(message.to);
340
+ if (agent) {
341
+ // In real implementation, would deliver to agent
342
+ }
343
+ }
344
+ }
345
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist",
6
+ "composite": true
7
+ },
8
+ "include": ["src/**/*"]
9
+ }