symposium 1.2.7 → 1.2.9

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 CHANGED
@@ -292,6 +292,8 @@ export default class Agent {
292
292
  } catch (e) {
293
293
  reject(e);
294
294
  }
295
+ }).then(() => {
296
+ emitter.emit('end', thread);
295
297
  });
296
298
 
297
299
  return this.type === 'chat' ? emitter : execution;
@@ -14,84 +14,97 @@ export default class AnthropicModel extends Model {
14
14
  }
15
15
 
16
16
  async generate(thread, functions = [], options = {}) {
17
- const parsed = this.parseOptions(options, functions);
18
- options = parsed.options;
19
- functions = parsed.functions;
17
+ try {
18
+ const parsed = this.parseOptions(options, functions);
19
+ options = parsed.options;
20
+ functions = parsed.functions;
21
+
22
+ let [system, messages] = await this.convertMessages(thread);
23
+
24
+ if (functions.length && !this.supports_functions) {
25
+ // Se il modello non supporta nativamente le funzioni, aggiungo il prompt al messaggio di sistema
26
+ const functions_prompt = this.promptFromFunctions(options, functions);
27
+ system += "\n\n" + functions_prompt;
28
+ functions = [];
29
+ }
20
30
 
21
- let [system, messages] = await this.convertMessages(thread);
31
+ const completion_payload = {
32
+ model: this.name,
33
+ system,
34
+ max_tokens: 16000,
35
+ thinking: {
36
+ type: "enabled",
37
+ budget_tokens: 10000,
38
+ },
39
+ betas: ["interleaved-thinking-2025-05-14"],
40
+ messages,
41
+ tools: functions.map(f => ({
42
+ name: f.name,
43
+ description: f.description,
44
+ input_schema: f.parameters,
45
+ required: f.required || undefined,
46
+ })),
47
+ };
22
48
 
23
- if (functions.length && !this.supports_functions) {
24
- // Se il modello non supporta nativamente le funzioni, aggiungo il prompt al messaggio di sistema
25
- const functions_prompt = this.promptFromFunctions(options, functions);
26
- system += "\n\n" + functions_prompt;
27
- functions = [];
28
- }
49
+ if (options.force_function) {
50
+ completion_payload.tool_choice = {
51
+ type: 'tool',
52
+ name: options.force_function,
53
+ };
54
+ }
29
55
 
30
- const completion_payload = {
31
- model: this.name,
32
- system,
33
- max_tokens: 16000,
34
- thinking: {
35
- type: "enabled",
36
- budget_tokens: 10000,
37
- },
38
- betas: ["interleaved-thinking-2025-05-14"],
39
- messages,
40
- tools: functions.map(f => ({
41
- name: f.name,
42
- description: f.description,
43
- input_schema: f.parameters,
44
- required: f.required || undefined,
45
- })),
46
- };
47
-
48
- if (options.force_function) {
49
- completion_payload.tool_choice = {
50
- type: 'tool',
51
- name: options.force_function,
52
- };
53
- }
56
+ const message = await this.getAnthropic().beta.messages.create(completion_payload);
57
+
58
+ const message_content = [];
59
+ if (message.content) {
60
+ for (let m of message.content) {
61
+ switch (m.type) {
62
+ case 'text':
63
+ message_content.push({type: 'text', content: m.text});
64
+ break;
65
+
66
+ case 'tool_use':
67
+ message_content.push({
68
+ type: 'function',
69
+ content: [
70
+ {
71
+ id: m.id,
72
+ name: m.name,
73
+ arguments: m.input,
74
+ },
75
+ ],
76
+ });
77
+ break;
78
+
79
+ case 'thinking':
80
+ message_content.push({
81
+ type: 'reasoning',
82
+ content: m.thinking,
83
+ original: m,
84
+ });
85
+ break;
54
86
 
55
- const message = await this.getAnthropic().beta.messages.create(completion_payload);
56
-
57
- const message_content = [];
58
- if (message.content) {
59
- for (let m of message.content) {
60
- switch (m.type) {
61
- case 'text':
62
- message_content.push({type: 'text', content: m.text});
63
- break;
64
-
65
- case 'tool_use':
66
- message_content.push({
67
- type: 'function',
68
- content: [
69
- {
70
- id: m.id,
71
- name: m.name,
72
- arguments: m.input,
73
- },
74
- ],
75
- });
76
- break;
77
-
78
- case 'thinking':
79
- message_content.push({
80
- type: 'reasoning',
81
- content: m.thinking,
82
- original: m,
83
- });
84
- break;
85
-
86
- default:
87
- throw new Error('Unrecognized message type in Anthropic response');
87
+ default:
88
+ throw new Error('Unrecognized message type in Anthropic response');
89
+ }
88
90
  }
89
91
  }
90
- }
91
92
 
92
- return [
93
- new Message('assistant', message_content),
94
- ];
93
+ return [
94
+ new Message('assistant', message_content),
95
+ ];
96
+ } catch (e) {
97
+ if (e.error?.error?.type === 'rate_limit_error') {
98
+ console.error('Rate limite exceeded for Anthropic API, waiting 60 seconds...');
99
+ await new Promise(resolve => setTimeout(resolve, 60000));
100
+ if ((options.counter || 0) < 3)
101
+ return this.generate(thread, functions, {...options, counter: (options.counter || 0) + 1});
102
+ else
103
+ throw new Error('Rate limit exceeded for Anthropic API, aborting.');
104
+ }
105
+
106
+ throw e;
107
+ }
95
108
  }
96
109
 
97
110
  async convertMessages(thread) {
@@ -187,7 +200,7 @@ export default class AnthropicModel extends Model {
187
200
  };
188
201
 
189
202
  if (lastMessage && lastMessage.role === parsedMessage.role) {
190
- lastMessage.content = lastMessage.content.concat(message.content);
203
+ lastMessage.content = lastMessage.content.concat(parsedMessage.content);
191
204
  } else {
192
205
  messages.push(parsedMessage);
193
206
  lastMessage = parsedMessage;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "symposium",
4
- "version": "1.2.7",
4
+ "version": "1.2.9",
5
5
  "description": "Agents",
6
6
  "main": "index.js",
7
7
  "author": "Domenico Giambra",