broad-painter-9222
12/15/2025, 2:42 PMtall-airline-16756
12/15/2025, 2:42 PMtall-airline-16756
12/15/2025, 2:42 PMon_enter().
• Detect end of user speech with on_user_turn_completed().
• In that hook, check elapsed time and trigger the agent reply (once or per your rules) with session.generate_reply() or session.say().
Example (Python — minimal):
from livekit.agents import Agent
from livekit.agents.voice import AgentSession
import asyncio
from datetime import datetime
class TimedPostUserAgent(Agent):
def __init__(self):
super().__init__(instructions="You are a helpful assistant.")
self.session_start = None
self.triggered = False # ensure one-time behavior
async def on_enter(self):
self.session_start = datetime.utcnow()
async def on_user_turn_completed(self, turn_ctx, new_message):
if self.triggered:
return
delay_seconds = 10 # time since session start required
elapsed = (datetime.utcnow() - self.session_start).total_seconds()
if elapsed >= delay_seconds:
self.triggered = True
await asyncio.sleep(0.5) # optional slight pause
await self.session.generate_reply(instructions="Say a brief greeting and ask how to help.")
If you want variations I can help with:
• Triggering repeatedly (every N minutes) instead of once
• Cancelling the behavior if user is active
• Using session.say() directly for fixed TTS text
Which variation do you want to implement?
Sources: Pipeline nodes and hooks | LiveKit docs | Agent speech and audio | LiveKit docs