Skip to content

Commit a674880

Browse files
committed
tool-error-callback
1 parent fc76f6d commit a674880

6 files changed

Lines changed: 34 additions & 3 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "agent-swarm-kit",
3-
"version": "1.1.92",
3+
"version": "1.1.93",
44
"description": "A TypeScript library for building orchestrated framework-agnostic multi-agent AI systems",
55
"author": {
66
"name": "Petr Tripolsky",

src/classes/MCP.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ export class MergeMCP implements IMCP {
248248
);
249249
{
250250
const { callbacks = {} } = swarm.agentSchemaService.get(agentName);
251+
callbacks.onToolError &&
252+
callbacks.onToolError(dto.clientId, dto.agentName, error);
251253
callbacks.onResurrect &&
252254
callbacks.onResurrect(
253255
dto.clientId,

src/client/ClientAgent.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ const createToolCall = async (
153153
tool.function.arguments,
154154
error
155155
);
156+
self.params.callbacks?.onToolError &&
157+
self.params.callbacks.onToolError(
158+
self.params.clientId,
159+
self.params.agentName,
160+
error
161+
);
156162
self._toolErrorSubject.next(TOOL_ERROR_SYMBOL);
157163
}
158164
};

src/interfaces/Agent.interface.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,20 @@ export interface IAgentSchemaInternalCallbacks {
283283
request: IToolRequest[]
284284
) => void;
285285

286+
/**
287+
* Optional callback triggered when a tool throw an error
288+
* This callback is used to log the error before resurrect
289+
*
290+
* @param {string} clientId - The ID of the client interacting with the agent.
291+
* @param {AgentName} agentName - The name of the agent making the tool request.
292+
* @param {IToolRequest} request - The content of the tool request.
293+
*/
294+
onToolError?: (
295+
clientId: string,
296+
agentName: AgentName,
297+
error: Error,
298+
) => void;
299+
286300
/**
287301
* Optional callback triggered when an assistant message is committed.
288302
* @param {string} clientId - The ID of the client interacting with the agent.

types.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3490,6 +3490,15 @@ interface IAgentSchemaInternalCallbacks {
34903490
* @param {IToolRequest} request - The content of the tool request.
34913491
*/
34923492
onToolRequest?: (clientId: string, agentName: AgentName, request: IToolRequest[]) => void;
3493+
/**
3494+
* Optional callback triggered when a tool throw an error
3495+
* This callback is used to log the error before resurrect
3496+
*
3497+
* @param {string} clientId - The ID of the client interacting with the agent.
3498+
* @param {AgentName} agentName - The name of the agent making the tool request.
3499+
* @param {IToolRequest} request - The content of the tool request.
3500+
*/
3501+
onToolError?: (clientId: string, agentName: AgentName, error: Error) => void;
34933502
/**
34943503
* Optional callback triggered when an assistant message is committed.
34953504
* @param {string} clientId - The ID of the client interacting with the agent.

0 commit comments

Comments
 (0)