symposium 0.11.3 → 0.12.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/Agent.js +42 -12
- package/package.json +3 -3
package/Agent.js
CHANGED
|
@@ -11,6 +11,7 @@ export default class Agent {
|
|
|
11
11
|
default_model = 'gpt-4o';
|
|
12
12
|
max_retries = 5;
|
|
13
13
|
callbacks = {};
|
|
14
|
+
utility = null;
|
|
14
15
|
|
|
15
16
|
constructor(options) {
|
|
16
17
|
this.options = {
|
|
@@ -58,7 +59,7 @@ export default class Agent {
|
|
|
58
59
|
async doInitThread(thread) {
|
|
59
60
|
}
|
|
60
61
|
|
|
61
|
-
async getThread(id, i) {
|
|
62
|
+
async getThread(id, i = 'default') {
|
|
62
63
|
let thread = this.threads.get(id);
|
|
63
64
|
if (thread) {
|
|
64
65
|
if (thread.interface !== i)
|
|
@@ -105,13 +106,37 @@ export default class Agent {
|
|
|
105
106
|
if (counter === 0)
|
|
106
107
|
thread = await this.beforeExecute(thread);
|
|
107
108
|
|
|
108
|
-
const
|
|
109
|
+
const completion_options = {};
|
|
110
|
+
if (this.utility) {
|
|
111
|
+
if (!['function', 'text'].includes(this.utility.type))
|
|
112
|
+
throw new Error('Bad utility definition');
|
|
113
|
+
|
|
114
|
+
if (this.utility.type === 'function') {
|
|
115
|
+
if (!this.utility.function || !this.utility.function.name || !this.utility.function.parameters)
|
|
116
|
+
throw new Error('Bad function definition');
|
|
117
|
+
|
|
118
|
+
completion_options.functions = [
|
|
119
|
+
this.utility.function,
|
|
120
|
+
];
|
|
121
|
+
completion_options.force_function = this.utility.function.name;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const completion = await this.generateCompletion(thread, completion_options);
|
|
109
126
|
if (completion) {
|
|
110
127
|
try {
|
|
111
128
|
thread = await this.afterExecute(thread, completion);
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
129
|
+
const response = await this.handleCompletion(thread, completion);
|
|
130
|
+
switch (response.type) {
|
|
131
|
+
case 'return':
|
|
132
|
+
return response.value;
|
|
133
|
+
|
|
134
|
+
case 'continue':
|
|
135
|
+
return await this.execute(thread);
|
|
136
|
+
|
|
137
|
+
default:
|
|
138
|
+
throw new Error('Unknown response type');
|
|
139
|
+
}
|
|
115
140
|
} catch (e) {
|
|
116
141
|
console.error(e);
|
|
117
142
|
|
|
@@ -161,15 +186,14 @@ export default class Agent {
|
|
|
161
186
|
}
|
|
162
187
|
|
|
163
188
|
async output(thread, msg) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
await callback(msg);
|
|
169
|
-
}
|
|
189
|
+
if (this.callbacks.hasOwnProperty(thread.interface + '-' + thread.id) && this.callbacks[thread.interface + '-' + thread.id].length) {
|
|
190
|
+
const callback = this.callbacks[thread.interface + '-' + thread.id].shift();
|
|
191
|
+
await callback(msg);
|
|
192
|
+
}
|
|
170
193
|
|
|
194
|
+
const i = this.options.interfaces.find(i => i.name === thread.interface);
|
|
195
|
+
if (i)
|
|
171
196
|
return i.output(thread, msg);
|
|
172
|
-
}
|
|
173
197
|
}
|
|
174
198
|
|
|
175
199
|
parseFunctions(message) {
|
|
@@ -206,6 +230,9 @@ export default class Agent {
|
|
|
206
230
|
for (let m of message.content) {
|
|
207
231
|
switch (m.type) {
|
|
208
232
|
case 'text':
|
|
233
|
+
if (this.utility && this.utility.type === 'text')
|
|
234
|
+
return m.content;
|
|
235
|
+
|
|
209
236
|
await this.output(thread, m.content);
|
|
210
237
|
break;
|
|
211
238
|
|
|
@@ -221,6 +248,9 @@ export default class Agent {
|
|
|
221
248
|
for (let f of functions) {
|
|
222
249
|
const response = await this.callFunction(thread, f);
|
|
223
250
|
|
|
251
|
+
if (this.utility && this.utility.type === 'function')
|
|
252
|
+
return response;
|
|
253
|
+
|
|
224
254
|
thread.addMessage('tool', [
|
|
225
255
|
{
|
|
226
256
|
type: 'function_response',
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "symposium",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.12.0",
|
|
5
5
|
"description": "Agents",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"author": "Domenico Giambra",
|
|
8
8
|
"license": "ISC",
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@anthropic-ai/sdk": "^0.
|
|
11
|
-
"groq-sdk": "^0.
|
|
10
|
+
"@anthropic-ai/sdk": "^0.36.0",
|
|
11
|
+
"groq-sdk": "^0.13.0",
|
|
12
12
|
"openai": "^4.12.1",
|
|
13
13
|
"tiktoken": "^1.0.10"
|
|
14
14
|
}
|