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

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