gorgeous-soccer-57984
09/01/2025, 4:49 AMtall-airline-16756
09/01/2025, 4:49 AMtall-airline-16756
09/01/2025, 4:50 AMAgentActivity class manages the real-time voice agent during an AgentSession. Think of it as the behind-the-scenes helper that keeps everything running smoothly. Here’s what it takes care of:
• Speech Queue Management: It organizes speech tasks by priority, so it can handle interruptions and schedule things just right.
• Turn Detection: It supports different ways to know when it’s someone's turn to talk, like using VAD, STT, or even real-time LLM.
• Component Integration: It brings together cool tools like speech-to-text (STT), large language models (LLM), text-to-speech (TTS), and voice activity detection (VAD) to work seamlessly.
• Event Handling: It sends out events you can listen to, like speech_created and metrics_collected, so you’re always in the loop.
• Real-Time Stream Processing: It processes audio and video streams on the fly and uses smart techniques to keep things quick and smooth.
This activity is usually set up and managed by an AgentSession, which looks after the agent’s lifecycle and resources. While you won’t see it directly in the public API, it’s the engine behind handy features like say(), interrupt(), and generateReply().
Sources: Agents Core Architecture | livekit/livekit_composite | DeepWiki | livekit-agents/livekit/agents/voice/agent_session.py | agents/src/voice/agent_session.ts | LLM Integrations | livekit/livekit_composite | DeepWikigorgeous-soccer-57984
09/01/2025, 4:53 AMtall-airline-16756
09/01/2025, 4:54 AMgorgeous-soccer-57984
09/01/2025, 4:57 AMasync def stt_node(
self, audio: AsyncIterable[rtc.AudioFrame], model_settings: ModelSettings
) -> AsyncGenerator[stt.SpeechEvent, None]:
"""Default implementation for `Agent.stt_node`"""
activity = self._get_activity_or_raise()
assert activity.stt is not None, "stt_node called but no STT node is available"
wrapped_stt = activity.stt
print("Stt in activity: ", activity.stt)
if not activity.stt.capabilities.streaming:
if not activity.vad:
raise RuntimeError(
f"The STT ({activity.stt.label}) does not support streaming, add a VAD to the AgentTask/VoiceAgent to enable streaming" # noqa: E501
"Or manually wrap your STT in a stt.StreamAdapter"
)
wrapped_stt = stt.StreamAdapter(stt=wrapped_stt, vad=activity.vad)
conn_options = activity.session.conn_options.stt_conn_options
async with wrapped_stt.stream(conn_options=conn_options) as stream:
@utils.log_exceptions(logger=logger)
async def _forward_input() -> None:
async for frame in audio:
stream.push_frame(frame)
forward_task = asyncio.create_task(_forward_input())
try:
async for event in stream:
yield event
finally:
await utils.aio.cancel_and_wait(forward_task)tall-airline-16756
09/01/2025, 4:57 AMgorgeous-soccer-57984
09/01/2025, 4:58 AMtall-airline-16756
09/01/2025, 4:58 AM