1313import logging
1414import uuid
1515
16- from vision_agents .core .events import PluginClosedEvent
1716
1817from . import events , LLM
1918
@@ -38,32 +37,26 @@ class Realtime(LLM, abc.ABC):
3837 - Transcript outgoing audio
3938
4039 """
41-
42- fps : int = 1
40+ fps : int = 1
41+ session_id : str # UUID to identify this session
4342
4443 def __init__ (
4544 self ,
4645 fps : int = 1 , # the number of video frames per second to send (for implementations that support setting fps)
4746 ):
4847 super ().__init__ ()
49- self ._is_connected = False
48+ self .connected = False
5049
5150 self .provider_name = "realtime_base"
5251 self .session_id = str (uuid .uuid4 ())
5352 self .fps = fps
5453 # The most common style output track (webrtc)
55- # TODO: do we like the output track here, or do we want to do an event, and have the agent manage the output track
5654 self .output_track : AudioStreamTrack = AudioStreamTrack (
5755 framerate = 48000 , stereo = True , format = "s16"
5856 )
5957 # Store current participant for user speech transcription events
6058 self ._current_participant : Optional [Participant ] = None
6159
62- @property
63- def is_connected (self ) -> bool :
64- """Return True if the realtime session is currently active."""
65- return self ._is_connected
66-
6760 @abc .abstractmethod
6861 async def connect (self ): ...
6962
@@ -82,7 +75,7 @@ async def _stop_watching_video_track(self) -> None:
8275
8376 def _emit_connected_event (self , session_config = None , capabilities = None ):
8477 """Emit a structured connected event."""
85- self ._is_connected = True
78+ self .connected = True
8679 # Mark ready when connected if provider uses base emitter
8780 try :
8881 self ._ready_event .set () # type: ignore[attr-defined]
@@ -98,7 +91,7 @@ def _emit_connected_event(self, session_config=None, capabilities=None):
9891
9992 def _emit_disconnected_event (self , reason = None , was_clean = True ):
10093 """Emit a structured disconnected event."""
101- self ._is_connected = False
94+ self .connected = False
10295 event = events .RealtimeDisconnectedEvent (
10396 session_id = self .session_id ,
10497 plugin_name = self .provider_name ,
@@ -182,6 +175,10 @@ def _emit_error_event(self, error, context="", user_metadata=None):
182175 )
183176 self .events .send (event )
184177
178+ @abc .abstractmethod
179+ async def close (self ):
180+ raise NotImplementedError ("llm.close isn't implemented" )
181+
185182 def _emit_user_speech_transcription (self , text : str , original = None ):
186183 """Emit a user speech transcription event with participant info."""
187184 event = events .RealtimeUserSpeechTranscriptionEvent (
@@ -202,19 +199,3 @@ def _emit_agent_speech_transcription(self, text: str, original=None):
202199 original = original ,
203200 )
204201 self .events .send (event )
205-
206- async def close (self ):
207- """Close the Realtime service and release any resources."""
208- if self ._is_connected :
209- await self ._close_impl ()
210- self ._emit_disconnected_event ("service_closed" , True )
211-
212- close_event = PluginClosedEvent (
213- session_id = self .session_id ,
214- plugin_name = self .provider_name ,
215- cleanup_successful = True ,
216- )
217- self .events .send (close_event )
218-
219- @abc .abstractmethod
220- async def _close_impl (self ): ...
0 commit comments