registerWithAgent

View as MarkdownOpen in Claude

Register this DataMap as a SWAIG function on an agent. Converts the DataMap to a SWAIG function definition and registers it with the agent’s registerSwaigFunction method.

Parameters

agent
objectRequired

An object with a registerSwaigFunction(fn: Record<string, unknown>) method (typically an AgentBase instance).

Returns

DataMap — Self for method chaining.

Example

1import { AgentBase, DataMap, FunctionResult } from '@signalwire/sdk';
2
3const dm = new DataMap('get_weather');
4dm.purpose('Look up current weather');
5dm.parameter('city', 'string', 'City name', { required: true });
6dm.webhook('GET', 'https://api.weather.com/v1/current?q=${args.city}');
7dm.output(new FunctionResult('Weather: ${response.current.condition.text}'));
8
9const agent = new AgentBase({ name: 'weather-agent' });
10dm.registerWithAgent(agent);