@wundr.io/autogen-orchestrator 1.0.3 → 1.0.12
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 +74 -88
- package/package.json +9 -6
- package/src/group-chat.ts +29 -43
- package/src/nested-chat.ts +17 -17
- package/src/speaker-selection.ts +42 -42
- package/src/termination.ts +17 -17
- package/src/types.ts +4 -4
- package/dist/group-chat.d.ts +0 -327
- package/dist/group-chat.d.ts.map +0 -1
- package/dist/group-chat.js +0 -724
- package/dist/group-chat.js.map +0 -1
- package/dist/index.d.ts +0 -16
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -69
- package/dist/index.js.map +0 -1
- package/dist/nested-chat.d.ts +0 -296
- package/dist/nested-chat.d.ts.map +0 -1
- package/dist/nested-chat.js +0 -600
- package/dist/nested-chat.js.map +0 -1
- package/dist/speaker-selection.d.ts +0 -195
- package/dist/speaker-selection.d.ts.map +0 -1
- package/dist/speaker-selection.js +0 -569
- package/dist/speaker-selection.js.map +0 -1
- package/dist/termination.d.ts +0 -237
- package/dist/termination.d.ts.map +0 -1
- package/dist/termination.js +0 -566
- package/dist/termination.js.map +0 -1
- package/dist/types.d.ts +0 -1248
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -201
- package/dist/types.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# @wundr.io/autogen-orchestrator
|
|
2
2
|
|
|
3
|
-
AutoGen-style conversational multi-agent orchestration for the Wundr platform. This package
|
|
3
|
+
AutoGen-style conversational multi-agent orchestration for the Wundr platform. This package
|
|
4
|
+
implements sophisticated patterns for coordinating multiple AI agents in group chat settings with
|
|
5
|
+
configurable speaker selection, termination conditions, and nested chat support.
|
|
4
6
|
|
|
5
7
|
## Table of Contents
|
|
6
8
|
|
|
@@ -45,11 +47,11 @@ const analyst = createParticipant(
|
|
|
45
47
|
['analysis', 'research', 'data']
|
|
46
48
|
);
|
|
47
49
|
|
|
48
|
-
const developer = createParticipant(
|
|
49
|
-
'
|
|
50
|
-
'
|
|
51
|
-
|
|
52
|
-
);
|
|
50
|
+
const developer = createParticipant('Developer', 'You are a senior software developer.', [
|
|
51
|
+
'coding',
|
|
52
|
+
'architecture',
|
|
53
|
+
'debugging',
|
|
54
|
+
]);
|
|
53
55
|
|
|
54
56
|
const reviewer = createParticipant(
|
|
55
57
|
'Reviewer',
|
|
@@ -134,9 +136,9 @@ import { Message, MessageRole, ContentType } from '@wundr.io/autogen-orchestrato
|
|
|
134
136
|
// Message structure
|
|
135
137
|
interface Message {
|
|
136
138
|
id: string;
|
|
137
|
-
role: MessageRole;
|
|
139
|
+
role: MessageRole; // 'system' | 'user' | 'assistant' | 'function'
|
|
138
140
|
content: string;
|
|
139
|
-
name: string;
|
|
141
|
+
name: string; // Sender name
|
|
140
142
|
timestamp: Date;
|
|
141
143
|
contentType?: ContentType; // 'text' | 'code' | 'image' | 'function_call' | 'function_result'
|
|
142
144
|
functionCall?: FunctionCall;
|
|
@@ -158,8 +160,8 @@ interface ChatContext {
|
|
|
158
160
|
currentSpeaker?: string;
|
|
159
161
|
previousSpeaker?: string;
|
|
160
162
|
startTime: Date;
|
|
161
|
-
state: Record<string, unknown>;
|
|
162
|
-
parentContext?: ChatContext;
|
|
163
|
+
state: Record<string, unknown>; // Custom state storage
|
|
164
|
+
parentContext?: ChatContext; // For nested chats
|
|
163
165
|
}
|
|
164
166
|
```
|
|
165
167
|
|
|
@@ -196,9 +198,9 @@ const chat = new GroupChatManager({
|
|
|
196
198
|
{ from: 'Specialist', to: ['Leader', 'Assistant'], weight: 0.5 },
|
|
197
199
|
],
|
|
198
200
|
allowedTransitions: {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
201
|
+
Leader: ['Specialist', 'Assistant'],
|
|
202
|
+
Specialist: ['Leader'],
|
|
203
|
+
Assistant: ['Leader', 'Specialist'],
|
|
202
204
|
},
|
|
203
205
|
},
|
|
204
206
|
});
|
|
@@ -229,9 +231,7 @@ const chat = new GroupChatBuilder()
|
|
|
229
231
|
Automatically chooses the best selection strategy:
|
|
230
232
|
|
|
231
233
|
```typescript
|
|
232
|
-
const chat = new GroupChatBuilder()
|
|
233
|
-
.withSpeakerSelection('auto')
|
|
234
|
-
.build();
|
|
234
|
+
const chat = new GroupChatBuilder().withSpeakerSelection('auto').build();
|
|
235
235
|
|
|
236
236
|
// Strategy selection logic:
|
|
237
237
|
// - Uses 'priority' if transition rules are configured
|
|
@@ -389,12 +389,7 @@ const selector = createSpeakerSelector('llm_selected');
|
|
|
389
389
|
const manager = new SpeakerSelectionManager('round_robin');
|
|
390
390
|
|
|
391
391
|
// Select next speaker
|
|
392
|
-
const result = await manager.selectSpeaker(
|
|
393
|
-
participants,
|
|
394
|
-
messages,
|
|
395
|
-
context,
|
|
396
|
-
selectionConfig
|
|
397
|
-
);
|
|
392
|
+
const result = await manager.selectSpeaker(participants, messages, context, selectionConfig);
|
|
398
393
|
|
|
399
394
|
console.log(result);
|
|
400
395
|
// {
|
|
@@ -471,9 +466,9 @@ const config: SpeakerSelectionConfig = {
|
|
|
471
466
|
},
|
|
472
467
|
],
|
|
473
468
|
allowedTransitions: {
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
469
|
+
Manager: ['Developer', 'Tester'],
|
|
470
|
+
Developer: ['Tester', 'Manager'],
|
|
471
|
+
Tester: ['Developer', 'Manager'],
|
|
477
472
|
},
|
|
478
473
|
};
|
|
479
474
|
```
|
|
@@ -706,10 +701,7 @@ Nested chats allow focused sub-discussions within a main conversation.
|
|
|
706
701
|
### Configuration
|
|
707
702
|
|
|
708
703
|
```typescript
|
|
709
|
-
import {
|
|
710
|
-
NestedChatManager,
|
|
711
|
-
NestedChatConfigBuilder,
|
|
712
|
-
} from '@wundr.io/autogen-orchestrator';
|
|
704
|
+
import { NestedChatManager, NestedChatConfigBuilder } from '@wundr.io/autogen-orchestrator';
|
|
713
705
|
|
|
714
706
|
// Using the builder
|
|
715
707
|
const nestedConfig = new NestedChatConfigBuilder()
|
|
@@ -738,9 +730,7 @@ const chat = new GroupChatBuilder()
|
|
|
738
730
|
|
|
739
731
|
```typescript
|
|
740
732
|
// Keyword trigger
|
|
741
|
-
new NestedChatConfigBuilder()
|
|
742
|
-
.withKeywordTrigger(['review code', 'code review'])
|
|
743
|
-
.build();
|
|
733
|
+
new NestedChatConfigBuilder().withKeywordTrigger(['review code', 'code review']).build();
|
|
744
734
|
|
|
745
735
|
// Participant trigger
|
|
746
736
|
new NestedChatConfigBuilder()
|
|
@@ -755,9 +745,7 @@ new NestedChatConfigBuilder()
|
|
|
755
745
|
.build();
|
|
756
746
|
|
|
757
747
|
// Manual trigger
|
|
758
|
-
new NestedChatConfigBuilder()
|
|
759
|
-
.withManualTrigger('startNestedDiscussion')
|
|
760
|
-
.build();
|
|
748
|
+
new NestedChatConfigBuilder().withManualTrigger('startNestedDiscussion').build();
|
|
761
749
|
|
|
762
750
|
// Trigger manually via state
|
|
763
751
|
chat.updateState('startNestedDiscussion', true);
|
|
@@ -771,9 +759,7 @@ chat.updateState('startNestedDiscussion', true);
|
|
|
771
759
|
// 'reflection' - Structured reflection summary
|
|
772
760
|
// 'custom' - Custom summary logic
|
|
773
761
|
|
|
774
|
-
const config = new NestedChatConfigBuilder()
|
|
775
|
-
.withSummaryMethod('reflection')
|
|
776
|
-
.build();
|
|
762
|
+
const config = new NestedChatConfigBuilder().withSummaryMethod('reflection').build();
|
|
777
763
|
```
|
|
778
764
|
|
|
779
765
|
### Nested Chat Events
|
|
@@ -799,7 +785,7 @@ import { TaskOrchestrator } from '@wundr.io/task-orchestrator';
|
|
|
799
785
|
const taskOrchestrator = new TaskOrchestrator();
|
|
800
786
|
|
|
801
787
|
// Create a chat for each complex task
|
|
802
|
-
taskOrchestrator.on('task:complex', async
|
|
788
|
+
taskOrchestrator.on('task:complex', async task => {
|
|
803
789
|
const chat = new GroupChatBuilder()
|
|
804
790
|
.withName(`Task: ${task.name}`)
|
|
805
791
|
.withParticipant(createParticipant('Planner', 'Plan the task execution'))
|
|
@@ -896,65 +882,65 @@ class AgentEventBridge extends EventEmitter {
|
|
|
896
882
|
|
|
897
883
|
### GroupChatManager
|
|
898
884
|
|
|
899
|
-
| Method
|
|
900
|
-
|
|
901
|
-
| `constructor(config: GroupChatConfig)`
|
|
902
|
-
| `setResponseGenerator(generator: ResponseGenerator)`
|
|
903
|
-
| `start(options?: StartChatOptions)`
|
|
904
|
-
| `pause()`
|
|
905
|
-
| `resume()`
|
|
906
|
-
| `stop(reason?: string)`
|
|
907
|
-
| `addMessage(options: CreateMessageOptions)`
|
|
908
|
-
| `addParticipant(options: AddParticipantOptions)`
|
|
909
|
-
| `removeParticipant(name: string)`
|
|
910
|
-
| `updateParticipantStatus(name: string, status: ParticipantStatus)` | Update participant status
|
|
911
|
-
| `addTerminationCondition(condition: TerminationCondition)`
|
|
912
|
-
| `addNestedChatConfig(config: NestedChatConfig)`
|
|
913
|
-
| `getStatus()`
|
|
914
|
-
| `getChatId()`
|
|
915
|
-
| `getMessages()`
|
|
916
|
-
| `getParticipants()`
|
|
917
|
-
| `getContext()`
|
|
918
|
-
| `getMetrics()`
|
|
919
|
-
| `updateState(key: string, value: T)`
|
|
920
|
-
| `getState<T>(key: string)`
|
|
885
|
+
| Method | Description |
|
|
886
|
+
| ------------------------------------------------------------------ | ------------------------------ |
|
|
887
|
+
| `constructor(config: GroupChatConfig)` | Create a new chat manager |
|
|
888
|
+
| `setResponseGenerator(generator: ResponseGenerator)` | Set the LLM response generator |
|
|
889
|
+
| `start(options?: StartChatOptions)` | Start the conversation |
|
|
890
|
+
| `pause()` | Pause the conversation |
|
|
891
|
+
| `resume()` | Resume a paused conversation |
|
|
892
|
+
| `stop(reason?: string)` | Stop the conversation |
|
|
893
|
+
| `addMessage(options: CreateMessageOptions)` | Add a message |
|
|
894
|
+
| `addParticipant(options: AddParticipantOptions)` | Add a participant |
|
|
895
|
+
| `removeParticipant(name: string)` | Remove a participant |
|
|
896
|
+
| `updateParticipantStatus(name: string, status: ParticipantStatus)` | Update participant status |
|
|
897
|
+
| `addTerminationCondition(condition: TerminationCondition)` | Add termination condition |
|
|
898
|
+
| `addNestedChatConfig(config: NestedChatConfig)` | Add nested chat configuration |
|
|
899
|
+
| `getStatus()` | Get current chat status |
|
|
900
|
+
| `getChatId()` | Get the chat ID |
|
|
901
|
+
| `getMessages()` | Get all messages |
|
|
902
|
+
| `getParticipants()` | Get all participants |
|
|
903
|
+
| `getContext()` | Get current context |
|
|
904
|
+
| `getMetrics()` | Get chat metrics |
|
|
905
|
+
| `updateState(key: string, value: T)` | Update context state |
|
|
906
|
+
| `getState<T>(key: string)` | Get context state value |
|
|
921
907
|
|
|
922
908
|
### SpeakerSelectionManager
|
|
923
909
|
|
|
924
|
-
| Method
|
|
925
|
-
|
|
926
|
-
| `constructor(method?: SpeakerSelectionMethod)`
|
|
927
|
-
| `selectSpeaker(participants, messages, context, config?)` | Select next speaker
|
|
928
|
-
| `setMethod(method: SpeakerSelectionMethod)`
|
|
929
|
-
| `getMethod()`
|
|
930
|
-
| `getStrategy(method: SpeakerSelectionMethod)`
|
|
910
|
+
| Method | Description |
|
|
911
|
+
| --------------------------------------------------------- | -------------------------- |
|
|
912
|
+
| `constructor(method?: SpeakerSelectionMethod)` | Create with initial method |
|
|
913
|
+
| `selectSpeaker(participants, messages, context, config?)` | Select next speaker |
|
|
914
|
+
| `setMethod(method: SpeakerSelectionMethod)` | Change selection method |
|
|
915
|
+
| `getMethod()` | Get current method |
|
|
916
|
+
| `getStrategy(method: SpeakerSelectionMethod)` | Get strategy instance |
|
|
931
917
|
|
|
932
918
|
### TerminationManager
|
|
933
919
|
|
|
934
|
-
| Method
|
|
935
|
-
|
|
920
|
+
| Method | Description |
|
|
921
|
+
| -------------------------------------------------- | ------------------------------ |
|
|
936
922
|
| `constructor(conditions?: TerminationCondition[])` | Create with initial conditions |
|
|
937
|
-
| `addCondition(condition: TerminationCondition)`
|
|
938
|
-
| `removeCondition(type: TerminationConditionType)`
|
|
939
|
-
| `clearConditions()`
|
|
940
|
-
| `evaluate(messages, participants, context)`
|
|
941
|
-
| `getConditions()`
|
|
942
|
-
| `hasCondition(type: TerminationConditionType)`
|
|
923
|
+
| `addCondition(condition: TerminationCondition)` | Add a condition |
|
|
924
|
+
| `removeCondition(type: TerminationConditionType)` | Remove conditions by type |
|
|
925
|
+
| `clearConditions()` | Clear all conditions |
|
|
926
|
+
| `evaluate(messages, participants, context)` | Evaluate all conditions |
|
|
927
|
+
| `getConditions()` | Get all conditions |
|
|
928
|
+
| `hasCondition(type: TerminationConditionType)` | Check if type exists |
|
|
943
929
|
|
|
944
930
|
### NestedChatManager
|
|
945
931
|
|
|
946
|
-
| Method
|
|
947
|
-
|
|
948
|
-
| `constructor(configs?: NestedChatConfig[])`
|
|
949
|
-
| `addConfig(config: NestedChatConfig)`
|
|
950
|
-
| `removeConfig(configId: string)`
|
|
951
|
-
| `checkTrigger(message, participants, context)`
|
|
952
|
-
| `startNestedChat(config, parentChatId, parentMessageId, participants, context)` | Start nested chat
|
|
953
|
-
| `addMessage(nestedChatId: string, message: Message)`
|
|
954
|
-
| `endNestedChat(nestedChatId, status?, reason?)`
|
|
955
|
-
| `getActiveChats()`
|
|
956
|
-
| `getCompletedChats()`
|
|
957
|
-
| `hasActiveChats()`
|
|
932
|
+
| Method | Description |
|
|
933
|
+
| ------------------------------------------------------------------------------- | --------------------------- |
|
|
934
|
+
| `constructor(configs?: NestedChatConfig[])` | Create with initial configs |
|
|
935
|
+
| `addConfig(config: NestedChatConfig)` | Add configuration |
|
|
936
|
+
| `removeConfig(configId: string)` | Remove configuration |
|
|
937
|
+
| `checkTrigger(message, participants, context)` | Check for triggers |
|
|
938
|
+
| `startNestedChat(config, parentChatId, parentMessageId, participants, context)` | Start nested chat |
|
|
939
|
+
| `addMessage(nestedChatId: string, message: Message)` | Add message to nested chat |
|
|
940
|
+
| `endNestedChat(nestedChatId, status?, reason?)` | End nested chat |
|
|
941
|
+
| `getActiveChats()` | Get active nested chat IDs |
|
|
942
|
+
| `getCompletedChats()` | Get completed results |
|
|
943
|
+
| `hasActiveChats()` | Check for active chats |
|
|
958
944
|
|
|
959
945
|
## Examples
|
|
960
946
|
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wundr.io/autogen-orchestrator",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"description": "AutoGen-style conversational multi-agent orchestration for the Wundr platform",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
-
"files": [
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"src"
|
|
10
|
+
],
|
|
8
11
|
"scripts": {
|
|
9
12
|
"build": "tsc",
|
|
10
13
|
"build:watch": "tsc --watch",
|
|
@@ -20,9 +23,9 @@
|
|
|
20
23
|
"typecheck": "tsc --noEmit"
|
|
21
24
|
},
|
|
22
25
|
"dependencies": {
|
|
23
|
-
"
|
|
26
|
+
"eventemitter3": "^5.0.1",
|
|
24
27
|
"uuid": "^11.0.3",
|
|
25
|
-
"
|
|
28
|
+
"zod": "^3.25.76"
|
|
26
29
|
},
|
|
27
30
|
"devDependencies": {
|
|
28
31
|
"@types/node": "^20.9.0",
|
|
@@ -31,9 +34,9 @@
|
|
|
31
34
|
"@typescript-eslint/parser": "^8.44.0",
|
|
32
35
|
"eslint": "^8.57.1",
|
|
33
36
|
"jest": "^29.7.0",
|
|
37
|
+
"prettier": "^3.3.3",
|
|
34
38
|
"ts-jest": "^29.4.1",
|
|
35
|
-
"typescript": "^5.2.2"
|
|
36
|
-
"prettier": "^3.3.3"
|
|
39
|
+
"typescript": "^5.2.2"
|
|
37
40
|
},
|
|
38
41
|
"publishConfig": {
|
|
39
42
|
"access": "public"
|
package/src/group-chat.ts
CHANGED
|
@@ -101,7 +101,7 @@ export class GroupChatManager extends EventEmitter<GroupChatEvents> {
|
|
|
101
101
|
const validationResult = GroupChatConfigSchema.safeParse(config);
|
|
102
102
|
if (!validationResult.success) {
|
|
103
103
|
throw new Error(
|
|
104
|
-
`Invalid GroupChatConfig: ${validationResult.error.message}
|
|
104
|
+
`Invalid GroupChatConfig: ${validationResult.error.message}`
|
|
105
105
|
);
|
|
106
106
|
}
|
|
107
107
|
|
|
@@ -125,13 +125,13 @@ export class GroupChatManager extends EventEmitter<GroupChatEvents> {
|
|
|
125
125
|
|
|
126
126
|
// Initialize managers
|
|
127
127
|
this.speakerManager = new SpeakerSelectionManager(
|
|
128
|
-
config.speakerSelectionMethod
|
|
128
|
+
config.speakerSelectionMethod
|
|
129
129
|
);
|
|
130
130
|
this.terminationManager = new TerminationManager(
|
|
131
|
-
config.terminationConditions || []
|
|
131
|
+
config.terminationConditions || []
|
|
132
132
|
);
|
|
133
133
|
this.nestedChatManager = new NestedChatManager(
|
|
134
|
-
config.nestedChatConfigs || []
|
|
134
|
+
config.nestedChatConfigs || []
|
|
135
135
|
);
|
|
136
136
|
|
|
137
137
|
// Initialize metrics
|
|
@@ -171,7 +171,7 @@ export class GroupChatManager extends EventEmitter<GroupChatEvents> {
|
|
|
171
171
|
nestedChatId,
|
|
172
172
|
result: nestedResult,
|
|
173
173
|
});
|
|
174
|
-
}
|
|
174
|
+
}
|
|
175
175
|
);
|
|
176
176
|
}
|
|
177
177
|
|
|
@@ -232,7 +232,7 @@ export class GroupChatManager extends EventEmitter<GroupChatEvents> {
|
|
|
232
232
|
* @returns Chat result
|
|
233
233
|
*/
|
|
234
234
|
private async runConversationLoop(
|
|
235
|
-
options: StartChatOptions
|
|
235
|
+
options: StartChatOptions
|
|
236
236
|
): Promise<ChatResult> {
|
|
237
237
|
const maxRounds = this.config.maxRounds || 100;
|
|
238
238
|
const maxMessages = this.config.maxMessages || 1000;
|
|
@@ -242,7 +242,7 @@ export class GroupChatManager extends EventEmitter<GroupChatEvents> {
|
|
|
242
242
|
const terminationResult = await this.terminationManager.evaluate(
|
|
243
243
|
this.messages,
|
|
244
244
|
Array.from(this.participants.values()),
|
|
245
|
-
this.context
|
|
245
|
+
this.context
|
|
246
246
|
);
|
|
247
247
|
|
|
248
248
|
if (terminationResult.shouldTerminate) {
|
|
@@ -253,14 +253,14 @@ export class GroupChatManager extends EventEmitter<GroupChatEvents> {
|
|
|
253
253
|
if (this.context.currentRound >= maxRounds) {
|
|
254
254
|
return this.endChat(
|
|
255
255
|
'terminated',
|
|
256
|
-
`Maximum rounds reached: ${maxRounds}
|
|
256
|
+
`Maximum rounds reached: ${maxRounds}`
|
|
257
257
|
);
|
|
258
258
|
}
|
|
259
259
|
|
|
260
260
|
if (this.messages.length >= maxMessages) {
|
|
261
261
|
return this.endChat(
|
|
262
262
|
'terminated',
|
|
263
|
-
`Maximum messages reached: ${maxMessages}
|
|
263
|
+
`Maximum messages reached: ${maxMessages}`
|
|
264
264
|
);
|
|
265
265
|
}
|
|
266
266
|
|
|
@@ -281,7 +281,7 @@ export class GroupChatManager extends EventEmitter<GroupChatEvents> {
|
|
|
281
281
|
Array.from(this.participants.values()),
|
|
282
282
|
this.messages,
|
|
283
283
|
this.context,
|
|
284
|
-
this.config.speakerSelectionConfig
|
|
284
|
+
this.config.speakerSelectionConfig
|
|
285
285
|
);
|
|
286
286
|
|
|
287
287
|
this.context.previousSpeaker = this.context.currentSpeaker;
|
|
@@ -335,7 +335,7 @@ export class GroupChatManager extends EventEmitter<GroupChatEvents> {
|
|
|
335
335
|
* @returns Generated response content
|
|
336
336
|
*/
|
|
337
337
|
private async generateResponse(
|
|
338
|
-
participant: ChatParticipant
|
|
338
|
+
participant: ChatParticipant
|
|
339
339
|
): Promise<string | null> {
|
|
340
340
|
const startTime = Date.now();
|
|
341
341
|
|
|
@@ -349,11 +349,12 @@ export class GroupChatManager extends EventEmitter<GroupChatEvents> {
|
|
|
349
349
|
response = await this.responseGenerator(
|
|
350
350
|
participant,
|
|
351
351
|
this.messages,
|
|
352
|
-
this.context
|
|
352
|
+
this.context
|
|
353
353
|
);
|
|
354
354
|
} else {
|
|
355
|
-
|
|
356
|
-
|
|
355
|
+
throw new Error(
|
|
356
|
+
`No response generator configured. Call setResponseGenerator() with a real LLM integration before starting the chat.`
|
|
357
|
+
);
|
|
357
358
|
}
|
|
358
359
|
|
|
359
360
|
// Update metrics
|
|
@@ -371,28 +372,13 @@ export class GroupChatManager extends EventEmitter<GroupChatEvents> {
|
|
|
371
372
|
const errorMessage =
|
|
372
373
|
error instanceof Error ? error.message : String(error);
|
|
373
374
|
console.error(
|
|
374
|
-
`Error generating response for ${participant.name}: ${errorMessage}
|
|
375
|
+
`Error generating response for ${participant.name}: ${errorMessage}`
|
|
375
376
|
);
|
|
376
377
|
|
|
377
378
|
return null;
|
|
378
379
|
}
|
|
379
380
|
}
|
|
380
381
|
|
|
381
|
-
/**
|
|
382
|
-
* Generate a placeholder response when no generator is set
|
|
383
|
-
* @param participant - Participant to generate for
|
|
384
|
-
* @returns Placeholder response
|
|
385
|
-
*/
|
|
386
|
-
private generatePlaceholderResponse(participant: ChatParticipant): string {
|
|
387
|
-
const prompts = [
|
|
388
|
-
`[${participant.name}]: I acknowledge the message and am ready to contribute.`,
|
|
389
|
-
`[${participant.name}]: Based on my expertise in ${participant.capabilities.join(', ')}, I suggest we proceed.`,
|
|
390
|
-
`[${participant.name}]: Let me analyze this from my perspective.`,
|
|
391
|
-
];
|
|
392
|
-
|
|
393
|
-
return prompts[Math.floor(Math.random() * prompts.length)]!;
|
|
394
|
-
}
|
|
395
|
-
|
|
396
382
|
/**
|
|
397
383
|
* Update metrics after a response
|
|
398
384
|
* @param participantName - Name of the participant
|
|
@@ -402,7 +388,7 @@ export class GroupChatManager extends EventEmitter<GroupChatEvents> {
|
|
|
402
388
|
private updateMetrics(
|
|
403
389
|
participantName: string,
|
|
404
390
|
latencyMs: number,
|
|
405
|
-
tokenEstimate: number
|
|
391
|
+
tokenEstimate: number
|
|
406
392
|
): void {
|
|
407
393
|
// Update per-participant metrics
|
|
408
394
|
this.metrics.messagesPerParticipant[participantName] =
|
|
@@ -431,7 +417,7 @@ export class GroupChatManager extends EventEmitter<GroupChatEvents> {
|
|
|
431
417
|
const triggeredConfig = this.nestedChatManager.checkTrigger(
|
|
432
418
|
message,
|
|
433
419
|
Array.from(this.participants.values()),
|
|
434
|
-
this.context
|
|
420
|
+
this.context
|
|
435
421
|
);
|
|
436
422
|
|
|
437
423
|
if (triggeredConfig) {
|
|
@@ -446,14 +432,14 @@ export class GroupChatManager extends EventEmitter<GroupChatEvents> {
|
|
|
446
432
|
*/
|
|
447
433
|
private async runNestedChat(
|
|
448
434
|
config: NestedChatConfig,
|
|
449
|
-
triggerMessageId: string
|
|
435
|
+
triggerMessageId: string
|
|
450
436
|
): Promise<void> {
|
|
451
437
|
const nestedChatId = this.nestedChatManager.startNestedChat(
|
|
452
438
|
config,
|
|
453
439
|
this.chatId,
|
|
454
440
|
triggerMessageId,
|
|
455
441
|
Array.from(this.participants.values()),
|
|
456
|
-
this.context
|
|
442
|
+
this.context
|
|
457
443
|
);
|
|
458
444
|
|
|
459
445
|
// Run nested chat rounds
|
|
@@ -475,19 +461,19 @@ export class GroupChatManager extends EventEmitter<GroupChatEvents> {
|
|
|
475
461
|
const selectionResult = await this.speakerManager.selectSpeaker(
|
|
476
462
|
nestedState.participants,
|
|
477
463
|
nestedState.messages,
|
|
478
|
-
nestedContext
|
|
464
|
+
nestedContext
|
|
479
465
|
);
|
|
480
466
|
|
|
481
467
|
// Generate response
|
|
482
468
|
const participant = nestedState.participants.find(
|
|
483
|
-
p => p.name === selectionResult.speaker
|
|
469
|
+
p => p.name === selectionResult.speaker
|
|
484
470
|
);
|
|
485
471
|
|
|
486
472
|
if (participant && this.responseGenerator) {
|
|
487
473
|
const response = await this.responseGenerator(
|
|
488
474
|
participant,
|
|
489
475
|
nestedState.messages,
|
|
490
|
-
nestedContext
|
|
476
|
+
nestedContext
|
|
491
477
|
);
|
|
492
478
|
|
|
493
479
|
if (response) {
|
|
@@ -510,7 +496,7 @@ export class GroupChatManager extends EventEmitter<GroupChatEvents> {
|
|
|
510
496
|
const result = await this.nestedChatManager.endNestedChat(
|
|
511
497
|
nestedChatId,
|
|
512
498
|
'completed',
|
|
513
|
-
`Completed after ${round} rounds
|
|
499
|
+
`Completed after ${round} rounds`
|
|
514
500
|
);
|
|
515
501
|
|
|
516
502
|
this.nestedResults.push(result);
|
|
@@ -587,7 +573,7 @@ export class GroupChatManager extends EventEmitter<GroupChatEvents> {
|
|
|
587
573
|
removeParticipant(name: string): void {
|
|
588
574
|
this.participants.delete(name);
|
|
589
575
|
this.context.activeParticipants = this.context.activeParticipants.filter(
|
|
590
|
-
n => n !== name
|
|
576
|
+
n => n !== name
|
|
591
577
|
);
|
|
592
578
|
}
|
|
593
579
|
|
|
@@ -740,7 +726,7 @@ export class GroupChatManager extends EventEmitter<GroupChatEvents> {
|
|
|
740
726
|
type: T,
|
|
741
727
|
data: T extends keyof ChatEventDataMap
|
|
742
728
|
? ChatEventDataMap[T]
|
|
743
|
-
: Record<string, unknown
|
|
729
|
+
: Record<string, unknown>
|
|
744
730
|
): void {
|
|
745
731
|
const event: ChatEvent<T> = {
|
|
746
732
|
type,
|
|
@@ -808,7 +794,7 @@ export class GroupChatManager extends EventEmitter<GroupChatEvents> {
|
|
|
808
794
|
*/
|
|
809
795
|
updateState<T extends string | number | boolean | object | null>(
|
|
810
796
|
key: string,
|
|
811
|
-
value: T
|
|
797
|
+
value: T
|
|
812
798
|
): void {
|
|
813
799
|
this.context.state[key] = value;
|
|
814
800
|
}
|
|
@@ -866,7 +852,7 @@ export class GroupChatBuilder {
|
|
|
866
852
|
* @param method - Selection method
|
|
867
853
|
*/
|
|
868
854
|
withSpeakerSelection(
|
|
869
|
-
method: GroupChatConfig['speakerSelectionMethod']
|
|
855
|
+
method: GroupChatConfig['speakerSelectionMethod']
|
|
870
856
|
): this {
|
|
871
857
|
this.config.speakerSelectionMethod = method;
|
|
872
858
|
return this;
|
|
@@ -967,7 +953,7 @@ export class GroupChatBuilder {
|
|
|
967
953
|
export function createParticipant(
|
|
968
954
|
name: string,
|
|
969
955
|
systemPrompt: string,
|
|
970
|
-
capabilities: string[] = []
|
|
956
|
+
capabilities: string[] = []
|
|
971
957
|
): ChatParticipant {
|
|
972
958
|
return {
|
|
973
959
|
id: uuidv4(),
|