Language detection

Let your agent automatically switch to the language

Overview

The language detection system tool allows your Conversational AI agent to switch its output language to any the agent supports. This system tool is not enabled automatically. Its description can be customized to accommodate your specific use case.

Where possible, we recommend enabling all languages for an agent and enabling the language detection system tool.

Our language detection tool triggers language switching in two cases, both based on the received audio’s detected language and content:

  • detection if a user speaks a different language than the current output language, a switch will be triggered
  • content if the user asks in the current language to change to a new language, a switch will be triggered

Enabling language detection

1

Configure supported languages

The languages that the agent can switch to must be defined in the Agent settings tab.

Agent languages

2

Add the language detection tool

Enable language detection by selecting the pre-configured system tool to your agent’s tools in the Agent tab. This is automatically available as an option when selecting add tool.

System tool

3

Configure tool description

Add a description that specifies when to call the tool

Description

API Implementation

When creating an agent via API, you can add the language detection tool to your agent configuration. It should be defined as a system tool:

1from elevenlabs import (
2 ConversationalConfig,
3 ElevenLabs,
4 AgentConfig,
5 PromptAgent,
6 PromptAgentToolsItem_System,
7 LanguagePreset,
8 ConversationConfigClientOverride,
9 AgentConfigOverride,
10 LanguagePresetTranslation,
11 PromptAgentOverride
12)
13
14# Initialize the client
15client = ElevenLabs(api_key="YOUR_API_KEY")
16
17# Create the language detection tool
18language_detection_tool = PromptAgentToolsItem_System(
19 name="language_detection",
20 description="" # Optional: Customize when the tool should be triggered
21)
22
23# Create language presets
24language_presets = {
25 "nl": LanguagePreset(
26 overrides=ConversationConfigClientOverride(
27 agent=AgentConfigOverride(
28 prompt=None,
29 first_message="Hoi, hoe gaat het met je?",
30 language=None
31 ),
32 tts=None
33 ),
34 first_message_translation=None
35 ),
36 "fi": LanguagePreset(
37 overrides=ConversationConfigClientOverride(
38 agent=AgentConfigOverride(
39 first_message="Hei, kuinka voit?",
40 ),
41 tts=None
42 ),
43 ),
44 "tr": LanguagePreset(
45 overrides=ConversationConfigClientOverride(
46 agent=AgentConfigOverride(
47 prompt=None,
48 first_message="Merhaba, nasılsın?",
49 language=None
50 ),
51 tts=None
52 ),
53 ),
54 "ru": LanguagePreset(
55 overrides=ConversationConfigClientOverride(
56 agent=AgentConfigOverride(
57 prompt=None,
58 first_message="Привет, как ты?",
59 language=None
60 ),
61 tts=None
62 ),
63 ),
64 "pt": LanguagePreset(
65 overrides=ConversationConfigClientOverride(
66 agent=AgentConfigOverride(
67 prompt=None,
68 first_message="Oi, como você está?",
69 language=None
70 ),
71 tts=None
72 ),
73 )
74}
75
76# Create the agent configuration
77conversation_config = ConversationalConfig(
78 agent=AgentConfig(
79 prompt=PromptAgent(
80 tools=[language_detection_tool],
81 first_message="Hi how are you?"
82 )
83 ),
84 language_presets=language_presets
85)
86
87# Create the agent
88response = client.conversational_ai.create_agent(
89 conversation_config=conversation_config
90)
Leave the description blank to use the default language detection prompt.