symposium 1.2.10 → 1.2.11

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 (3) hide show
  1. package/Agent.js +30 -9
  2. package/Tool.js +4 -0
  3. package/package.json +1 -1
package/Agent.js CHANGED
@@ -419,20 +419,25 @@ export default class Agent {
419
419
  }
420
420
 
421
421
  if (functions.length) {
422
- for (let f of functions) {
423
- if (this.utility && ['function', 'json'].includes(this.utility.type))
424
- return {type: 'response', value: this.afterHandle(thread, completion, f.arguments)};
422
+ if (this.utility && ['function', 'json'].includes(this.utility.type))
423
+ return {type: 'response', value: this.afterHandle(thread, completion, functions[0].arguments)};
425
424
 
426
- const function_response = await this.callFunction(thread, f, emitter);
425
+ const responses = await Promise.all(functions.map(async f => this.callFunction(thread, f, emitter)));
427
426
 
427
+ if (responses.some(r => r.type === 'tool_auth')) {
428
+ emitter.emit('tool_auth', responses.filter(r => r.type === 'tool_auth').map(r => ({tool: r.tool, arguments: r.arguments})));
429
+ return {type: 'void'};
430
+ }
431
+
432
+ for (let r of responses) {
428
433
  thread.addMessage('tool', [
429
434
  {
430
435
  type: 'function_response',
431
- content: {name: f.name, response: function_response, id: f.id || undefined},
436
+ content: {name: f.name, response: r, id: f.id || undefined},
432
437
  },
433
438
  ], f.name);
434
439
 
435
- await this.log('function_response', function_response);
440
+ await this.log('function_response', r);
436
441
  }
437
442
 
438
443
  await this.afterHandle(thread, completion);
@@ -481,19 +486,35 @@ export default class Agent {
481
486
  throw new Error('Unrecognized function ' + function_call.name);
482
487
 
483
488
  const func = functions.get(function_call.name);
484
- await this.log('function_call', function_call);
485
489
 
490
+ await this.log('function_call', function_call);
486
491
  emitter.emit('tool', function_call);
487
492
 
493
+ if (!func.tool.authorize(thread, function_call.name, function_call.arguments)) {
494
+ return {
495
+ type: 'tool_auth',
496
+ tool: function_call.name,
497
+ arguments: function_call.arguments,
498
+ };
499
+ }
500
+
488
501
  try {
489
502
  const response = await func.tool.callFunction(thread, function_call.name, function_call.arguments);
490
503
  if (emitter)
491
504
  emitter.emit('tool_response', {name: func.tool.name, success: true, response});
492
- return response;
505
+
506
+ return {
507
+ type: 'response',
508
+ response,
509
+ };
493
510
  } catch (error) {
494
511
  if (emitter)
495
512
  emitter.emit('tool_response', {name: func.tool.name, success: false, error: error.message || error});
496
- return {error};
513
+
514
+ return {
515
+ type: 'error',
516
+ error,
517
+ };
497
518
  }
498
519
  }
499
520
 
package/Tool.js CHANGED
@@ -8,4 +8,8 @@ export default class Tool {
8
8
  async callFunction(thread, name, payload) {
9
9
  return {error: 'callFunction is yet to be implemented'};
10
10
  }
11
+
12
+ async authorize(thread, name, payload) {
13
+ return true;
14
+ }
11
15
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "symposium",
4
- "version": "1.2.10",
4
+ "version": "1.2.11",
5
5
  "description": "Agents",
6
6
  "main": "index.js",
7
7
  "author": "Domenico Giambra",