Skip to content

Commit

Permalink
feat: deal with error message for connection failures
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasliu-agora committed Dec 4, 2024
1 parent 97b3e56 commit a355dce
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions realtime_agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit a355dce

Please sign in to comment.