symposium 0.9.6 → 0.10.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 +27 -11
- package/Interface.js +10 -0
- package/package.json +2 -2
package/Agent.js
CHANGED
|
@@ -14,6 +14,7 @@ export default class Agent {
|
|
|
14
14
|
constructor(options) {
|
|
15
15
|
this.options = {
|
|
16
16
|
memory_handler: null,
|
|
17
|
+
interfaces: [],
|
|
17
18
|
...options,
|
|
18
19
|
};
|
|
19
20
|
|
|
@@ -51,7 +52,7 @@ export default class Agent {
|
|
|
51
52
|
async doInitThread(thread) {
|
|
52
53
|
}
|
|
53
54
|
|
|
54
|
-
async getThread(id
|
|
55
|
+
async getThread(id) {
|
|
55
56
|
let thread = this.threads.get(id);
|
|
56
57
|
if (!thread) {
|
|
57
58
|
thread = new Thread(this.name + '-' + id, this);
|
|
@@ -64,9 +65,6 @@ export default class Agent {
|
|
|
64
65
|
this.threads.set(id, thread);
|
|
65
66
|
}
|
|
66
67
|
|
|
67
|
-
if (reply)
|
|
68
|
-
thread.reply = reply;
|
|
69
|
-
|
|
70
68
|
return thread;
|
|
71
69
|
}
|
|
72
70
|
|
|
@@ -82,7 +80,8 @@ export default class Agent {
|
|
|
82
80
|
return null;
|
|
83
81
|
}
|
|
84
82
|
|
|
85
|
-
async message(
|
|
83
|
+
async message(thread_id, content) {
|
|
84
|
+
const thread = await this.getThread(thread_id);
|
|
86
85
|
await this.log('user_message', content);
|
|
87
86
|
thread.addMessage('user', content);
|
|
88
87
|
|
|
@@ -103,7 +102,9 @@ export default class Agent {
|
|
|
103
102
|
if (completion) {
|
|
104
103
|
try {
|
|
105
104
|
thread = await this.afterExecute(thread, completion);
|
|
106
|
-
await this.handleCompletion(thread, completion);
|
|
105
|
+
const interrupt = await this.handleCompletion(thread, completion);
|
|
106
|
+
if (!interrupt)
|
|
107
|
+
await this.execute(thread);
|
|
107
108
|
} catch (e) {
|
|
108
109
|
console.error(e);
|
|
109
110
|
|
|
@@ -135,17 +136,27 @@ export default class Agent {
|
|
|
135
136
|
return this.generateCompletion(thread, options, retry_counter + 1);
|
|
136
137
|
}
|
|
137
138
|
|
|
138
|
-
await
|
|
139
|
+
await this.error(thread, error.response.status + ': ' + JSON.stringify(error.response.data));
|
|
139
140
|
} else if (error.message) {
|
|
140
141
|
console.error(error.message);
|
|
141
|
-
await
|
|
142
|
+
await this.error(thread, error.message);
|
|
142
143
|
} else {
|
|
143
144
|
console.error(error);
|
|
144
|
-
await
|
|
145
|
+
await this.error(thread, 'Errore interno');
|
|
145
146
|
}
|
|
146
147
|
}
|
|
147
148
|
}
|
|
148
149
|
|
|
150
|
+
async error(thread, error) {
|
|
151
|
+
for (let i of this.options.interfaces)
|
|
152
|
+
await i.error(thread, error);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
async output(thread, msg) {
|
|
156
|
+
for (let i of this.options.interfaces)
|
|
157
|
+
await i.output(thread, msg);
|
|
158
|
+
}
|
|
159
|
+
|
|
149
160
|
parseFunctions(message) {
|
|
150
161
|
const newContent = [];
|
|
151
162
|
for (let m of message.content) {
|
|
@@ -180,7 +191,7 @@ export default class Agent {
|
|
|
180
191
|
for (let m of message.content) {
|
|
181
192
|
switch (m.type) {
|
|
182
193
|
case 'text':
|
|
183
|
-
await
|
|
194
|
+
await this.output(thread, m.content);
|
|
184
195
|
break;
|
|
185
196
|
|
|
186
197
|
case 'function':
|
|
@@ -205,12 +216,17 @@ export default class Agent {
|
|
|
205
216
|
await this.log('function_response', response);
|
|
206
217
|
}
|
|
207
218
|
|
|
208
|
-
|
|
219
|
+
return this.afterHandle(thread, completion, true);
|
|
209
220
|
} else {
|
|
210
221
|
await thread.storeState();
|
|
222
|
+
return this.afterHandle(thread, completion, false);
|
|
211
223
|
}
|
|
212
224
|
}
|
|
213
225
|
|
|
226
|
+
async afterHandle(thread, completion, executed_function) {
|
|
227
|
+
return !executed_function;
|
|
228
|
+
}
|
|
229
|
+
|
|
214
230
|
async getFunctions(parsed = true) {
|
|
215
231
|
if (this.functions === null) {
|
|
216
232
|
this.functions = new Map();
|
package/Interface.js
ADDED
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "symposium",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.10.0",
|
|
5
5
|
"description": "Agents",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"author": "Domenico Giambra",
|
|
8
8
|
"license": "ISC",
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@anthropic-ai/sdk": "^0.33.0",
|
|
11
|
-
"groq-sdk": "^0.
|
|
11
|
+
"groq-sdk": "^0.12.0",
|
|
12
12
|
"openai": "^4.12.1",
|
|
13
13
|
"tiktoken": "^1.0.10"
|
|
14
14
|
}
|