Skip to content

Commit a355dce

Browse files
feat: deal with error message for connection failures
1 parent 97b3e56 commit a355dce

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

realtime_agent/agent.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from agora_realtime_ai_api.rtc import Channel, ChatMessage, RtcEngine, RtcOptions
1212

1313
from .logger import setup_logger
14-
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
14+
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
1515
from .realtime.connection import RealtimeApiConnection
1616
from .tools import ClientToolCallResponse, ToolContext
1717
from .utils import PCMWriter
@@ -109,9 +109,14 @@ async def setup_and_run_agent(
109109

110110
start_session_message = await anext(connection.listen())
111111
# assert isinstance(start_session_message, messages.StartSession)
112-
logger.info(
113-
f"Session started: {start_session_message.session.id} model: {start_session_message.session.model}"
114-
)
112+
if isinstance(start_session_message, SessionUpdated):
113+
logger.info(
114+
f"Session started: {start_session_message.session.id} model: {start_session_message.session.model}"
115+
)
116+
elif isinstance(start_session_message, ErrorMessage):
117+
logger.info(
118+
f"Error: {start_session_message.error}"
119+
)
115120

116121
agent = cls(
117122
connection=connection,

0 commit comments

Comments
 (0)