The event and the payload it carries, as one pair: ToolCallEvent.Started with a ToolCallStartedPayload — the call the agent has just begun, with the arguments its LLM produced; ToolCallEvent.Done with a ToolCallDonePayload — the call that has just finished, with the result the tool returned; or ToolCallEvent.Error with a ToolCallErrorPayload — the call that has just failed, with the reason in error when the server gave one.
import { AgentManagerCallbacks, ToolCallEvent } from '@d-id/client-sdk';
const callbacks: AgentManagerCallbacks = {
onToolEvent(event, data) {
if (event === ToolCallEvent.Started) {
console.log('started', data.name, data.input);
} else if (event === ToolCallEvent.Done) {
console.log('done', data.name, data.output, data.durationMs);
} else {
console.log('failed', data.name, data.error ?? 'no reason given');
}
},
};
The handler type for onToolEvent: the event argument narrows the payload argument.
One signature over three argument pairs, one pair per tool-call event, so the first argument narrows the second: a handler written against this type sees exactly one of ToolCallStartedPayload, ToolCallDonePayload and ToolCallErrorPayload, never a union of the three — in an inline
onToolEvent(event, data) { … }handler as much as in a standalone function annotated with this type. A payload that does not belong to its event is rejected. Expressive (V4) agents only.