- 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:
Standard JSON Schema keywords are passed to the agent as written —
items to type
the elements of an array, nested properties to describe an object, minimum and
maximum to bound a number, plus const, default, title, pattern, format,
minLength, maxLength, minItems, maxItems, uniqueItems, multipleOf,
exclusiveMinimum, exclusiveMaximum, additionalProperties, required,
nullable, anyOf, oneOf and allOf.
Anything outside that list is rejected, including $ref. Your schema reaches the
agent as you wrote it, so an unrecognized keyword would be a way to slip text into
the agent’s instructions — the rejection names the keyword and where it sits.
Break any of these and the request comes back 400 invalid_request_error, so you
find out when you declare the function rather than when the agent tries to use it.
The first three name the function at fault; the last reports the totals:
Two things are adjusted rather than refused.
A long description is shortened, not rejected: 1,000 characters for a function’s own
description, 500 for a description or title anywhere inside parameters. The
navigation function the SDK builds for you is the exception — its description is
the list of your pages, so it gets 20,000.
A function whose name collides with one of the agent’s server-side tools is left out
of that turn. The name is yours to pick, so keep your function names distinct from
your agent’s tool names.
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
