what is agent activity in livekit
# ask-ai
g
what is agent activity in livekit
t
Thanks for reaching out, Dhruv. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Agent activity in LiveKit is all about how the
AgentActivity
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 | DeepWiki
g
why is the stt node called only once
t
Hey there! Just wanted to share a bit about how the STT node in LiveKit works—it’s built to handle a continuous stream of audio frames during a single user turn or utterance. That’s why it might seem like it’s "called only once" per interaction. Here’s the scoop: • Single Invocation Per Turn: The STT node kicks in once for each user turn or audio stream and keeps processing the audio throughout that turn, giving you both interim and final transcriptions. • Turn-Based Design: When you stop speaking, the system picks up on that, wraps up the transcription, and gets ready for the next turn. If you start talking again, the STT node jumps back in for the new turn. • Stream Management: Each session handles multiple audio streams, creating a fresh STT stream for every turn it detects. Voice Activity Detection (VAD) or server-side turn detection helps break continuous audio into neat, separate turns. This setup helps make sure your transcriptions are spot-on and work smoothly with other parts like LLM and TTS. If you want to dive deeper or explore customization options, just give me a shout—I’m here to help! Sources: Pipeline nodes and hooks | LiveKit Docs | livekit-plugins/livekit-plugins-baseten/livekit/plugins/baseten/stt.py | Speech-to-text (STT) integrations | LiveKit Docs
g
the following is the stt_node, however the stt in activity is printed only once when the agent is initialized and not eveyr turn,
Copy code
async 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)
t
Hey there! It looks like the STT in the activity should be processed on every user turn, but right now it’s only showing up once during initialization. Could you tell me a bit more about your setup? Specifically: • How are you setting up the STT, VAD, and turn detection components in your agent? • Which STT provider are you using, and does it support streaming transcription? • Have you checked the turn detection mode and how events are handled in your implementation? Getting these details will really help us figure out what’s going on. Thanks! Sources: livekit-agents/livekit/agents/voice/agent.py
g
audio is processed on every turn, but that line printed only once
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!