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

# registerSwaigFunction

> Register a pre-built SwaigFunction instance or a raw function descriptor.

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

[define-tool]: /docs/server-sdks/reference/typescript/agents/swml-service/define-tool

[ref-swmlservice]: /docs/server-sdks/reference/typescript/agents/swml-service

Register a pre-built `SwaigFunction` instance or a raw function descriptor (e.g.,
from a [`DataMap`][datamap]) on a [`SWMLService`][ref-swmlservice]. Unlike
[`defineTool()`][define-tool], this method accepts pre-built objects rather than
taking a handler callback.

## **Parameters**

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

## **Returns**

[`SWMLService`][ref-swmlservice] -- Returns `this` for method chaining.

## **Example**

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

const service = new SWMLService({ name: 'swaig-host', route: '/' });

const plantTool = new DataMap('get_plant_info')
  .description('Get care information for a plant')
  .parameter('plantId', 'string', 'Plant ID', { required: true })
  .webhook('GET', 'https://api.plants.example.com/plants/${args.plantId}')
  .output(new FunctionResult(
    'The plant ${args.plantId} needs ${response.water_schedule} watering.',
  ));

service.registerSwaigFunction(plantTool.toSwaigFunction());
```