***

title: registerSwaigFunction
slug: /reference/typescript/agents/agent-base/register-swaig-function
description: Register a pre-built SwaigFunction instance or a raw function descriptor.
max-toc-depth: 3
---------------------

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

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

[define-tool]: /docs/server-sdks/reference/typescript/agents/agent-base/define-tool

[ref-agentbase]: /docs/server-sdks/reference/typescript/agents/agent-base

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

## **Parameters**

<ParamField path="fn" type="SwaigFunction | Record<string, unknown>" required={true} toc={true}>
  A `SwaigFunction` instance or a plain object with a `"function"` key. Typically
  generated by `DataMap.toSwaigFunction()`.
</ParamField>

## **Returns**

[`AgentBase`][ref-agentbase] -- Returns `this` for method chaining.

## **Example**

```typescript {17}
import { AgentBase, DataMap } from '@signalwire/sdk';

const agent = new AgentBase({ name: 'plant-agent', route: '/plants' });
agent.setPromptText('You are a helpful plant care assistant.');

// Create a DataMap that calls a plant API server-side
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({
    response: 'The plant ${args.plantId} needs ${response.water_schedule} watering.',
    action: [{ say: 'Here is the plant care information.' }],
  });

// Register the DataMap as a SWAIG function
agent.registerSwaigFunction(plantTool.toSwaigFunction());
await agent.serve();
```