registerSwaigFunction

View as MarkdownOpen in Claude

Register a pre-built SwaigFunction instance or a raw function descriptor (e.g., from a DataMap). Unlike defineTool(), this method accepts pre-built objects rather than taking a handler callback.

Parameters

fn
SwaigFunction | Record<string, unknown>Required

A SwaigFunction instance or a plain object with a "function" key. Typically generated by DataMap.toSwaigFunction().

Returns

AgentBase — Returns this for method chaining.

Example

1import { AgentBase, DataMap } from '@signalwire/sdk';
2
3const agent = new AgentBase({ name: 'plant-agent', route: '/plants' });
4agent.setPromptText('You are a helpful plant care assistant.');
5
6// Create a DataMap that calls a plant API server-side
7const plantTool = new DataMap('get_plant_info')
8 .description('Get care information for a plant')
9 .parameter('plantId', 'string', 'Plant ID', { required: true })
10 .webhook('GET', 'https://api.plants.example.com/plants/${args.plantId}')
11 .output({
12 response: 'The plant ${args.plantId} needs ${response.water_schedule} watering.',
13 action: [{ say: 'Here is the plant care information.' }],
14 });
15
16// Register the DataMap as a SWAIG function
17agent.registerSwaigFunction(plantTool.toSwaigFunction());
18await agent.serve();