Skip to main content
Client functions are JavaScript functions you register in the browser with the JavaScript SDK. When a registered function is relevant, the agent calls it: the SDK runs the function on the page and sends the result back to the agent. Use them for:
  • 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

  1. You register functions with the SDK.
  2. The SDK sends their schemas to AGO with each message.
  3. When a function is relevant, the agent calls it.
  4. The SDK runs the function in the browser and sends the result back.
  5. The agent uses the result to continue its answer.
The agent sees each function’s description and parameters and decides whether and when to call it. You do not trigger it yourself.

Registering a Function

Use client.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 with 400 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 a description or title inside parameters. The navigateToPage function 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.
Valid 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:
This is useful when navigating between pages where different functions apply. For example, register cart functions only on the product page and unregister them when the user navigates away.

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 the description 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