Functions are an advanced feature designed to be used by developers. If you just need to do an API call, we recommend using the API tool instead.

Creating a Function tool
Create a new Function tool from Tools → New tool → Function, or click Function → Create new function directly from a Playbook’s tool panel. Once created, you can call the Function tool from inside a Playbook or Workflow using the Function step. A Function tool cannot be used directly by the Agent. Each function has four components:- Input variables: Data passed into the function when it runs. You can optionally add descriptions to each input variable.
- Output variables: Data returned by the function that can be used later in the conversation.
- Paths: Different exit routes the function can take based on its results. Only available when used in workflows.
- Code: The JavaScript logic that processes inputs and returns results.
Writing function code
Every function must export a default asyncmain function. This is the entry point Voiceflow calls when the function runs.
Accessing input variables
Input variables are available throughargs.inputVars:
Returning results
Functions return an object containing runtime commands that tell Voiceflow what to do next:- outputVars: An object mapping output variable names to their values. These variables must also have been set in the sidebar of the function window.
- next: Specifies which path to exit through (eg:
{ path: 'success' }). If your function has no paths defined, a default exit is used automatically. Paths are ignored when functions are used in Playbooks. - trace: An array of traces that become part of the agent’s response.
Making network requests
Functions have access to a modified fetch API for calling external services:Differences from standard fetch
The Voiceflow fetch API differs from the standard browser/Node.js fetch in how you access the response body. Instead of calling.json() as a method, access the .json property directly:
Supported traces
Traces let your function generate responses as part of the conversation. Different trace types are available depending on your project type.Text traces (all project types)
Visual traces (chat projects only)
Listening for user input (workflows only)
When a function is used in a workflow via the Function step, it can pause execution and wait for user input using listen functionality. This is useful when you want the user to click a button or make a selection before continuing. Note: Listen functionality is not available when functions are called from Playbooks. To enable listening, use thenext command with listen: true:
next command for listening includes:
- listen: Set to
trueto pause and wait for input, orfalseto continue immediately while keeping events available for later. - to: An array of conditions. Each condition has an
onquery (using MongoDB-style syntax) and adestpath to exit through if matched. - defaultTo: The path to use if no conditions match.
Persistent events
Whenlisten is set to false, the function continues immediately but the defined events persist for the entire session. Users can trigger these events at any point later in the conversation:
Testing functions
You can test your function directly in the editor by clicking Run in the top right corner of the function window. The test panel lets you enter values for your input variables and shows the output variables, traces, and execution time. Use debug traces to surface diagnostic information during testing:Limitations
Function tools have some important limitations:- No module imports: you cannot import external npm packages or use
require(). - No browser/Node.js APIs: methods like
setTimeout(),setInterval(), and other runtime-specific APIs are not available. Only standard ECMAScript built-ins are supported. - No paths in Playbooks: functions called from Playbooks cannot use multiple paths or listen functionality. They can only return output variables and traces.