How they work
- You define a tool in the Portal with a name, description, and JSON Schema for parameters — the same way you configure other tool types.
- The assistant decides when to call it based on the conversation context and the tool’s description.
- Your client-side handler runs in the browser, receiving the parsed arguments from the assistant.
- The return value is sent back to the assistant so it can continue the conversation naturally.
Client-side tools are available for WebRTC-based conversations (voice and chat) using the
@telnyx/ai-agent-lib JavaScript/React library. They are not available for SIP/phone-call-based conversations.When to use client-side tools
| Scenario | Client-side tool | Webhook tool |
|---|---|---|
| Read data the page already has (shopping cart, user session) | ✅ | |
| Trigger a UI action (open a modal, navigate, play media) | ✅ | |
| Call an API authenticated with the user’s browser session | ✅ | |
| Query a backend database or internal service | ✅ | |
| Send a notification to an external system | ✅ | |
| Needs to work for phone/SIP calls | ✅ |
Configure a client-side tool in the Portal
- Open AI Assistants in the Telnyx Portal.
- Select an assistant and scroll to the Tools section.
- Click Add Tool and select Client-Side Tool.
- Fill in the fields:
| Field | Description |
|---|---|
| Name | The tool name the assistant uses to call it. Must match the name you register in your client code. Only letters, numbers, underscores, and hyphens. |
| Description | Tell the assistant what the tool does and when to use it. The clearer the description, the better the assistant is at deciding when to invoke it. |
| Parameters | A JSON Schema object defining the tool’s input parameters. Use the visual editor for simple schemas (strings, numbers, booleans, enums, arrays) or switch to Advanced mode for complex schemas with nested objects or custom keywords. |
| Timeout (ms) | How long the client has to execute the tool before a timeout error is returned to the assistant. Default: 5000 ms. This per-tool value is sent to the client and applied automatically — you do not need to configure it in code. |
- Click Create & Add to Assistant.
The Parameters schema uses the same JSON Schema format as webhook tool body parameters. The visual editor supports
string, number, integer, boolean, enum, and array types. If your schema uses keywords the visual editor doesn’t support (like minimum, pattern, or default), it will be displayed in Advanced mode as raw JSON to preserve those keywords.Implement client-side tool handlers
Install the Telnyx AI Agent library:Client-side tools require
@telnyx/ai-agent-lib version 0.5.0 or later.Register tools at construction time
Register tools at runtime
Use with React
Handler contract
- The return value is serialized and sent back as the tool output. Strings are sent verbatim; anything else is JSON-stringified.
- Handlers may be async. Each runs with its tool’s Timeout configured in the Portal, falling back to
clientToolTimeoutMsfor tools that have none. If the handler exceeds it, a{ "error": "timeout" }output is returned to the assistant. - The library handles the
call_idround-trip — you don’t need to manage that yourself.
Error handling
The library always returns a result to the assistant so the conversation never hangs:| Scenario | What happens |
|---|---|
| Unknown tool name | Safe error output { "error": "unknown_tool" } |
| Invalid JSON arguments | Safe error output { "error": "invalid_arguments" } |
| Handler throws or rejects | Safe error output { "error": "handler_error" } |
| Handler exceeds timeout | Safe error output { "error": "timeout" } |
| Disconnected before output sent | Output dropped, error event emitted |
Duplicate call_id (re-delivery) | Ignored — tool is not executed twice |
Observe tool lifecycle events
Tool arguments and outputs are never logged — they may contain customer data. Only safe correlation fields (
callId, tool name) appear in debug logs.Client-side tools vs. webhook tools
| Feature | Client-side tools | Webhook tools |
|---|---|---|
| Execution location | Browser/client | Your backend server |
| Requires public endpoint | No | Yes |
| Works with phone/SIP calls | No | Yes |
| Works with WebRTC (voice/chat) | Yes | Yes |
| Can access browser state | Yes | No |
| Latency | Minimal (no HTTP round-trip) | Network-dependent |
| Can be tested in the Portal | No | Yes (test button) |
Use cases
- E-commerce: Look up cart contents, check order status from the browser session, apply a promo code
- Scheduling: Read the user’s calendar from the page, open a booking modal
- Customer support: Fetch user details from the client session, trigger a screen share
- IoT dashboards: Read device state from the dashboard, toggle a device on/off
Learn more
- Tools Library — Create shared tools and reuse them across assistants
- Async Tools & Deferred Context — Webhook tools that don’t block the conversation
- Voice Assistant Quickstart — Get started with AI assistants in the Portal
- @telnyx/ai-agent-lib on npm — Full API reference for the JavaScript/React library