- 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
- You register functions with the SDK.
- The SDK sends their schemas to AGO with each message.
- When a function is relevant, the agent calls it.
- The SDK runs the function in the browser and sends the result back.
- The agent uses the result to continue its answer.
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:
You can also use these standard JSON Schema keywords:
items, nested properties, minimum, maximum, const, default, title, pattern, format, minLength, maxLength, minItems, maxItems, uniqueItems, multipleOf, exclusiveMinimum, exclusiveMaximum, additionalProperties, required, nullable, anyOf, oneOf and allOf.
Any other keyword, including $ref, is rejected, and the error names the keyword and where it appears. AGO sends your schema to the agent as written, so only this list is accepted.
Limits
A request that breaks one of these limits is rejected with400 invalid_request_error when you send the message, before the agent runs. The error names the function at fault, except for the per-request totals.
Two limits shorten or skip instead of rejecting:
- Descriptions are shortened: 1,000 characters for a function’s
description, 500 for adescriptionortitleinsideparameters. ThenavigateToPagefunction the SDK builds from your page list can use up to 20,000 characters. - A function whose name matches one of the agent’s server-side tools is left out of that turn. Pick names that differ from your agent’s tool names.
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. The more functions the agent has to choose from, the harder it is to pick the right one: past about 10, expect it 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 endpoints used by the SDK
- Tools — Server-side tools that agents can use
