Client tools

Empower your assistant to trigger client-side operations.

Client tools enable your assistant to execute client-side functions. Unlike server-side tools, client tools allow the assistant to perform actions such as triggering browser events, running client-side functions, or sending notifications to a UI.

Overview

Applications may require assistants to interact directly with the user’s environment. Client-side tools give your assistant the ability to perform client-side operations.

Here are a few examples where client tools can be useful:

  • Triggering UI events: Allow an assistant to trigger browser events, such as alerts, modals or notifications.
  • Interacting with the DOM: Enable an assistant to manipulate the Document Object Model (DOM) for dynamic content updates or to guide users through complex interfaces.
To perform operations server-side, use tools instead.

Guide

Prerequisites

1

Create a new client-side tool

Navigate to your agent dashboard. In the Tools section, click Add Tool. Ensure the Tool Type is set to Client. Then configure the following:

SettingParameter
NamelogMessage
DescriptionUse this client-side tool to log a message to the user’s client.

Then create a new parameter message with the following configuration:

SettingParameter
Data TypeString
Identifiermessage
Requiredtrue
DescriptionThe message to log in the console. Ensure the message is informative and relevant.

logMessage client-tool setup

2

Register the client tool in your code

Unlike server-side tools, client tools need to be registered in your code.

Use the following code to register the client tool:

1from elevenlabs import ElevenLabs
2from elevenlabs.conversational_ai.conversation import Conversation, ClientTools
3
4def log_message(parameters):
5 message = parameters.get("message")
6 print(message)
7
8client_tools = ClientTools()
9client_tools.register("logMessage", log_message)
10
11conversation = Conversation(
12 client=ElevenLabs(api_key="your-api-key"),
13 agent_id="your-agent-id",
14 client_tools=client_tools,
15 # ...
16)
17
18conversation.start_session()

The tool and parameter names in the agent configuration are case-sensitive and must match those registered in your code.

3

Testing

Initiate a conversation with your agent and say something like:

Log a message to the console that says Hello World

You should see a Hello World log appear in your console.

4

Next steps

Now that you’ve set up a basic client-side event, you can:

  • Explore more complex client tools like opening modals, navigating to pages, or interacting with the DOM.
  • Combine client tools with server-side webhooks for full-stack interactions.
  • Use client tools to enhance user engagement and provide real-time feedback during conversations.

Troubleshooting

  • Ensure the tool and parameter names in the agent configuration match those registered in your code.
  • View the conversation transcript in the agent dashboard to verify the tool is being executed.
  • Open the browser console to check for any errors.
  • Ensure that your code has necessary error handling for undefined or unexpected parameters.

Best practices

Name tools intuitively, with detailed descriptions

If you find the assistant does not make calls to the correct tools, you may need to update your tool names and descriptions so the assistant more clearly understands when it should select each tool. Avoid using abbreviations or acronyms to shorten tool and argument names.

You can also include detailed descriptions for when a tool should be called. For complex tools, you should include descriptions for each of the arguments to help the assistant know what it needs to ask the user to collect that argument.

Name tool parameters intuitively, with detailed descriptions

Use clear and descriptive names for tool parameters. If applicable, specify the expected format for a parameter in the description (e.g., YYYY-mm-dd or dd/mm/yy for a date).

Consider providing additional information about how and when to call tools in your assistant’s system prompt

Providing clear instructions in your system prompt can significantly improve the assistant’s tool calling accuracy. For example, guide the assistant with instructions like the following:

Use `check_order_status` when the user inquires about the status of their order, such as 'Where is my order?' or 'Has my order shipped yet?'.

Provide context for complex scenarios. For example:

Before scheduling a meeting with `schedule_meeting`, check the user's calendar for availability using check_availability to avoid conflicts.

LLM selection

When using tools, we recommend avoiding the default LLM (Gemini 1.5 Flash), and instead pick another LLM like GPT-4o mini or Claude 3.5 Sonnet.

It’s important to note that the choice of LLM matters to the success of function calls. Some LLMs can struggle with extracting the relevant parameters from the conversation.

Built with