Skip to navigation

Add a semantic gate: a yes/no question a decision model answers about the call right before the function runs. Every gate must pass. When one fails, the data_map doesn’t run, and the AI gets the on_fail output of the first failing gate.

Call gate() once per gate, up to 8. The gates are checked when toSwaigFunction() builds the function, which throws for any gate the platform would refuse. To set what the AI says during the check, use gateFillers().

Parameters

gate
SemanticGate | Record<string, unknown>Required

A SemanticGate, or a gate object in the platform’s shape (question, threshold, on_fail, and optional id, criteria).

Returns

DataMap — Self for method chaining.

Examples

import { DataMap, FunctionResult, SemanticGate } from '@signalwire/sdk';
const cancelOrder = new DataMap('cancel_order')
.purpose("Cancel one of the caller's open orders")
.parameter('order_id', 'string', 'The order number', { required: true })
.gate(
new SemanticGate(
'Has the caller asked in `conversation` to cancel the order in `proposed_function`?',
0.9,
'cancel_order was not run. Ask the caller which order to cancel.',
),
)
.webhook('POST', 'https://api.example.com/orders/${enc:args.order_id}/cancel')
.output(new FunctionResult('The order is cancelled. Tell the caller.'));
console.log(cancelOrder.toSwaigFunction());