ElevenLabs provides a VoxEngine client for connecting a call or media unit to the ElevenLabs Agents WebSocket API.
Use ElevenLabs.createAgentsClient(...) to create an AgentsClient for the current scenario.
Add the module before using the namespace:
Create the client, bridge media, and listen for ElevenLabs Agents events.
Creates a new ElevenLabs.AgentsClient instance.
Parameters
Returns
Creates a new ElevenLabs.RealtimeTTSPlayer instance with the specified text (TTS is used to play the text). You can attach media streams later via the ElevenLabs.RealtimeTTSPlayer.sendMediaTo or VoxEngine.sendMediaBetween methods.
NOTE: this method uses 11labs initializeConnection(https://elevenlabs.io/docs/api-reference/text-to-speech/v-1-text-to-speech-voice-id-stream-input#send.initializeConnection) method internally.
Parameters
Returns
Adds a handler for the specified ElevenLabs.AgentsEvents or ElevenLabs.Events event. Use only functions as handlers; anything except a function leads to the error and scenario termination when a handler is called.
Parameters
Returns
Clears the ElevenLabs WebSocket media buffer.
Parameters
Returns
Result of the client tool call. https://elevenlabs.io/docs/agents-platform/api-reference/agents-platform/websocket#send.Client-Tool-Result
Parameters
Returns
Closes the ElevenLabs connection (over WebSocket) or connection attempt.
Parameters
This method does not accept parameters.
Returns
Allows to send non-interrupting background information to the conversation. https://elevenlabs.io/docs/agents-platform/api-reference/agents-platform/websocket#send.Contextual-Update
Parameters
Returns
Defines what can be customized when starting a conversation. https://elevenlabs.io/docs/agents-platform/api-reference/agents-platform/websocket#send.Conversation-Initiation-Client-Data
Parameters
Returns
Returns the AgentsClient id.
Parameters
This method does not accept parameters.
Returns
Removes a handler for the specified ElevenLabs.AgentsEvents or ElevenLabs.Events event.
Parameters
Returns
Starts sending media from the ElevenLabs (via WebSocket) to the media unit. ElevenLabs works in real time.
Parameters
Returns
Stops sending media from the ElevenLabs (via WebSocket) to the media unit.
Parameters
Returns
Allows to send user text messages to the conversation. https://elevenlabs.io/docs/agents-platform/customization/events/client-to-server-events#user-messages
Parameters
Returns
Returns the ElevenLabs WebSocket id.
Parameters
This method does not accept parameters.
Returns
These events describe audio received through the ElevenLabs WebSocket media bridge.
Triggered when the audio stream sent by a third party through an ElevenLabs WebSocket is started playing.
Event constant: Events.WebSocketMediaStarted
Payload
Triggers after the end of the audio stream sent by a third party through an ElevenLabs WebSocket (1 second of silence).
Event constant: Events.WebSocketMediaEnded
Payload
These events mirror server messages from the ElevenLabs Agents WebSocket API. The data field contains the provider event payload.
The unknown event.
Event constant: AgentsEvents.Unknown
Payload
The HTTP response event.
Event constant: AgentsEvents.HTTPResponse
Payload
Automatically sent when starting a conversation. Initializes conversation settings and parameters. https://elevenlabs.io/docs/agents-platform/customization/events/client-events#conversation_initiation_metadata
Event constant: AgentsEvents.ConversationInitiationMetadata
Payload
Example data:
Health check event requiring immediate response. Used to maintain WebSocket connection. https://elevenlabs.io/docs/agents-platform/customization/events/client-events#ping
Event constant: AgentsEvents.Ping
Payload
Example data:
Contains finalized speech-to-text results. Represents complete user utterances. Used for conversation history. https://elevenlabs.io/docs/agents-platform/customization/events/client-events#user_transcript
Event constant: AgentsEvents.UserTranscript
Payload
Example data:
Contains complete agent message. Sent with first audio chunk. Used for display and history. https://elevenlabs.io/docs/agents-platform/customization/events/client-events#agent_response
Event constant: AgentsEvents.AgentResponse
Payload
Example data:
Contains truncated response after interruption. Updates displayed message. Maintains conversation accuracy. https://elevenlabs.io/docs/agents-platform/customization/events/client-events#agent_response_correction
Event constant: AgentsEvents.AgentResponseCorrection
Payload
Example data:
Contains event id of interrupted event. https://elevenlabs.io/docs/agents-platform/api-reference/agents-platform/websocket#receive.Interruption
Event constant: AgentsEvents.Interruption
Payload
Example data:
Contains contextual information to be added to the conversation state. https://elevenlabs.io/docs/agents-platform/api-reference/agents-platform/websocket#receive.Contextual-Update
Event constant: AgentsEvents.ContextualUpdate
Payload
Represents a function call the agent wants the client to execute. Contains tool name, tool call ID, and parameters. Requires client-side execution of the function and sending the result back to the server. https://elevenlabs.io/docs/agents-platform/customization/events/client-events#client_tool_call
Event constant: AgentsEvents.ClientToolCall
Payload
Example data:
Voice Activity Detection score event. Indicates the probability that the user is speaking. Values range from 0 to 1, where higher values indicate higher confidence of speech. https://elevenlabs.io/docs/agents-platform/customization/events/client-events#vad_score
Event constant: AgentsEvents.VadScore
Payload
Contains preliminary text from the agent. https://elevenlabs.io/docs/agents-platform/api-reference/agents-platform/websocket#receive.Internal-Tentative-Agent-Response
Event constant: AgentsEvents.InternalTentativeAgentResponse
Payload
Example data:
The WebSocket error response event.
Event constant: AgentsEvents.WebSocketError
Payload
Contains information about connector.
Event constant: AgentsEvents.ConnectorInformation
Payload
Indicates when the agent has executed a tool function. Contains tool metadata and execution status. Provides visibility into agent tool usage during conversations. https://elevenlabs.io/docs/agents-platform/customization/events/client-events#agent_tool_response
Event constant: AgentsEvents.AgentToolResponse
Payload
Example data: