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