> Fetch clean Markdown by appending `.md` to any page URL under https://signalwire.com/docs or requesting it with the HTTP header `Accept: text/markdown`. The root index at https://signalwire.com/docs/llms.txt lists the available documentation indexes. # Helper Functions > Convenience functions for creating common DataMap patterns. [ref-datamap]: /docs/server-sdks/reference/typescript/agents/data-map [ref-functionresult]: /docs/server-sdks/reference/typescript/agents/function-result ```typescript {3} import { createSimpleApiTool } from '@signalwire/sdk'; const weatherTool = createSimpleApiTool({ name: 'get_weather', url: 'https://api.weather.com/v1/current?q=${args.location}', responseTemplate: 'Weather: ${response.current.condition.text}, ${response.current.temp_f}F', parameters: { location: { type: 'string', description: 'City name', required: true }, }, }); ``` Create a DataMap for a straightforward single-endpoint API call with minimal configuration. ## **Parameters** **`name`** `string` — required Function name. --- **`url`** `string` — required API endpoint URL. --- **`responseTemplate`** `string` — required Template string for formatting the response. --- **`parameters`** `Record` Parameter definitions. Keys are parameter names, values are objects with `"type"`, `"description"`, and optional `"required"` keys. --- **`method`** `string` — default: GET HTTP method. --- **`headers`** `Record` HTTP headers. --- **`body`** `Record` Request body for POST/PUT. --- **`errorKeys`** `string[]` Keys indicating an error response. --- ## **Returns** [`DataMap`][ref-datamap] -- A fully configured DataMap ready for further chaining or conversion. --- ```typescript {3} import { createExpressionTool, FunctionResult } from '@signalwire/sdk'; const controlTool = createExpressionTool({ name: 'playback_control', patterns: { '${args.command}': ['play.*', new FunctionResult('Playing.')], }, parameters: { command: { type: 'string', description: 'Playback command', required: true }, }, }); ``` Create a DataMap for pattern-matching responses without API calls. ## **Parameters** **`name`** `string` — required Function name. --- **`patterns`** `Record` — required Object mapping test values to `[pattern, FunctionResult]` tuples. --- **`parameters`** `Record` Parameter definitions (same format as `createSimpleApiTool`). --- ## **Returns** [`DataMap`][ref-datamap] -- A fully configured DataMap. ## **Example** ```typescript {9} import { AgentBase, FunctionResult, createSimpleApiTool, createExpressionTool, } from '@signalwire/sdk'; // Simple API tool -- one line instead of a full DataMap chain const weather = createSimpleApiTool({ name: 'get_weather', url: 'https://api.weatherapi.com/v1/current.json?key=KEY&q=${enc:args.city}', responseTemplate: 'Weather in ${args.city}: ${response.current.condition.text}', parameters: { city: { type: 'string', description: 'City name', required: true }, }, errorKeys: ['error'], }); // Expression tool -- pattern matching without API calls const greeting = createExpressionTool({ name: 'greet', patterns: { '${args.language}': ['spanish|espanol', new FunctionResult('Hola!')], }, parameters: { language: { type: 'string', description: 'Language to greet in' }, }, }); const agent = new AgentBase({ name: 'helper-demo' }); agent.setPromptText('You are a helpful assistant.'); agent.registerSwaigFunction(weather.toSwaigFunction()); agent.registerSwaigFunction(greeting.toSwaigFunction()); agent.run(); ``` > Convenience functions for creating common DataMap patterns.