@mast-ai/core 0.3.0 → 0.5.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/dist/runner.js +19 -6
- package/package.json +1 -1
package/dist/runner.js
CHANGED
|
@@ -194,16 +194,21 @@ export class AgentRunner {
|
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
196
|
if (toolCalls.length > 0) {
|
|
197
|
+
// Emit tool_call_started only for registered tools so hallucinated
|
|
198
|
+
// calls never appear in the UI.
|
|
197
199
|
for (const call of toolCalls) {
|
|
198
|
-
|
|
200
|
+
if (this.registry.getTool(call.name)) {
|
|
201
|
+
yield { type: 'tool_call_started', name: call.name, args: call.args };
|
|
202
|
+
}
|
|
199
203
|
}
|
|
200
204
|
const toolResults = await Promise.all(toolCalls.map(async (call) => {
|
|
201
205
|
const tool = this.registry.getTool(call.name);
|
|
202
206
|
if (!tool) {
|
|
203
207
|
return {
|
|
204
208
|
call,
|
|
205
|
-
result: `
|
|
209
|
+
result: `Tool '${call.name}' does not exist and was not called.`,
|
|
206
210
|
error: true,
|
|
211
|
+
hallucinated: true,
|
|
207
212
|
};
|
|
208
213
|
}
|
|
209
214
|
try {
|
|
@@ -211,16 +216,24 @@ export class AgentRunner {
|
|
|
211
216
|
signal,
|
|
212
217
|
onEvent: onToolEvent ? (event) => onToolEvent(call.name, event) : undefined,
|
|
213
218
|
});
|
|
214
|
-
return { call, result, error: false };
|
|
219
|
+
return { call, result, error: false, hallucinated: false };
|
|
215
220
|
}
|
|
216
221
|
catch (err) {
|
|
217
222
|
const message = err instanceof Error ? err.message : String(err);
|
|
218
|
-
return {
|
|
223
|
+
return {
|
|
224
|
+
call,
|
|
225
|
+
result: `Error executing tool: ${message}`,
|
|
226
|
+
error: true,
|
|
227
|
+
hallucinated: false,
|
|
228
|
+
};
|
|
219
229
|
}
|
|
220
230
|
}));
|
|
221
231
|
const resultMessages = [];
|
|
222
|
-
for (const { call, result, error } of toolResults) {
|
|
223
|
-
|
|
232
|
+
for (const { call, result, error, hallucinated } of toolResults) {
|
|
233
|
+
// Suppress completed events for hallucinated calls — they had no started event.
|
|
234
|
+
if (!hallucinated) {
|
|
235
|
+
yield { type: 'tool_call_completed', name: call.name, result, error };
|
|
236
|
+
}
|
|
224
237
|
resultMessages.push({
|
|
225
238
|
role: 'user',
|
|
226
239
|
content: { type: 'tool_result', id: call.id, name: call.name, result },
|