diff --git a/realtime_agent/agent.py b/realtime_agent/agent.py index 88eb895..c334302 100644 --- a/realtime_agent/agent.py +++ b/realtime_agent/agent.py @@ -11,7 +11,7 @@ from agora_realtime_ai_api.rtc import Channel, ChatMessage, RtcEngine, RtcOptions from .logger import setup_logger -from .realtime.struct import FunctionCallOutputItemParam, InputAudioBufferCommitted, InputAudioBufferSpeechStarted, InputAudioBufferSpeechStopped, InputAudioTranscription, ItemCreate, ItemCreated, ItemInputAudioTranscriptionCompleted, RateLimitsUpdated, ResponseAudioDelta, ResponseAudioDone, ResponseAudioTranscriptDelta, ResponseAudioTranscriptDone, ResponseContentPartAdded, ResponseContentPartDone, ResponseCreate, ResponseCreated, ResponseDone, ResponseFunctionCallArgumentsDelta, ResponseFunctionCallArgumentsDone, ResponseOutputItemAdded, ResponseOutputItemDone, ServerVADUpdateParams, SessionUpdate, SessionUpdateParams, SessionUpdated, Voices, to_json +from .realtime.struct import ErrorMessage, FunctionCallOutputItemParam, InputAudioBufferCommitted, InputAudioBufferSpeechStarted, InputAudioBufferSpeechStopped, InputAudioTranscription, ItemCreate, ItemCreated, ItemInputAudioTranscriptionCompleted, RateLimitsUpdated, ResponseAudioDelta, ResponseAudioDone, ResponseAudioTranscriptDelta, ResponseAudioTranscriptDone, ResponseContentPartAdded, ResponseContentPartDone, ResponseCreate, ResponseCreated, ResponseDone, ResponseFunctionCallArgumentsDelta, ResponseFunctionCallArgumentsDone, ResponseOutputItemAdded, ResponseOutputItemDone, ServerVADUpdateParams, SessionUpdate, SessionUpdateParams, SessionUpdated, Voices, to_json from .realtime.connection import RealtimeApiConnection from .tools import ClientToolCallResponse, ToolContext from .utils import PCMWriter @@ -109,9 +109,14 @@ async def setup_and_run_agent( start_session_message = await anext(connection.listen()) # assert isinstance(start_session_message, messages.StartSession) - logger.info( - f"Session started: {start_session_message.session.id} model: {start_session_message.session.model}" - ) + if isinstance(start_session_message, SessionUpdated): + logger.info( + f"Session started: {start_session_message.session.id} model: {start_session_message.session.model}" + ) + elif isinstance(start_session_message, ErrorMessage): + logger.info( + f"Error: {start_session_message.error}" + ) agent = cls( connection=connection,