defineTools

View as MarkdownOpen in Claude

Protected lifecycle method for registering tools on the agent. Subclasses override this method to call defineTool() or registerSwaigFunction() after all instance fields are initialized.

This method is not called automatically. Subclasses must invoke this.defineTools() explicitly at the end of their constructor.

Parameters

None.

Returns

void

Example

import { AgentBase } from '@signalwire/sdk';
class WeatherAgent extends AgentBase {
constructor() {
super({ name: 'weather', route: '/weather' });
this.setPromptText('You are a weather assistant.');
this.defineTools();
}
protected override defineTools(): void {
this.defineTool({
name: 'check_weather',
description: 'Check the current weather',
parameters: {
type: 'object',
properties: {
city: { type: 'string', description: 'City name' },
},
required: ['city'],
},
handler: async (args) => {
return { response: `The weather in ${args.city} is sunny and 72F.` };
},
});
}
}
const agent = new WeatherAgent();
await agent.serve();