symposium 0.11.4 → 0.12.1

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.
Files changed (2) hide show
  1. package/Agent.js +45 -8
  2. 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 = {
@@ -105,13 +106,40 @@ export default class Agent {
105
106
  if (counter === 0)
106
107
  thread = await this.beforeExecute(thread);
107
108
 
108
- const completion = await this.generateCompletion(thread);
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 interrupt = await this.handleCompletion(thread, completion);
113
- if (!interrupt)
114
- await this.execute(thread);
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
+ case 'void':
138
+ return;
139
+
140
+ default:
141
+ throw new Error('Unknown response type');
142
+ }
115
143
  } catch (e) {
116
144
  console.error(e);
117
145
 
@@ -205,6 +233,9 @@ export default class Agent {
205
233
  for (let m of message.content) {
206
234
  switch (m.type) {
207
235
  case 'text':
236
+ if (this.utility && this.utility.type === 'text')
237
+ return this.afterHandle(thread, completion, 'return', m.content);
238
+
208
239
  await this.output(thread, m.content);
209
240
  break;
210
241
 
@@ -220,6 +251,9 @@ export default class Agent {
220
251
  for (let f of functions) {
221
252
  const response = await this.callFunction(thread, f);
222
253
 
254
+ if (this.utility && this.utility.type === 'function')
255
+ return this.afterHandle(thread, completion, 'return', response);
256
+
223
257
  thread.addMessage('tool', [
224
258
  {
225
259
  type: 'function_response',
@@ -230,15 +264,18 @@ export default class Agent {
230
264
  await this.log('function_response', response);
231
265
  }
232
266
 
233
- return this.afterHandle(thread, completion, true);
267
+ return this.afterHandle(thread, completion, 'continue');
234
268
  } else {
235
269
  await thread.storeState();
236
- return this.afterHandle(thread, completion, false);
270
+ return this.afterHandle(thread, completion, 'void');
237
271
  }
238
272
  }
239
273
 
240
- async afterHandle(thread, completion, executed_function) {
241
- return !executed_function;
274
+ async afterHandle(thread, completion, type, value = null) {
275
+ return {
276
+ type,
277
+ value,
278
+ };
242
279
  }
243
280
 
244
281
  async getFunctions(parsed = true) {
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "symposium",
4
- "version": "0.11.4",
4
+ "version": "0.12.1",
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.33.0",
11
- "groq-sdk": "^0.12.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
  }