symposium 1.2.6 → 1.2.7
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 +12 -6
- package/README.md +12 -3
- package/package.json +1 -1
package/Agent.js
CHANGED
|
@@ -252,6 +252,14 @@ export default class Agent {
|
|
|
252
252
|
|
|
253
253
|
try {
|
|
254
254
|
thread = await this.afterExecute(thread, completion, emitter);
|
|
255
|
+
|
|
256
|
+
for (let message of completion) {
|
|
257
|
+
if (message.role === 'assistant' && message.content.some(c => c.type === 'reasoning')) {
|
|
258
|
+
const reasoning = message.content.find(c => c.type === 'reasoning').content;
|
|
259
|
+
emitter.emit('reasoning', reasoning);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
255
263
|
const response = await this.handleCompletion(thread, completion, emitter);
|
|
256
264
|
|
|
257
265
|
switch (this.type) {
|
|
@@ -470,20 +478,18 @@ export default class Agent {
|
|
|
470
478
|
throw new Error('Unrecognized function ' + function_call.name);
|
|
471
479
|
|
|
472
480
|
const func = functions.get(function_call.name);
|
|
473
|
-
const partialOutput = func.partialOutput ? ((typeof func.partialOutput) === 'text' ? func.partialOutput : func.partialOutput.call(this, function_call.arguments)) : 'Uso lo strumento ' + function_call.name + '...';
|
|
474
|
-
if (emitter)
|
|
475
|
-
emitter.emit('partial', partialOutput);
|
|
476
|
-
|
|
477
481
|
await this.log('function_call', function_call);
|
|
478
482
|
|
|
483
|
+
emitter.emit('tool', function_call);
|
|
484
|
+
|
|
479
485
|
try {
|
|
480
486
|
const response = await func.tool.callFunction(thread, function_call.name, function_call.arguments);
|
|
481
487
|
if (emitter)
|
|
482
|
-
emitter.emit('
|
|
488
|
+
emitter.emit('tool_response', {name: func.tool.name, success: true, response});
|
|
483
489
|
return response;
|
|
484
490
|
} catch (error) {
|
|
485
491
|
if (emitter)
|
|
486
|
-
emitter.emit('
|
|
492
|
+
emitter.emit('tool_response', {name: func.tool.name, success: false, error: error.message || error});
|
|
487
493
|
return {error};
|
|
488
494
|
}
|
|
489
495
|
}
|
package/README.md
CHANGED
|
@@ -137,8 +137,15 @@ async function main() {
|
|
|
137
137
|
console.error(`\nAn error occurred: ${error.message}`);
|
|
138
138
|
});
|
|
139
139
|
|
|
140
|
-
emitter.on('
|
|
141
|
-
console.log(`\n> ${
|
|
140
|
+
emitter.on('tool', (tool) => {
|
|
141
|
+
console.log(`\n> Using tool: ${tool.name} with arguments ${JSON.stringify(tool.arguments)}\n`);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
emitter.on('tool_response', (tool_response) => {
|
|
145
|
+
if (tool_response.success)
|
|
146
|
+
console.log(`\n> Tool ${tool_response.name} completed successfully with response: ${JSON.stringify(tool_response.response)}\n`);
|
|
147
|
+
else
|
|
148
|
+
console.log(`\n> Tool ${tool_response.name} failed with error: ${tool_response.error}\n`);
|
|
142
149
|
});
|
|
143
150
|
}
|
|
144
151
|
|
|
@@ -149,7 +156,9 @@ When you run this, the agent will respond to your message, and the response will
|
|
|
149
156
|
|
|
150
157
|
- `start`: Emitted when the agent begins processing the message. The `thread` object is passed as an argument.
|
|
151
158
|
- `output`: Emitted for each chunk of text in the response stream.
|
|
152
|
-
- `
|
|
159
|
+
- `reasoning`: Emitted when the agent generates reasoning steps (if applicable).
|
|
160
|
+
- `tool`: Emitted when the agent decides to use a tool. The tool name and arguments are provided.
|
|
161
|
+
- `tool_response`: Emitted when a tool call completes, with the response or error
|
|
153
162
|
- `error`: Emitted if an error occurs during processing.
|
|
154
163
|
|
|
155
164
|
## Advanced Usage
|