Voice Agent/Bot State
Voice agents/bots are often used to collect various types of data. For instance, customers are asked for their names, date of birth, what product they want to book or cancel, the time slot that is favorable etc.
This data is usually collected using the defined tools, where the parameters contain the information the LLM extracted from the customers response.
In order to carry this data between function calls as well as stages, there is a state object that is active during the entire call session that can be used to store and retrieve such information.
In order to access/and use the state within the prompt or tool section, the state must be explicitely enabled. After modification of the state, the modified state object must be returned similar to the stack otherwise the modification will not be visible in subsequent function calls and stages.
State Object
The state object is a simple Javascript object that can be used to store flat or even nested information.
No Code Data Collection
Data collection is happening during an action, i.e., a function call. Hence, it is possible to define where the collected information should be stored in the state directly in the tools tools section of a function definition/configuration:

The key/path defines where the collected/extracted data should be stored within the state object. The dot notation allows to stored it in a nested data structure.
Code-based Data Collection
The following example shows how manually store the collected information in the state object and retunning it when leaving the function:
function someFunction(params) {
if (!params["state"]["user"]) params["state"]["user"] = {};
params["state"]["user"]["name"] = params["user"];
return { state: params["state"] };
}