early-window-29567
11/13/2025, 10:41 PMawait send_loading_progress(50, "Initializing AI agent...")
agent = Agent(
instructions=system_prompt,
tools=[get_unit_info, generate_template, change_unit],
)
# Create session state with participant data
await send_loading_progress(60, "Preparing session...")
session_id = str(uuid.uuid4())
state = SessionState(
session_id=session_id,
room_name=ctx.room.name,
current_lesson=0,
user_name=participant_data.user_name,
user_email=participant_data.user_email,
avatar_id=participant_data.avatar_id,
voice_id=participant_data.voice_id,
language=participant_data.language or 'en',
video_url=participant_data.video_url,
video_data=participant_data.video_data,
question_answers=participant_data.question_answers,
)
# Use voice_id from participant data if available
voice_id = participant_data.voice_id
if not voice_id:
logger.warning("[SimplifiedAgent] No voice_id provided, using default ElevenLabs voice")
# Create session with error handling
await send_loading_progress(70, "Configuring voice and AI...")
try:
session = AgentSession[SessionState](
userdata=state,
vad=silero.VAD.load(),
stt=stt.FallbackAdapter([
deepgram.STT(model="nova-3"),
]),
llm=openai.LLM(model="gpt-4o-mini"),
# Use OpenAI TTS directly (ElevenLabs quota/API issues)
tts=openai.TTS(voice="alloy"),
)
logger.info("[SimplifiedAgent] ✅ Session created successfully")
except Exception as e:
logger.error(f"[SimplifiedAgent] Error creating AgentSession: {e}")
logger.error("This might be related to SSL certificate issues.")
raise
# Initialize Beyond Presence avatar if avatar_id is provided
if participant_data.avatar_id:
await send_loading_progress(85, "Initializing avatar...")
logger.info(f"[SimplifiedAgent] Initializing avatar: {participant_data.avatar_id}")
avatar = await initialize_avatar(ctx, session, participant_data.avatar_id)
if avatar:
logger.info("[SimplifiedAgent] ✅ Avatar initialized successfully")
else:
logger.info("[SimplifiedAgent] Continuing without avatar (voice-only mode)")
else:
logger.info("[SimplifiedAgent] No avatar selected - faceless mode")
# Complete loading
await send_loading_progress(100, "Ready!")
await send_loading_progress(80, "Starting voice session...")
# Start session with transcription enabled (like old agent)
await session.start(
agent=agent,
room=ctx.room,
room_input_options=RoomInputOptions(
noise_cancellation=noise_cancellation.BVC(),
),
room_output_options=RoomOutputOptions(
sync_transcription=True, # Enable transcription sync
),
)
logger.info("[SimplifiedAgent] ✅ Session started with transcription enabled")
# Setup on_enter callback to generate greeting after session starts
# This is called automatically after the entrypoint returns
async def on_session_ready():
logger.info("[SimplifiedAgent] Session ready, generating greeting...")
user_name = participant_data.user_name
greeting_input = f"Hello{', ' + user_name if user_name else ''}! I'd like to start learning."
await session.generate_reply(user_input=greeting_input)
logger.info("[SimplifiedAgent] ✅ Greeting complete, agent listening")
# Schedule the greeting to run after this function returns
asyncio.create_task(on_session_ready())
except Exception as e:
logger.error(f"[SimplifiedAgent] Error in entrypoint: {e}")
logger.error("If this is an SSL error, try running with: PYTHONHTTPSVERIFY=0 python simple_agent.py")
raise
if __name__ == "__main__":
cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))tall-airline-16756
11/13/2025, 10:41 PMtall-airline-16756
11/13/2025, 10:41 PMlk.transcription topic. Make sure your frontend is set up to listen to these streams so you can receive the transcription data smoothly. If you’d like a handy example, the Next.js Transcription Frontend is a great reference for how to get this going.
About pausing speech, LiveKit Agents have built-in ways to pause and resume transcription and speech output, mainly to keep everything in sync and handle interruptions. However, there isn’t a public API to manually control this from the frontend just yet. Interruptions happen automatically when the user speaks, which might pause the agent’s output if certain conditions are met.
If you’re looking for more manual control, one option is to send custom data messages from your frontend and manage them inside your agent through a dedicated signaling channel. I’m here to help if you want some guidance on how to set this up—just let me know!
Sources: Text and transcriptions | LiveKit docs | LICENSE | README.md | Live Conversations with AI using ChatGPT and WebRTC | Live Conversations with AI using ChatGPT and WebRTC