@@ -313,6 +313,25 @@ def __init__(
313313 self .user_id = user_id
314314
315315
316+ class OnPremInitiationData :
317+ """Configuration options for the Conversation in on-prem mode."""
318+
319+ def __init__ (
320+ self ,
321+ on_prem_conversation_url : str ,
322+ post_call_transcription_webhook_url : Optional [str ] = None ,
323+ post_call_audio_webhook_url : Optional [str ] = None ,
324+ agent_config_dict : Optional [dict ] = None ,
325+ override_agent_config_list : Optional [dict ] = None ,
326+ tools_config_list : Optional [dict ] = None ,
327+ ):
328+ self .on_prem_conversation_url = on_prem_conversation_url
329+ self .post_call_transcription_webhook_url = post_call_transcription_webhook_url
330+ self .post_call_audio_webhook_url = post_call_audio_webhook_url
331+ self .agent_config_dict = agent_config_dict or {}
332+ self .override_agent_config_list = override_agent_config_list or {}
333+ self .tools_config_list = tools_config_list or {}
334+
316335class BaseConversation :
317336 """Base class for conversation implementations with shared parameters and logic."""
318337
@@ -325,20 +344,25 @@ def __init__(
325344 requires_auth : bool ,
326345 config : Optional [ConversationInitiationData ] = None ,
327346 client_tools : Optional [ClientTools ] = None ,
347+ on_prem_config : Optional [OnPremInitiationData ] = None ,
328348 ):
329349 self .client = client
330350 self .agent_id = agent_id
331351 self .user_id = user_id
332352 self .requires_auth = requires_auth
333353 self .config = config or ConversationInitiationData ()
334354 self .client_tools = client_tools or ClientTools ()
355+ self .on_prem_config = on_prem_config
335356
336357 self .client_tools .start ()
337358
338359 self ._conversation_id = None
339360 self ._last_interrupt_id = 0
340361
341362 def _get_wss_url (self ):
363+ if self .on_prem_config :
364+ return self .on_prem_config .on_prem_conversation_url
365+
342366 base_http_url = self .client ._client_wrapper .get_base_url ()
343367 base_ws_url = urllib .parse .urlparse (base_http_url )._replace (scheme = "wss" if base_http_url .startswith ("https" ) else "ws" ).geturl ()
344368 # Ensure base URL ends with '/' for proper joining
@@ -353,6 +377,18 @@ def _get_signed_url(self):
353377 separator = "&" if "?" in signed_url else "?"
354378 return f"{ signed_url } { separator } source=python_sdk&version={ __version__ } "
355379
380+ def _create_on_prem_initiation_message (self ):
381+ return json .dumps (
382+ {
383+ "type" : "enclave_setup_config" ,
384+ "agent_config_dict" : self .on_prem_config .agent_config_dict ,
385+ "override_agent_config_list" : self .on_prem_config .override_agent_config_list ,
386+ "tools_config_list" : self .on_prem_config .tools_config_list ,
387+ "post_call_transcription_webhook_url" : self .on_prem_config .post_call_transcription_webhook_url ,
388+ "post_call_audio_webhook_url" : self .on_prem_config .post_call_audio_webhook_url ,
389+ }
390+ )
391+
356392 def _create_initiation_message (self ):
357393 return json .dumps (
358394 {
@@ -527,6 +563,7 @@ def __init__(
527563 callback_user_transcript : Optional [Callable [[str ], None ]] = None ,
528564 callback_latency_measurement : Optional [Callable [[int ], None ]] = None ,
529565 callback_end_session : Optional [Callable ] = None ,
566+ on_prem_config : Optional [OnPremInitiationData ] = None ,
530567 ):
531568 """Conversational AI session.
532569
@@ -556,6 +593,7 @@ def __init__(
556593 requires_auth = requires_auth ,
557594 config = config ,
558595 client_tools = client_tools ,
596+ on_prem_config = on_prem_config ,
559597 )
560598
561599 self .audio_interface = audio_interface
@@ -663,6 +701,8 @@ def send_contextual_update(self, text: str):
663701 def _run (self , ws_url : str ):
664702 with connect (ws_url , max_size = 16 * 1024 * 1024 ) as ws :
665703 self ._ws = ws
704+ if self .on_prem_config :
705+ ws .send (self ._create_on_prem_initiation_message ())
666706 ws .send (self ._create_initiation_message ())
667707 self ._ws = ws
668708
@@ -780,6 +820,7 @@ def __init__(
780820 callback_user_transcript : Optional [Callable [[str ], Awaitable [None ]]] = None ,
781821 callback_latency_measurement : Optional [Callable [[int ], Awaitable [None ]]] = None ,
782822 callback_end_session : Optional [Callable [[], Awaitable [None ]]] = None ,
823+ on_prem_config : Optional [OnPremInitiationData ] = None ,
783824 ):
784825 """Async Conversational AI session.
785826
@@ -810,6 +851,7 @@ def __init__(
810851 requires_auth = requires_auth ,
811852 config = config ,
812853 client_tools = client_tools ,
854+ on_prem_config = on_prem_config ,
813855 )
814856
815857 self .audio_interface = audio_interface
@@ -916,6 +958,8 @@ async def send_contextual_update(self, text: str):
916958 async def _run (self , ws_url : str ):
917959 async with websockets .connect (ws_url , max_size = 16 * 1024 * 1024 ) as ws :
918960 self ._ws = ws
961+ if self .on_prem_config :
962+ await ws .send (self ._create_on_prem_initiation_message ())
919963 await ws .send (self ._create_initiation_message ())
920964
921965 async def input_callback (audio ):
0 commit comments