def prewarm(proc: JobProcess):
proc.userdata["vad"] = silero.VAD.load()
async def entrypoint(ctx: JobContext):
ctx.log_context_fields = {
"room": ctx.room.name,
"user_id": "waec_student",
}
await ctx.connect()
logger.info("Connected to room")
participant = await ctx.wait_for_participant()
user_id = participant.identity
logger.info(f"Participant joined with identity: {user_id}")
# Load chat history FIRST, before creating the agent
temp_agent = WAECExamAgent(user_id=user_id)
chat_ctx = await temp_agent.load_chat_history()
# Create the actual agent with the loaded chat history
agent = WAECExamAgent(user_id=user_id, chat_ctx=chat_ctx)
logger.info(f"Created agent with loaded conversation context")
session = AgentSession(
vad=ctx.proc.userdata["vad"],
llm=openai.LLM(model="gpt-4.1-mini"),
stt= openai.STT(model="whisper-1"),
tts=openai.TTS(),
# stt=deepgram.STT(model="nova-2", language="en-US"),
# tts=deepgram.TTS(),
allow_interruptions=True
)
logger.info("Agent session components initialized")
# Set the session reference
agent.session = session
@session.on("metrics_collected")
def _on_metrics_collected(ev: MetricsCollectedEvent):
metrics.log_metrics(ev.metrics)
usage_collector.collect(ev.metrics)
usage_collector = metrics.UsageCollector()
async def log_usage():
summary = usage_collector.get_summary()
logger.info(f"Usage summary: {summary}")
async def save_conversation_on_shutdown():
try:
await agent.save_chat_history(session.history)
logger.info(f"Conversation summary saved successfully for user: {user_id}")
except Exception as e:
logger.error(f"Error saving conversation: {str(e)}")
async def delete_room():
async with api.LiveKitAPI(
os.getenv("LIVEKIT_URL"),
os.getenv("LIVEKIT_API_KEY"),
os.getenv("LIVEKIT_API_SECRET")
) as api_client:
await api_client.room.delete_room(api.DeleteRoomRequest(
room=ctx.room.name,
))
logger.info("Room deleted successfully")
ctx.add_shutdown_callback(save_conversation_on_shutdown)
ctx.add_shutdown_callback(log_usage)
ctx.add_shutdown_callback(delete_room)
i want to chang hti sto use eleven labs and alos tis vice id :
9Dbo4hEvXQ5l7MXGZFQA