# Client tools: a talking avatar that controls modals, UI and cart

Let a live AI avatar open a modal, scroll the page or add to cart: client tools run in your page and return a result it speaks, within 2\.5 seconds\.

Published: 2026-11-24T02:44:14.642Z
Updated: 2026-11-24T02:44:14.642Z
Canonical: https://realtimeavatar.ai/blog/avatar-client-tools-ui-modals-cart
Markdown: [en](https://realtimeavatar.ai/blog/avatar-client-tools-ui-modals-cart.md)

Declare each UI action as a client tool that runs in your page. The character calls show_modal or add_to_cart mid-conversation, your handler calls dialog.showModal(), element.scrollIntoView() or your cart API, and the short string it returns goes back to the model, so the character can say what actually happened on screen. On Realtime Avatar your server opts the call in with clientTools: true, the page registers the tools with attachAvatarTools after the room connects, and each call has 2.5 seconds to answer. Below: five tools you can paste (open a dialog, scroll to a section, highlight an element, add to cart, show a vocabulary card), a game variant, and the rules that keep them safe.

Getting the result back into the conversation is where platforms differ. From each vendor's own docs, read 16 November 2026:

- Realtime Avatar: yes. What execute returns goes back to the model as the tool result, inside a fixed 2.5-second deadline.
- Anam: yes when a client tool sets awaitResult to true, with toolTimeoutSeconds from 1 to 600 seconds (10 by default). The default, false, is fire-and-forget.
- Tavus: yes. Your app answers each conversation.tool_call event with a conversation.tool_result carrying the matching tool_call_id, and that path has no hard timeout.
- Runway Characters: no. Its client tools run in the browser and do not return results to the conversation; Runway points to its server tools when the character must speak from your data.

## The pattern: grant on the server, register in the page, return a sentence

Three pieces make a UI action callable, and each one lives where the trust already is.

1. Grant on the server. Your connect route adds clientTools: true to the call policy (on the wire, capabilities: ["client_tools"]). It is your server's decision, so a page cannot give itself tools, and nothing about a tool appears in the mint request.
2. Register in the page. After the room connects, call attachAvatarTools(room, tools). The manifest is registered over RPC, and the key of each record is the name the model calls, so show_modal is both your object key and the tool's name.
3. Return a sentence. execute receives the arguments and an AbortSignal, does the UI work, and returns a short description of what changed, such as "The pricing dialog is open on the user's screen." The character speaks from that, so it does not claim a dialog opened when the element was missing.

If you have used OpenAI's function calling, this is the same loop with the model side handled for you. OpenAI's guide lists five steps: send the tools, receive a tool call, execute code in your application, send the tool output back in a second request, and receive the final response. On a live avatar call the platform runs the model side, and your page supplies only the execute step. Its return value is the tool output, so there is no second request to write: the character's next words are generated from it.

Two habits separate a demo from a feature. First, write each description like a brief to a colleague: what the tool does and when to reach for it. The docs call the description the whole teaching signal, and it is. Second, put every target the model may name in a JSON Schema enum: section ids, dialog names, variant ids, item names. The model then picks from a closed list instead of inventing a #pricing-table-2 that does not exist. The enum guides the model; your handler is still the gate, so check the value again inside execute.

Saying when each tool applies in the instructions your server sets for the call makes the behavior more predictable:

```
// Server: the session policy your connect route returns opts this call in.
session: async () => ({
  instructions:
    "You are the store's product guide. When the user asks about price, call " +
    "show_modal with 'pricing', then summarize what is on screen. Call add_to_cart " +
    "only when they clearly choose a variant, and remind them checkout is theirs.",
  clientTools: true,
}),

```

## Five tools you can copy

The snippets use only the two exports the Realtime Avatar docs show from realtime-avatar/tools: attachAvatarTools and the AvatarTool type. Element ids, product data and routes are placeholders. The first three tools are pure DOM work with no network calls. They assume dialogs with ids like modal-pricing, sections with plain ids, and elements tagged with a data-explain attribute. Change the lists to match your page.

```
import type { AvatarTool } from "realtime-avatar/tools";

// Every target the model may name, listed once. Ids match elements in your page.
const MODALS = ["pricing", "size-guide", "returns"] as const;
const SECTIONS = ["features", "pricing", "reviews", "faq"] as const;

const isOneOf = <T extends string>(list: readonly T[], value: string): value is T =>
  (list as readonly string[]).includes(value);

export const show_modal: AvatarTool<{ modal: string }> = {
  description:
    "Open a dialog on the user's screen. Use 'pricing' when they ask what it costs, " +
    "'size-guide' when they ask about fit, 'returns' when they ask about returns.",
  parameters: {
    type: "object",
    properties: { modal: { type: "string", enum: [...MODALS] } },
    required: ["modal"],
  },
  execute: ({ modal }) => {
    if (!isOneOf(MODALS, modal)) return "No such dialog. Nothing was opened.";
    const dialog = document.getElementById("modal-" + modal);
    if (!(dialog instanceof HTMLDialogElement)) return "That dialog is not on this page.";
    if (!dialog.open) dialog.showModal();
    return "The " + modal + " dialog is open on the user's screen.";
  },
};

export const scroll_to_section: AvatarTool<{ section: string }> = {
  description: "Scroll the page to a section as you start talking about it.",
  parameters: {
    type: "object",
    properties: { section: { type: "string", enum: [...SECTIONS] } },
    required: ["section"],
  },
  execute: ({ section }) => {
    const el = isOneOf(SECTIONS, section) ? document.getElementById(section) : null;
    if (!el) return "There is no " + section + " section on this page.";
    el.scrollIntoView({ behavior: "smooth", block: "start" });
    return "Scrolled to the " + section + " section.";
  },
};

// "Pointing" is your page outlining an element: the video tile cannot see your layout.
const EXPLAINABLE = ["plan-table", "battery-spec", "warranty-badge"] as const;

export const highlight_element: AvatarTool<{ target: string }> = {
  description: "Outline one part of the page for a few seconds while you explain it.",
  parameters: {
    type: "object",
    properties: { target: { type: "string", enum: [...EXPLAINABLE] } },
    required: ["target"],
  },
  execute: ({ target }) => {
    const el = isOneOf(EXPLAINABLE, target)
      ? document.querySelector('[data-explain="' + target + '"]')
      : null;
    if (!el) return "Nothing called " + target + " is on screen.";
    el.scrollIntoView({ behavior: "smooth", block: "nearest" });
    el.classList.add("avatar-highlight"); // your CSS: an outline or a pulse
    setTimeout(() => el.classList.remove("avatar-highlight"), 3000);
    return "Highlighted " + target + ".";
  },
};

```

A detail from MDN that matters on a live call: showModal() opens the dialog as modal, which makes the rest of the page inert until it closes. That includes your call controls when they sit outside the dialog, so the user cannot mute or hang up until it closes. Give every dialog a visible close button (on desktop, Esc also closes a modal dialog), or use show() for a non-modal panel when the user should keep access to the call. For scrolling, behavior: "smooth" animates the move, block: "start" aligns the section with the top of the visible area, and block: "nearest" scrolls as little as possible, which suits a highlight on something that may already be in view.

On highlighting: the character's video is its own tile and does not know where your elements are, so "pointing" means your page outlining the element while the character explains it.

### Add to cart, safe to repeat

add_to_cart is the one tool here that writes to your backend, so it is built from the product on screen and is safe to call twice.

```
import type { AvatarTool } from "realtime-avatar/tools";

type Variant = { id: string; label: string };
type Product = { name: string; variants: Variant[] };

// Built from the product the page is showing, so the enum is exactly what is on screen.
export function cartTool(product: Product): AvatarTool<{ variant_id: string; quantity: number }> {
  return {
    description:
      "Put " + product.name + " in the cart when the user clearly picks a variant, " +
      "for example 'I'll take the blue one'. Variants: " +
      product.variants.map((v) => v.id + " = " + v.label).join("; ") +
      ". quantity is the total the customer wants of that variant, not an amount to add. " +
      "If it is unclear which one, ask. Never start checkout.",
    parameters: {
      type: "object",
      properties: {
        variant_id: { type: "string", enum: product.variants.map((v) => v.id) },
        quantity: { type: "integer", minimum: 1, maximum: 10 },
      },
      required: ["variant_id", "quantity"],
    },
    execute: async ({ variant_id, quantity }, { signal }) => {
      const variant = product.variants.find((v) => v.id === variant_id);
      if (!variant) return "That variant is not on this page. Nothing was added.";
      if (!Number.isInteger(quantity) || quantity < 1 || quantity > 10) {
        return "Quantity must be 1 to 10. Nothing was added.";
      }
      if (signal.aborted) return "Cancelled before writing.";
      // PUT sets the line's quantity instead of adding to it, so a call that was
      // abandoned at the deadline and then repeated cannot put two in the cart.
      const res = await fetch("/api/cart/lines/" + encodeURIComponent(variant.id), {
        method: "PUT",
        headers: { "content-type": "application/json" },
        body: JSON.stringify({ quantity }),
        signal,
      });
      if (!res.ok) return "The cart refused that (" + res.status + "). Nothing changed.";
      return quantity + " x " + product.name + ", " + variant.label +
        ", is in the cart. Checkout is the user's button to press.";
    },
  };
}

```

- The enum is exactly the variants on screen, and the description maps each id to its label, so "I'll take the blue one" resolves to a real id, or to a question back to the customer when two variants are blue.
- PUT sets the line's quantity rather than adding to it, and the description tells the model that quantity is the total, so "make it two" sends 2. If the deadline passes mid-request and the customer repeats themselves, the second call writes the same state as the first.
- The signal goes to fetch, and signal.aborted is checked right before the write, which is what the tool calling docs advise for anything slow.
- It never checks out. A cart is reversible; payment stays behind a button the customer presses. Show a small toast with an undo next to the cart icon, so a misheard sentence costs one tap to fix.

### A vocabulary card while the tutor keeps talking

A tutor's tool should return at once so the sentence carries on. Pass in your UI's setter, such as a React state setter or a store action, and the tool only renders.

```
import type { AvatarTool } from "realtime-avatar/tools";

type VocabCard = { word: string; meaning: string; example: string };

// showCard is your UI's setter, for example a React state setter or a store action.
export function vocabTool(showCard: (card: VocabCard) => void): AvatarTool<VocabCard> {
  return {
    description:
      "Show a vocabulary card on screen the first time you introduce a new word, " +
      "then keep talking. One card per new word.",
    parameters: {
      type: "object",
      properties: {
        word: { type: "string", maxLength: 40 },
        meaning: { type: "string", maxLength: 80 },
        example: { type: "string", maxLength: 160 },
      },
      required: ["word", "meaning", "example"],
    },
    execute: ({ word, meaning, example }) => {
      showCard({ word: word.slice(0, 40), meaning: meaning.slice(0, 80), example: example.slice(0, 160) });
      return "The card for '" + word + "' is on screen.";
    },
  };
}

```

maxLength in the schema asks the model to keep cards short, and slice() enforces it, because a schema guides and does not guarantee. In React, keep the tool objects outside render, register them once per connected room, and let the setter trigger the re-render.

### Game variant: give_item and open_door

```
import type { AvatarTool } from "realtime-avatar/tools";
// game is your own game-state object. Its rules decide; the model only asks.

const ITEMS = ["iron_key", "healing_potion", "map_fragment"] as const;
const DOORS = ["cellar", "north_gate"] as const;
const isOneOf = <T extends string>(list: readonly T[], value: string): value is T =>
  (list as readonly string[]).includes(value);

export const give_item: AvatarTool<{ item: string }> = {
  description: "Give the player an item when the quest says they have earned it.",
  parameters: {
    type: "object",
    properties: { item: { type: "string", enum: [...ITEMS] } },
    required: ["item"],
  },
  execute: ({ item }) => {
    if (!isOneOf(ITEMS, item)) return "No such item.";
    const r = game.tryGiveItem(item); // the game's rules decide, not the model
    return r.ok ? "The player now has the " + item + "." : "Not given: " + r.reason;
  },
};

export const open_door: AvatarTool<{ door: string }> = {
  description: "Open a door the player is standing at, once they have what it needs.",
  parameters: {
    type: "object",
    properties: { door: { type: "string", enum: [...DOORS] } },
    required: ["door"],
  },
  execute: ({ door }) => {
    if (!isOneOf(DOORS, door)) return "No such door.";
    const r = game.tryOpenDoor(door);
    return r.ok ? "The " + door + " door is open." : "Still locked: " + r.reason;
  },
};

```

In a browser game the tool is a thin bridge into game state: the NPC asks, the game's own rules decide. A refusal comes back as a reason, such as "Still locked: needs the iron key", which the NPC can turn into a line of dialogue instead of pretending the door opened. The SDKs are TypeScript, React and React Native, so this fits a game that runs in a browser or in React Native, like a canvas game in a web page; there is no Unity or Unreal plugin, so a game built in one of those engines has no supported client today. An NPC your game already draws can run as voice only with mode="voice".

### Register them

```
// Page: room is the LiveKit room your page connected. Each record key is the
// name the model calls.
import { attachAvatarTools } from "realtime-avatar/tools";

const { accepted, rejected } = await attachAvatarTools(room, {
  show_modal,
  scroll_to_section,
  highlight_element,
  add_to_cart: cartTool(product),
  show_vocab_card: vocabTool(setCard),
});
console.info("Tools armed:", accepted);
if (rejected.length > 0) console.warn("Tools the avatar does not have:", rejected);

```

Read the return value. A tool listed in rejected is a tool the character simply does not have, which looks exactly like the model ignoring it, so log it while you develop.

## Keeping actions safe

- The model reaches only what you register. There is no hosted executor: every tool runs in your page or on your server, with your credentials and your authorization rules. A same-origin fetch from a tool sends the signed-in user's cookies by default, so your existing routes authorize it like any click.
- Prefer named tools over a generic one. A click_any_selector or run_script tool lets one misheard sentence press Delete account. Named tools with enum targets keep the reachable surface to the list you wrote.
- Validate every argument inside execute, even with an enum: membership, ranges, lengths. When a value is wrong, return a sentence saying nothing happened instead of acting on it.
- Make side effects idempotent. A tool has 2.5 seconds; after that the platform abandons the call and tells the model it failed. The abort is cooperative: a handler that ignores its AbortSignal keeps running and can still commit, and only its result is discarded. Set state instead of incrementing it, or check signal.aborted right before the write.
- Confirm anything that costs money in your own UI. Let the avatar fill the cart, open the checkout dialog or prefill a form, and leave the final purchase click to the user.

## When the action is slow

The 2.5 seconds is a conversational floor, not a setting: past a couple of seconds of dead air a video call stops feeling live. UI tools rarely come close, but a tool that builds a comparison from your API, prices a quote or calls a model will. Two patterns fit.

- Acknowledge, then finish on screen. Start the work, return at once with what is about to happen, and render the result when it lands. The character says it is building the comparison and keeps the conversation going.
- Run it on your server. Your backend runs the slow step with its own credentials, and the result reaches the character through sendTurn with per-turn instructions, so the next reply is grounded in it. This also keeps secrets out of the page.

```
import type { AvatarTool } from "realtime-avatar/tools";
// buildComparison, renderComparison and renderComparisonError are your app code.

const PLANS = ["basic", "plus", "pro"] as const;

// Slow work: answer inside the deadline, finish on screen.
export const compare_plans: AvatarTool<{ plans: string[] }> = {
  description: "Build a side-by-side comparison of two or three plans the user names.",
  parameters: {
    type: "object",
    properties: {
      plans: { type: "array", items: { type: "string", enum: [...PLANS] }, minItems: 2, maxItems: 3 },
    },
    required: ["plans"],
  },
  execute: ({ plans }) => {
    const valid = plans.filter((p) => (PLANS as readonly string[]).includes(p));
    if (valid.length < 2) return "Name at least two of basic, plus and pro.";
    void buildComparison(valid).then(renderComparison, renderComparisonError);
    return "Building the comparison now. It will appear on screen in a few seconds.";
  },
};

```

## How this differs elsewhere (November 2026)

Each vendor was read from its own docs on 16 November 2026: where the handler runs, and whether its result returns to the conversation.

- Runway Characters client tools: defined with clientTool, passed in the tools array when your server creates the session, and handled in React with useClientEvent. They run entirely in the browser and do not return results to the conversation; Runway points to its server tools when the character must speak from data.
- Runway Page Actions: ready-made click, scroll_to and highlight actions, added by passing pageActionTools when your server creates the session and placing a PageActions component inside its AvatarCall. They target elements by id or by a data-avatar-target attribute, with no custom tool definitions.
- Anam client tools: handled in the browser with registerToolCallHandler. With awaitResult set to true the handler's return value goes back to the LLM; the default, false, is fire-and-forget. toolTimeoutSeconds ranges from 1 to 600 seconds, 10 by default.
- Tavus: by default a tool call reaches your frontend as a conversation.tool_call event on the call's data channel, and your app answers with conversation.tool_result carrying the matching tool_call_id. That path has no hard timeout, and app messages are capped at 4 KB; Tavus can instead deliver a tool call as an HTTPS request to a URL you configure.

Where they fit better. If all you need is click, scroll and highlight on elements you tag, and the character does not need to hear back what happened, Runway's Page Actions are less code than writing tools. If a UI action legitimately takes longer than 2.5 seconds and you want its result spoken, Anam's configurable timeout or Tavus app messages fit better than Realtime Avatar's fixed deadline. And if you already run a LiveKit Agents, Pipecat or OpenAI Realtime voice agent, keep its tools there: Realtime Avatar does not offer a renderer-only mode that lip-syncs audio from your own agent.

### Seeing what happened

Register a transcript webhook when your server mints the call, and after it ends the platform POSTs the full two-sided transcript and the tool calls the model made to your HTTPS endpoint, signed with HMAC-SHA256 over the timestamp and body. Store the tool calls next to the transcript to see which dialogs opened, which variants went into carts and which tools failed; the entry fields are in the tool calling docs.

## What a guided demo costs

Prices from Realtime Avatar's billing catalog, as of November 2026. One credit is one second on air, so a five-minute guided product demo uses 300 credits whatever the tools do on screen.

- Sandbox: free, 480 credits once per account, no card: 8 realtime minutes, or your first avatar plus 2 minutes of calls. Enough to test the tools.
- Starter: $9 a month with 120 realtime minutes (7,200 credits), then $0.095 a minute. That is 24 five-minute demos included, then $0.475 for each additional one; 3 concurrent streams.
- Developer: $24 a month with 600 minutes (36,000 credits), then $0.085 a minute. That is 120 five-minute demos included, then $0.425 each; 10 concurrent streams.

The figures cover call time only. Each avatar beyond the plan's included count (5 on Starter, 25 on Developer) costs $3.

## FAQ

### How do I let an AI avatar open a modal or scroll the page with client-side tool calls?

Declare show_modal and scroll_to_section as client tools whose execute calls dialog.showModal() or element.scrollIntoView(), with the valid ids in an enum. Grant clientTools: true on the server, register after the room connects, and return a sentence the character speaks from.

### Can the avatar in my Lovable app open the pricing modal when the user asks about price?

Yes. The Lovable guide sets up a server route that starts the call; have that route's session policy return clientTools: true, register show_modal in the page after the call connects, and say in both the tool description and the instructions that price questions open the pricing dialog.

### Can a shopping avatar add an item to the cart when the customer says "I'll take the blue one"?

Yes, with a tool like add_to_cart built from the product on screen: an enum of its variant ids, a description that maps each id to its label, an instruction to ask when the choice is ambiguous, and a set-quantity write that is safe to repeat. Keep checkout behind the customer's own click.

### How do I make a language tutor avatar show vocabulary cards while it talks?

Register show_vocab_card with your UI's setter and have it return immediately: the card renders from your React state while the sentence continues. The AI tutor use case covers answer checks, hints and scores.

### Can a talking avatar highlight or point at things on my page while it explains them?

It can ask your page to: highlight_element scrolls a tagged element into view and outlines it. The outline is the pointer.

### How do I let an AI NPC give the player an item or open a door during a live conversation?

Expose give_item and open_door with enums of real item and door ids, and route each call into your game's own rules, returning the refusal reason when the rules say no. The game NPC use case covers quest state and concurrency.

### How do I handle function calls from a realtime voice NPC in the browser over WebRTC?

The call runs over LiveKit and the tool manifest is registered over RPC in that room, so a handler is ordinary browser code: dispatch into your game loop and return within 2.5 seconds; anything slower finishes in the game after an immediate acknowledgement.

### Has anyone actually run a real-time AI avatar for product demos?

This post does not cite a customer deployment. The pieces a guided demo needs are documented and testable on the free Sandbox: scroll_to_section to move through the page, highlight_element for the detail being discussed and show_modal for pricing, with the demo script in your server's instructions.

- [Avatar API tool calling compared: client tools, deadlines, limits](https://realtimeavatar.ai/blog/avatar-api-tool-calling-compared)

- [Tool calling docs: client tools, the 2.5-second deadline, transcript entries](https://realtimeavatar.ai/docs/tool-calling)
- [Add a live avatar to a Lovable app](https://realtimeavatar.ai/docs/lovable)
- [AI tutor use case: exercises driven by tools](https://realtimeavatar.ai/use-cases/ai-tutor)
- [Game NPC use case: quest state and game actions](https://realtimeavatar.ai/use-cases/game-npc)
- [Build a shopping avatar that compares products before checkout](https://realtimeavatar.ai/blog/ai-shopping-avatar-product-comparison)
- [Plans and per-minute prices](https://realtimeavatar.ai/pricing)

- [MDN: the dialog element and showModal() (read 16 November 2026)](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/dialog)
- [MDN: Element.scrollIntoView() (read 16 November 2026)](https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView)
- [Runway Characters client tools and Page Actions (read 16 November 2026)](https://docs.dev.runwayml.com/characters/tools/client-tools/)
- [Anam client tools and events (read 16 November 2026)](https://anam.ai/docs/personas/tools/client-tools)
- [Tavus tool delivery: app messages and API calls (read 16 November 2026)](https://docs.tavus.io/sections/conversational-video-interface/pal/llm-tool-delivery)
- [OpenAI function calling guide: the five-step tool calling flow (read 16 November 2026)](https://developers.openai.com/api/docs/guides/function-calling)
