For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Log inSign up
Support
GuidesReference
GuidesReference
    • Core
      • Overview
    • Agents
      • Overview
      • AgentBase
      • AgentServer
      • Configuration
      • ContextBuilder
      • DataMap
      • FunctionResult
      • Helper Functions & Utilities
      • LiveWire
      • PomBuilder
      • Prefabs
      • SkillBase
      • SkillManager
      • SkillRegistry
      • Skills
      • SwaigFunction
        • execute
        • toSwaig
        • validateArgs
      • SwmlBuilder
      • SWMLService
    • RELAY
      • Overview
      • Actions
      • Call
      • Constants
      • Events
      • Message
      • RelayClient
      • RelayError
    • REST Client
      • Overview
      • Addresses
      • Calling
      • ChatResource
      • Compat
      • Datasphere
      • Fabric
      • ImportedNumbersResource
      • Logs
      • LookupResource
      • MFA
      • Number Groups
      • Phone Numbers
      • Project
      • PubSubResource
      • Queues
      • Recordings
      • Registry
      • RestClient
      • RestError
      • Short Codes
      • SIP Profile
      • Verified Callers
      • Video
LogoLogoSignalWire Docs
Log inSign up
Support
On this page
  • Parameters
  • Returns
  • Example
AgentsSwaigFunction

execute

|View as Markdown|Open in Claude|
Was this page helpful?
Edit this page
Previous

toSwaig

Next
Built with

Execute the function with the given arguments. Calls the handler and normalizes the return value into a serialized result dictionary.

Parameters

args
Record<string, unknown>Required

Parsed arguments for the function, matching the parameter schema.

rawData
Record<string, unknown>

Full raw request data including global_data, call_id, caller_id_number, meta_data, and ai_session_id.

Returns

Promise<Record<string, unknown>> — The function result as a dictionary (from FunctionResult.toDict()). If the handler throws an exception, returns a generic error message rather than exposing internal details.

The handler can return a FunctionResult, an object with a "response" key, or a plain string. All formats are normalized to a result dictionary.

Example

1import { SwaigFunction, FunctionResult } from '@signalwire/sdk';
2
3const func = new SwaigFunction({
4 name: "lookup_account",
5 handler: async (args, rawData) => {
6 const accountId = (args.account_id as string) ?? "";
7 return new FunctionResult(`Account ${accountId} is active.`);
8 },
9 description: "Look up account status",
10 parameters: {
11 type: "object",
12 properties: {
13 account_id: { type: "string", description: "Account ID" },
14 },
15 required: ["account_id"],
16 },
17});
18
19const result = await func.execute({ account_id: "12345" });
20console.log(result);
21// { response: "Account 12345 is active." }