- Navigating your application — open a specific page, scroll to a section, or show a modal
- Reading application state — return the current user’s cart, selected filters, or form values
- Triggering UI actions — open a contact form, start a product tour, or play a video
- Calling browser APIs — get the current time, geolocation, or clipboard contents
How It Works
Registering a Function
Useclient.registerFunction() with three arguments: a name, a handler, and a schema that describes the function to the agent.
Function with Parameters
Schema Reference
Each property in
parameters.properties accepts:
Naming Rules
Function names must follow these rules:- Only letters, numbers, underscores, and hyphens
- Between 1 and 50 characters
- No spaces or special characters
getCurrentTime, add-to-cart, search_products
Invalid names: get current time, ../hack, my@function
Unregistering a Function
Remove a function when it is no longer relevant:Listing Registered Functions
Listening to Function Events
Track when functions are invoked and when results are returned:Error Handling
If a registered function throws an error, the SDK catches it and sends the error message back to the agent. The agent can then inform the user or try an alternative approach.Best Practices
Write Clear Descriptions
The agent relies on thedescription field to decide when to call a function. Be specific about what the function does and when it should be used.
Return Structured Data
Return objects with descriptive keys so the agent can use the information in its response.Keep the Number of Functions Low
You can send up to 30 client functions with a message. Above that, the request is rejected. Stay well under the limit whenever you can. The more functions the agent has to choose from, the harder it becomes to pick the right one — past 10 functions in a single message, expect the agent to call the wrong function or miss the right one more often. Register only the functions relevant to the current page or state, and unregister the ones that no longer apply.Keep Functions Focused
Each function should do one thing. Register multiple focused functions rather than one function that does everything.Register Contextually
Register functions that are relevant to the current page or state. On a product page, register product-related functions. On the checkout page, register checkout-related functions.Complete Example
Related Documentation
- JavaScript SDK — Full SDK setup and usage guide
- SDK API Reference — REST API endpoints
- Tools — Server-side tools that agents can use
