***

title: FunctionResult
slug: /reference/typescript/agents/function-result
description: Fluent interface for returning responses and actions from SWAIG tool functions.
max-toc-depth: 3
---------------------

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

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

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

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

[swaig-function]: /docs/swml/reference/ai/swaig/functions

[swml-swaig-functions-reference]: /docs/swml/reference/ai/swaig/functions

[setresponse]: /docs/server-sdks/reference/typescript/agents/function-result/set-response

[setpostprocess]: /docs/server-sdks/reference/typescript/agents/function-result/set-post-process

[addaction]: /docs/server-sdks/reference/typescript/agents/function-result/add-action

[addactions]: /docs/server-sdks/reference/typescript/agents/function-result/add-actions

[todict]: /docs/server-sdks/reference/typescript/agents/function-result/to-dict

[connect]: /docs/server-sdks/reference/typescript/agents/function-result/connect

[hangup]: /docs/server-sdks/reference/typescript/agents/function-result/hangup

[hold]: /docs/server-sdks/reference/typescript/agents/function-result/hold

[swmltransfer]: /docs/server-sdks/reference/typescript/agents/function-result/swml-transfer

[say]: /docs/server-sdks/reference/typescript/agents/function-result/say

[waitforuser]: /docs/server-sdks/reference/typescript/agents/function-result/wait-for-user

[stop]: /docs/server-sdks/reference/typescript/agents/function-result/stop

[playbackgroundfile]: /docs/server-sdks/reference/typescript/agents/function-result/play-background-file

[stopbackgroundfile]: /docs/server-sdks/reference/typescript/agents/function-result/stop-background-file

[recordcall]: /docs/server-sdks/reference/typescript/agents/function-result/record-call

[stoprecordcall]: /docs/server-sdks/reference/typescript/agents/function-result/stop-record-call

[tap]: /docs/server-sdks/reference/typescript/agents/function-result/tap

[stoptap]: /docs/server-sdks/reference/typescript/agents/function-result/stop-tap

[updateglobaldata]: /docs/server-sdks/reference/typescript/agents/function-result/update-global-data

[removeglobaldata]: /docs/server-sdks/reference/typescript/agents/function-result/remove-global-data

[setmetadata]: /docs/server-sdks/reference/typescript/agents/function-result/set-metadata

[removemetadata]: /docs/server-sdks/reference/typescript/agents/function-result/remove-metadata

[swmlchangestep]: /docs/server-sdks/reference/typescript/agents/function-result/swml-change-step

[swmlchangecontext]: /docs/server-sdks/reference/typescript/agents/function-result/swml-change-context

[switchcontext]: /docs/server-sdks/reference/typescript/agents/function-result/switch-context

[swmluserevent]: /docs/server-sdks/reference/typescript/agents/function-result/swml-user-event

[simulateuserinput]: /docs/server-sdks/reference/typescript/agents/function-result/simulate-user-input

[togglefunctions]: /docs/server-sdks/reference/typescript/agents/function-result/toggle-functions

[enablefunctionsontimeout]: /docs/server-sdks/reference/typescript/agents/function-result/enable-functions-on-timeout

[adddynamichints]: /docs/server-sdks/reference/typescript/agents/function-result/add-dynamic-hints

[cleardynamichints]: /docs/server-sdks/reference/typescript/agents/function-result/clear-dynamic-hints

[setendofspeechtimeout]: /docs/server-sdks/reference/typescript/agents/function-result/set-end-of-speech-timeout

[setspeecheventtimeout]: /docs/server-sdks/reference/typescript/agents/function-result/set-speech-event-timeout

[updatesettings]: /docs/server-sdks/reference/typescript/agents/function-result/update-settings

[enableextensivedata]: /docs/server-sdks/reference/typescript/agents/function-result/enable-extensive-data

[replaceinhistory]: /docs/server-sdks/reference/typescript/agents/function-result/replace-in-history

[sendsms]: /docs/server-sdks/reference/typescript/agents/function-result/send-sms

[pay]: /docs/server-sdks/reference/typescript/agents/function-result/pay

[createpaymentprompt]: /docs/server-sdks/reference/typescript/agents/function-result/create-payment-prompt

[createpaymentaction]: /docs/server-sdks/reference/typescript/agents/function-result/create-payment-action

[createpaymentparameter]: /docs/server-sdks/reference/typescript/agents/function-result/create-payment-parameter

[siprefer]: /docs/server-sdks/reference/typescript/agents/function-result/sip-refer

[joinroom]: /docs/server-sdks/reference/typescript/agents/function-result/join-room

[joinconference]: /docs/server-sdks/reference/typescript/agents/function-result/join-conference

[executeswml]: /docs/server-sdks/reference/typescript/agents/function-result/execute-swml

[executerpc]: /docs/server-sdks/reference/typescript/agents/function-result/execute-rpc

[rpcdial]: /docs/server-sdks/reference/typescript/agents/function-result/rpc-dial

[rpcaimessage]: /docs/server-sdks/reference/typescript/agents/function-result/rpc-ai-message

[rpcaiunhold]: /docs/server-sdks/reference/typescript/agents/function-result/rpc-ai-unhold

`FunctionResult` is the return type for all SWAIG tool functions. It wraps a response
message (text for the AI to speak) and an ordered list of actions (transfers, SMS,
data updates, context switches, and more). Every method returns `this`, so you can
chain calls into a single fluent expression.

Returned from functions defined with [`defineTool()`][define-tool] on
[`AgentBase`][agentbase].

<Info>
  FunctionResult builds the response payload for a [SWAIG function][swaig-function].
  See the [SWML SWAIG functions reference][swml-swaig-functions-reference] for the
  full response format specification.
</Info>

## **Properties**

<ParamField path="response" type="string" default="''" toc={true}>
  Text the AI speaks back to the caller after the function executes.
</ParamField>

<ParamField path="action" type={"Record<string, unknown>[]"} default="[]" toc={true}>
  Ordered list of action objects to execute. Actions run sequentially in the
  order they were added.
</ParamField>

<ParamField path="postProcess" type="boolean" default="false" toc={true}>
  When `true`, the AI speaks the response and takes one more conversational turn
  with the user before executing actions. When `false` (default), actions execute
  immediately after the response.
</ParamField>

## **Example**

```typescript {10}
import { AgentBase, FunctionResult } from '@signalwire/sdk';

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

agent.defineTool({
  name: 'transfer_to_billing',
  description: 'Transfer the caller to billing',
  handler: (args, rawData) => {
    return new FunctionResult(
      "I'll transfer you to billing. Anything else first?",
      true // postProcess
    )
      .updateGlobalData({ transferred: true })
      .sendSms({
        toNumber: '+15551234567',
        fromNumber: '+15559876543',
        body: 'You are being transferred to billing.',
      })
      .connect('+15551234567', true);
  },
});

agent.run();
```

## **Fluent Chaining Pattern**

Every method on `FunctionResult` returns `this`, so you build complex responses
in a single expression. Actions execute in the order they are added.

<Warning>
  Terminal actions like `connect(destination, true)` and `hangup()` end the call flow.
  Place them **last** in the chain so that preceding actions (data updates, SMS, etc.)
  have a chance to execute.
</Warning>

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

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

agent.defineTool({
  name: 'transfer_now',
  description: 'Transfer the caller',
  handler: (args, rawData) => {
    // Data update + SMS execute before the terminal transfer
    return new FunctionResult('Transferring you now.')
      .updateGlobalData({ transferred: true })
      .sendSms({
        toNumber: '+15551234567',
        fromNumber: '+15559876543',
        body: 'Your call is being transferred.',
      })
      .connect('+15551234567', true); // terminal — goes last
  },
});

agent.run();
```

## **Methods**

### Core

<CardGroup cols={3}>
  <Card title="setResponse" href="/docs/server-sdks/reference/typescript/agents/function-result/set-response">
    Set or replace the response text on a FunctionResult.
  </Card>

  <Card title="setPostProcess" href="/docs/server-sdks/reference/typescript/agents/function-result/set-post-process">
    Enable or disable post-processing on a FunctionResult.
  </Card>

  <Card title="addAction" href="/docs/server-sdks/reference/typescript/agents/function-result/add-action">
    Append a raw action to the FunctionResult action list.
  </Card>

  <Card title="addActions" href="/docs/server-sdks/reference/typescript/agents/function-result/add-actions">
    Append multiple raw actions to the FunctionResult action list.
  </Card>

  <Card title="toDict" href="/docs/server-sdks/reference/typescript/agents/function-result/to-dict">
    Serialize a FunctionResult to the SWAIG response format.
  </Card>
</CardGroup>

### Call Control

<CardGroup cols={3}>
  <Card title="connect" href="/docs/server-sdks/reference/typescript/agents/function-result/connect">
    Transfer or connect the call to another destination.
  </Card>

  <Card title="hangup" href="/docs/server-sdks/reference/typescript/agents/function-result/hangup">
    End the call immediately.
  </Card>

  <Card title="hold" href="/docs/server-sdks/reference/typescript/agents/function-result/hold">
    Put the call on hold with an optional timeout.
  </Card>

  <Card title="swmlTransfer" href="/docs/server-sdks/reference/typescript/agents/function-result/swml-transfer">
    Transfer the call to a SWML endpoint with a return message.
  </Card>
</CardGroup>

### Speech

<CardGroup cols={3}>
  <Card title="say" href="/docs/server-sdks/reference/typescript/agents/function-result/say">
    Make the AI agent speak specific text immediately.
  </Card>

  <Card title="waitForUser" href="/docs/server-sdks/reference/typescript/agents/function-result/wait-for-user">
    Control how the agent pauses and waits for user input.
  </Card>

  <Card title="stop" href="/docs/server-sdks/reference/typescript/agents/function-result/stop">
    Stop the agent execution immediately.
  </Card>
</CardGroup>

### Media

<CardGroup cols={3}>
  <Card title="playBackgroundFile" href="/docs/server-sdks/reference/typescript/agents/function-result/play-background-file">
    Play an audio or video file in the background during a call.
  </Card>

  <Card title="stopBackgroundFile" href="/docs/server-sdks/reference/typescript/agents/function-result/stop-background-file">
    Stop the currently playing background audio file.
  </Card>

  <Card title="recordCall" href="/docs/server-sdks/reference/typescript/agents/function-result/record-call">
    Start recording the call in the background.
  </Card>

  <Card title="stopRecordCall" href="/docs/server-sdks/reference/typescript/agents/function-result/stop-record-call">
    Stop an active background call recording.
  </Card>

  <Card title="tap" href="/docs/server-sdks/reference/typescript/agents/function-result/tap">
    Stream call audio to an external endpoint via WebSocket or RTP.
  </Card>

  <Card title="stopTap" href="/docs/server-sdks/reference/typescript/agents/function-result/stop-tap">
    Stop an active media tap stream.
  </Card>
</CardGroup>

### Data

<CardGroup cols={3}>
  <Card title="updateGlobalData" href="/docs/server-sdks/reference/typescript/agents/function-result/update-global-data">
    Set or update key-value pairs in the global session data.
  </Card>

  <Card title="removeGlobalData" href="/docs/server-sdks/reference/typescript/agents/function-result/remove-global-data">
    Remove one or more keys from the global session data.
  </Card>

  <Card title="setMetadata" href="/docs/server-sdks/reference/typescript/agents/function-result/set-metadata">
    Set function-scoped metadata key-value pairs.
  </Card>

  <Card title="removeMetadata" href="/docs/server-sdks/reference/typescript/agents/function-result/remove-metadata">
    Remove one or more keys from the current function's metadata store.
  </Card>
</CardGroup>

### Context Navigation

<CardGroup cols={3}>
  <Card title="swmlChangeStep" href="/docs/server-sdks/reference/typescript/agents/function-result/swml-change-step">
    Transition to a different step within the current conversation context.
  </Card>

  <Card title="swmlChangeContext" href="/docs/server-sdks/reference/typescript/agents/function-result/swml-change-context">
    Switch to a different conversation context.
  </Card>

  <Card title="switchContext" href="/docs/server-sdks/reference/typescript/agents/function-result/switch-context">
    Perform an advanced context switch with prompt replacement and history control.
  </Card>
</CardGroup>

### Events

<CardGroup cols={2}>
  <Card title="swmlUserEvent" href="/docs/server-sdks/reference/typescript/agents/function-result/swml-user-event">
    Send a custom user event through SWML for real-time UI updates.
  </Card>

  <Card title="simulateUserInput" href="/docs/server-sdks/reference/typescript/agents/function-result/simulate-user-input">
    Inject text as simulated user speech input.
  </Card>
</CardGroup>

### Functions

<CardGroup cols={2}>
  <Card title="toggleFunctions" href="/docs/server-sdks/reference/typescript/agents/function-result/toggle-functions">
    Enable or disable specific SWAIG functions at runtime.
  </Card>

  <Card title="enableFunctionsOnTimeout" href="/docs/server-sdks/reference/typescript/agents/function-result/enable-functions-on-timeout">
    Allow SWAIG function calls when a speaker timeout occurs.
  </Card>
</CardGroup>

### Hints

<CardGroup cols={2}>
  <Card title="addDynamicHints" href="/docs/server-sdks/reference/typescript/agents/function-result/add-dynamic-hints">
    Add speech recognition hints dynamically during a call.
  </Card>

  <Card title="clearDynamicHints" href="/docs/server-sdks/reference/typescript/agents/function-result/clear-dynamic-hints">
    Remove all dynamically added speech recognition hints.
  </Card>
</CardGroup>

### Settings

<CardGroup cols={3}>
  <Card title="setEndOfSpeechTimeout" href="/docs/server-sdks/reference/typescript/agents/function-result/set-end-of-speech-timeout">
    Adjust the end-of-speech silence timeout for speech recognition.
  </Card>

  <Card title="setSpeechEventTimeout" href="/docs/server-sdks/reference/typescript/agents/function-result/set-speech-event-timeout">
    Adjust the speech event timeout for noisy environments.
  </Card>

  <Card title="updateSettings" href="/docs/server-sdks/reference/typescript/agents/function-result/update-settings">
    Update AI runtime settings dynamically during a call.
  </Card>

  <Card title="enableExtensiveData" href="/docs/server-sdks/reference/typescript/agents/function-result/enable-extensive-data">
    Send full data to the LLM for the current turn only.
  </Card>

  <Card title="replaceInHistory" href="/docs/server-sdks/reference/typescript/agents/function-result/replace-in-history">
    Control how this function call appears in the AI's conversation history.
  </Card>
</CardGroup>

### SMS

<CardGroup cols={2}>
  <Card title="sendSms" href="/docs/server-sdks/reference/typescript/agents/function-result/send-sms">
    Send an SMS or MMS message from a tool function.
  </Card>
</CardGroup>

### Payment

<CardGroup cols={3}>
  <Card title="pay" href="/docs/server-sdks/reference/typescript/agents/function-result/pay">
    Collect and process a credit card payment during a call.
  </Card>

  <Card title="createPaymentPrompt" href="/docs/server-sdks/reference/typescript/agents/function-result/create-payment-prompt">
    Build a payment prompt object for use with pay().
  </Card>

  <Card title="createPaymentAction" href="/docs/server-sdks/reference/typescript/agents/function-result/create-payment-action">
    Build a single action entry for a payment prompt.
  </Card>

  <Card title="createPaymentParameter" href="/docs/server-sdks/reference/typescript/agents/function-result/create-payment-parameter">
    Build a parameter entry for the pay() method.
  </Card>
</CardGroup>

### SIP

<CardGroup cols={2}>
  <Card title="sipRefer" href="/docs/server-sdks/reference/typescript/agents/function-result/sip-refer">
    Send a SIP REFER message to transfer the call in a SIP environment.
  </Card>
</CardGroup>

### Rooms and Conferences

<CardGroup cols={2}>
  <Card title="joinRoom" href="/docs/server-sdks/reference/typescript/agents/function-result/join-room">
    Join a SignalWire room for multi-party communication.
  </Card>

  <Card title="joinConference" href="/docs/server-sdks/reference/typescript/agents/function-result/join-conference">
    Join an ad-hoc audio conference with extensive configuration options.
  </Card>
</CardGroup>

### SWML and RPC

<CardGroup cols={3}>
  <Card title="executeSwml" href="/docs/server-sdks/reference/typescript/agents/function-result/execute-swml">
    Execute a raw SWML document as an action.
  </Card>

  <Card title="executeRpc" href="/docs/server-sdks/reference/typescript/agents/function-result/execute-rpc">
    Execute a generic RPC method on a call.
  </Card>

  <Card title="rpcDial" href="/docs/server-sdks/reference/typescript/agents/function-result/rpc-dial">
    Dial out to a phone number with a destination SWML URL via RPC.
  </Card>

  <Card title="rpcAiMessage" href="/docs/server-sdks/reference/typescript/agents/function-result/rpc-ai-message">
    Inject a message into the AI agent running on another call.
  </Card>

  <Card title="rpcAiUnhold" href="/docs/server-sdks/reference/typescript/agents/function-result/rpc-ai-unhold">
    Release another call from hold via RPC.
  </Card>
</CardGroup>