Conversation
Synchronous conversational AI session for real-time voice conversations with an agent.Constructor
BaseElevenLabs
required
The ElevenLabs client to use for the conversation.
str
required
The ID of the agent to converse with.
str
The ID of the user conversing with the agent.
bool
required
Whether the agent requires authentication.
AudioInterface
required
The audio interface to use for input and output.
ConversationInitiationData
Configuration options for the conversation including extra_body, conversation_config_override, dynamic_variables, and user_id.
ClientTools
Client-side tools that can be called by the agent during the conversation.
Callable[[str], None]
Callback function invoked when the agent provides a response.
Callable[[str, str], None]
Callback for agent response corrections. First argument is the original response (previously given to callback_agent_response), second argument is the corrected response.
Callable[[str, AgentChatResponsePartType], None]
Callback for streaming text response chunks. First argument is the text chunk, second argument is the type (START, DELTA, or STOP).
Callable[[str], None]
Callback function invoked when user speech is transcribed.
Callable[[int], None]
Callback for latency measurements in milliseconds.
Callable[[AudioEventAlignment], None]
Callback for audio alignment data with character-level timing information.
Callable
Callback function invoked when the session ends.
OnPremInitiationData
Configuration options for on-premises deployment.
Methods
start_session
end_session is called.
end_session
wait_for_session_end
end_session before calling this method, otherwise it will block.
Returns: The conversation ID, if available.
send_user_message
str
required
The text message to send to the agent.
RuntimeError if the session is not active or websocket is not connected.
register_user_activity
RuntimeError if the session is not active or websocket is not connected.
send_contextual_update
str
required
The contextual information to send to the conversation.
RuntimeError if the session is not active or websocket is not connected.
Example
AsyncConversation
Asynchronous conversational AI session for real-time voice conversations with an agent.Constructor
BaseElevenLabs
required
The ElevenLabs client to use for the conversation.
str
required
The ID of the agent to converse with.
str
The ID of the user conversing with the agent.
bool
required
Whether the agent requires authentication.
AsyncAudioInterface
required
The async audio interface to use for input and output.
ConversationInitiationData
Configuration options for the conversation.
ClientTools
Client-side tools that can be called by the agent during the conversation.
Callable[[str], Awaitable[None]]
Async callback function invoked when the agent provides a response.
Callable[[str, str], Awaitable[None]]
Async callback for agent response corrections.
Callable[[str, AgentChatResponsePartType], Awaitable[None]]
Async callback for streaming text response chunks.
Callable[[str], Awaitable[None]]
Async callback function invoked when user speech is transcribed.
Callable[[int], Awaitable[None]]
Async callback for latency measurements in milliseconds.
Callable[[AudioEventAlignment], Awaitable[None]]
Async callback for audio alignment data with character-level timing.
Callable[[], Awaitable[None]]
Async callback function invoked when the session ends.
OnPremInitiationData
Configuration options for on-premises deployment.
Methods
All methods are async and should be awaited.start_session
end_session is called.
end_session
wait_for_session_end
end_session before calling this method, otherwise it will block.
Returns: The conversation ID, if available.
send_user_message
str
required
The text message to send to the agent.
RuntimeError if the session is not active or websocket is not connected.
register_user_activity
RuntimeError if the session is not active or websocket is not connected.
send_contextual_update
str
required
The contextual information to send to the conversation.
RuntimeError if the session is not active or websocket is not connected.
Example
Supporting Classes
ConversationInitiationData
Configuration options for the Conversation.dict
Additional custom data to include in the conversation initiation.
dict
Configuration overrides for the conversation.
dict
Dynamic variables to use during the conversation.
str
The ID of the user conversing with the agent.
AudioEventAlignment
Audio alignment data containing character-level timing information.List[str]
List of characters in the audio.
List[int]
Start times for each character in milliseconds.
List[int]
Duration of each character in milliseconds.