Enforcing structure or format

When getting information from the user, it is often required that the information be ingested in a specific format.

For example for providing a date, there are multiple ways users can say the date - “7th May 2025” or “May the 7th this year” etc. In such cases, you can provide the format in which you want the date to be in the description of the action.

example

const { setActions } = usePonder();
const submitDate = (date) => {
    console.log(date) // <-- will always have YYYY-MM-DD format
}


setActions([
    {
        name: "submitDate"
        description: "Call this function when the user needs to provide a date. Make sure the format of the date is YYYY-MM-DD"
        arguments: ["name": "date", "type": "string", "required": true]
        function: submitDate
    }
])

Controlling agent behaviour based on function output

Often times you might want the agent to say or act in a specific manner based on the output of the function. In such cases, the return of the function can include instructions for the agent on how to handle the outcome. For example, in our submitDate example, we can tell the agent to tell the user to provide a date after 2025.

example

const { setActions } = usePonder();
const submitDate = (date) => {
    console.log(date) // <-- will always have YYYY-MM-DD format

    // your date handling logic

    if (date.year < 2025) {
        return {status: "failure", message: "Tell the user to only provide dates after 1 Jan 2025"}
    }
    else {
        return {status: "success", message: "Say nothing."}
    }
}


setActions([
    {
        name: "submitDate"
        description: "Call this function when the user needs to provide a date. Make sure the format of the date is YYYY-MM-DD"
        arguments: ["name": "date", "type": "string", "required": true]
        function: submitDate
    }
])