***

title: toSwaigFunction
slug: /reference/typescript/agents/data-map/to-swaig-function
description: Convert the DataMap to a SWAIG function definition object.
max-toc-depth: 3
---------------------

For a complete index of all SignalWire documentation pages, fetch https://signalwire.com/docs/llms.txt

[ref-datamap]: /docs/server-sdks/reference/typescript/agents/data-map

Convert this [DataMap][ref-datamap] to a SWAIG function definition object. Register the
result with your agent using `agent.registerSwaigFunction()`.

## **Returns**

`Record<string, unknown>` -- An object containing the function name, description,
parameter schema, and `data_map` configuration (instead of a webhook URL).

## **Example**

```typescript {9}
import { DataMap, FunctionResult } from '@signalwire/sdk';

const dm = new DataMap('get_weather');
dm.purpose('Look up 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.temp_f}F'));

const swaigDef = dm.toSwaigFunction();
console.log(JSON.stringify(swaigDef, null, 2));
```