symposium 1.0.3 → 1.0.5
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 +15 -5
- package/{MemoryHandler.js → ContextHandler.js} +1 -1
- package/README.md +2 -2
- package/Summarizer.js +2 -2
- package/Symposium.js +17 -0
- package/index.js +2 -2
- package/package.json +4 -4
package/Agent.js
CHANGED
|
@@ -72,7 +72,10 @@ export default class Agent {
|
|
|
72
72
|
async doInitThread(thread) {
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
async getThread(id) {
|
|
75
|
+
async getThread(id = null) {
|
|
76
|
+
if (id === null)
|
|
77
|
+
id = uuid();
|
|
78
|
+
|
|
76
79
|
let thread = this.threads.get(id);
|
|
77
80
|
if (!thread) {
|
|
78
81
|
thread = new Thread(id, this);
|
|
@@ -359,6 +362,10 @@ export default class Agent {
|
|
|
359
362
|
return value;
|
|
360
363
|
}
|
|
361
364
|
|
|
365
|
+
getEmitter() {
|
|
366
|
+
return new BufferedEventEmitter();
|
|
367
|
+
}
|
|
368
|
+
|
|
362
369
|
async getFunctions(parsed = true) {
|
|
363
370
|
if (this.functions === null) {
|
|
364
371
|
this.functions = new Map();
|
|
@@ -382,23 +389,26 @@ export default class Agent {
|
|
|
382
389
|
return this.functions;
|
|
383
390
|
}
|
|
384
391
|
|
|
385
|
-
async callFunction(thread, function_call, emitter) {
|
|
392
|
+
async callFunction(thread, function_call, emitter = null) {
|
|
386
393
|
const functions = await this.getFunctions(false);
|
|
387
394
|
if (!functions.has(function_call.name))
|
|
388
395
|
throw new Error('Unrecognized function ' + function_call.name);
|
|
389
396
|
|
|
390
397
|
const func = functions.get(function_call.name);
|
|
391
398
|
const partialOutput = func.partialOutput ? ((typeof func.partialOutput) === 'text' ? func.partialOutput : func.partialOutput.call(this, function_call.arguments)) : 'Uso lo strumento ' + function_call.name + '...';
|
|
392
|
-
emitter
|
|
399
|
+
if (emitter)
|
|
400
|
+
emitter.emit('partial', partialOutput);
|
|
393
401
|
|
|
394
402
|
await this.log('function_call', function_call);
|
|
395
403
|
|
|
396
404
|
try {
|
|
397
405
|
const response = await func.tool.callFunction(thread, function_call.name, function_call.arguments);
|
|
398
|
-
emitter
|
|
406
|
+
if (emitter)
|
|
407
|
+
emitter.emit('partial', 'Risposta ricevuta da ' + func.tool.name);
|
|
399
408
|
return response;
|
|
400
409
|
} catch (error) {
|
|
401
|
-
emitter
|
|
410
|
+
if (emitter)
|
|
411
|
+
emitter.emit('partial', 'Ricevuto errore da ' + func.tool.name);
|
|
402
412
|
return {error};
|
|
403
413
|
}
|
|
404
414
|
}
|
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@ The framework is built around a few core components:
|
|
|
38
38
|
- **`Thread`**: Represents a single conversation with an agent. It maintains the message history and the agent's state for that conversation. Each thread has a unique ID.
|
|
39
39
|
- **`Tool`**: A base class for creating tools that an `Agent` can use. Tools expose functions that the LLM can call to interact with external APIs or data.
|
|
40
40
|
- **`Message`**: A wrapper for messages within a `Thread`, containing the role (`user`, `assistant`, `system`, `tool`), content, and other metadata.
|
|
41
|
-
- **`
|
|
41
|
+
- **`ContextHandler`**: A class for managing an agent's long contexts. It can be extended to create custom memory strategies.
|
|
42
42
|
- **`Summarizer`**: A utility agent for summarizing text or conversations.
|
|
43
43
|
- **`Logger`**: A simple logging utility that can be passed to an agent to log its activity.
|
|
44
44
|
|
|
@@ -338,7 +338,7 @@ This is a high-level overview. For details, please refer to the source code.
|
|
|
338
338
|
|
|
339
339
|
### Other Classes
|
|
340
340
|
|
|
341
|
-
- **`
|
|
341
|
+
- **`ContextHandler`**: Provides a base for managing long-term context. Can be extended for custom memory strategies.
|
|
342
342
|
- **`Summarizer`**: A utility agent for text summarization.
|
|
343
343
|
- **`Logger`**: A simple logger for agent activity.
|
|
344
344
|
|
package/Summarizer.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Symposium from "./Symposium.js";
|
|
2
|
-
import
|
|
2
|
+
import ContextHandler from "./ContextHandler.js";
|
|
3
3
|
|
|
4
|
-
export default class Summarizer extends
|
|
4
|
+
export default class Summarizer extends ContextHandler {
|
|
5
5
|
constructor(threshold = 0.7, summary_length = 0.5) {
|
|
6
6
|
super();
|
|
7
7
|
this.threshold = threshold;
|
package/Symposium.js
CHANGED
|
@@ -2,6 +2,8 @@ import fs from 'fs';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import {fileURLToPath} from 'url';
|
|
4
4
|
|
|
5
|
+
import Agent from "./Agent.js";
|
|
6
|
+
|
|
5
7
|
export default class Symposium {
|
|
6
8
|
static models = new Map();
|
|
7
9
|
static storage = null;
|
|
@@ -113,4 +115,19 @@ export default class Symposium {
|
|
|
113
115
|
|
|
114
116
|
return mimeToExt[mime] || null;
|
|
115
117
|
}
|
|
118
|
+
|
|
119
|
+
static async oneShot(system, prompt, options = {}) {
|
|
120
|
+
const agent = new Agent(options.agent || {});
|
|
121
|
+
agent.type = 'utility';
|
|
122
|
+
agent.utility = options.response || {
|
|
123
|
+
type: 'text',
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
agent.doInitThread = async thread => {
|
|
127
|
+
await thread.addMessage('system', system);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const thread = await agent.getThread();
|
|
131
|
+
return agent.message(prompt, thread);
|
|
132
|
+
}
|
|
116
133
|
}
|
package/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import Agent from "./Agent.js";
|
|
|
5
5
|
import Thread from "./Thread.js";
|
|
6
6
|
import Tool from "./Tool.js";
|
|
7
7
|
import Logger from "./Logger.js";
|
|
8
|
-
import
|
|
8
|
+
import ContextHandler from "./ContextHandler.js";
|
|
9
9
|
import Summarizer from "./Summarizer.js";
|
|
10
10
|
|
|
11
11
|
export {
|
|
@@ -14,6 +14,6 @@ export {
|
|
|
14
14
|
Thread,
|
|
15
15
|
Tool,
|
|
16
16
|
Logger,
|
|
17
|
-
|
|
17
|
+
ContextHandler,
|
|
18
18
|
Summarizer,
|
|
19
19
|
};
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "symposium",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.5",
|
|
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.64.0",
|
|
11
|
+
"groq-sdk": "^0.32.0",
|
|
12
12
|
"openai": "^5.0.0",
|
|
13
13
|
"tiktoken": "^1.0.10",
|
|
14
|
-
"uuid": "^
|
|
14
|
+
"uuid": "^13.0.0"
|
|
15
15
|
}
|
|
16
16
|
}
|