when the agent goes into session what parameters w...
# ask-ai
r
when the agent goes into session what parameters we can update?
t
Thanks for reaching out, Rahul. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking which agent/session parameters can be updated when an agent enters a session — here are the options you can set or change at entry or at runtime. • AI models ◦
llm
,
stt
,
tts
,
vad
— can be specified per session/agent and overridden at runtime. • Turn-detection & interruption ◦
turn_detection
method,
allow_interruptions
,
min_endpointing_delay
,
max_endpointing_delay
— adjustable at runtime via
activity.update_options(...)
. • Agent behavior & tools ◦
instructions
(system prompt) — updateable via
update_instructions
. ◦
tools
— replaceable via
update_tools
. ◦
chat_ctx
(conversation history) — replaceable via
update_chat_ctx
. • Room input/output options ◦
audio_input
,
text_input
, noise-cancellation, sample rate, etc. — configured on session start (room options / RoomOptions). ◦
participant_kinds
(which participant types agent listens to) — set at start. • Interaction/timeouts ◦
user_away_timeout
,
min_consecutive_speech_delay
and similar interaction timing — configured on session start or adjusted where supported. • Session metadata & custom state ◦
userdata
,
job.metadata
— available to the agent and can hold session-specific state. • Custom lifecycle behavior ◦ Use
on_enter
,
on_user_turn_completed
, or other overridden hooks in a custom Agent subclass to initialize state, run greetings, or modify behavior when entering the session. If you want, tell me which parameter you plan to change (e.g., switching STT model, disabling interruptions, or updating instructions) and I’ll give the exact code snippet for that case. Sources: Agents and handoffs | LiveKit docs | Agent session | LiveKit docs | Agents (Python) | livekit/livekit_composite | DeepWiki | How to test your agent using another agent | Pipeline nodes and hooks | LiveKit docs
r
if a particular session has started which parameters can we update?
t
Regarding an already-started session, you can update these parameters at runtime: • AI models ◦
llm
,
stt
,
tts
,
vad
(can be overridden for the running agent) • Turn-detection & interruption settings ◦
allow_interruptions
◦
turn_detection
method ◦
min_endpointing_delay
,
max_endpointing_delay
◦ Update via
activity.update_options(...)
• Agent behavior & tools ◦
instructions
(use
update_instructions
) ◦
tools
(use
update_tools
) ◦
chat_ctx
/ conversation history (use
update_chat_ctx
) • Session metadata & custom state ◦
userdata
and other mutable session state • Custom lifecycle actions ◦ You can run logic in
on_enter
,
on_user_turn_completed
, etc., to modify behavior or state while the session is active Parameters typically set only at session start and not changed at runtime: • Room input/output base options (e.g., `audio_input`/sample rate,
participant_kinds
) • Some interaction timeouts if not exposed for runtime change Which specific parameter do you want to update right now? I can provide the exact code snippet.
r
user_away_timeout give me example of this how can I use so if there is total silence by agent and user is not speaking
t
You're asking how to use
user_away_timeout
to detect total silence (both agent and user not speaking) and take action. Below is a concise explanation and a runnable example pattern you can adapt. What
user_away_timeout
does • It's a timeout (seconds) after which the session marks the user as "away" if no user speech activity is detected. Use it to trigger follow-ups, end the session, or run cleanup when both sides are silent. Example pattern (pseudo/Python-like) 1. Set
user_away_timeout
when you start the session or update session options. 2. Listen for the session's "user_away" or equivalent event, or poll the session state. 3. On the event, take the desired action (send a prompt, end call, log, etc.). 4. Cancel/reset timeout when user speech resumes. Example:
Copy code
# set when creating the session or updating options
session_options = {
    "user_away_timeout": 30.0  # seconds of silence before marking user away
}
session.start(options=session_options)

# event handler for user away
async def on_user_away(event):
    # action when both agent and user silent for user_away_timeout
    await session.generate_reply(instructions="Are you still there?"),
    # or end session:
    # await session.end(reason="user_away_timeout")

# handler for user speech resuming
async def on_user_speech(event):
    # reset any timers/flags and continue normal flow
    pass

# register handlers (API names may vary)
session.on("user_away", on_user_away)
session.on("user_speech", on_user_speech)
Tips • Use a short prompt (e.g., “Are you still there?”) before ending the session to allow the user to respond. • If you need mid-session dynamic changes, you can update the timeout at runtime (e.g.,
activity.update_options(user_away_timeout=60.0)
). • Combine with
min_endpointing_delay
/
turn_detection
so silence detection aligns with your voice activity settings. Tell me which language or SDK you're using (Python/JS/other) and whether you want the agent to prompt first or end the session — I’ll give a precise code snippet for that environment.
r
python give me precise eample
t
Below is a precise Python example that uses
user_away_timeout
to detect user silence, prompts the user when they go away, and ends the session after a longer period of total silence (no agent or user activity). Adjust model/plugin values and thresholds to your setup.
Copy code
import asyncio
import time
from livekit import agents
from livekit.agents import JobContext, UserState, UserStateChangedEvent

async def entrypoint(ctx: JobContext):
    # Configure session: user_away_timeout triggers when user is silent
    session = agents.AgentSession(
        ctx.room,
        llm="your-llm-id",
        stt="your-stt-id",
        tts="your-tts-id",
        user_away_timeout=15.0  # seconds of user silence => user marked AWAY
    )

    total_silence_threshold = 60.0  # seconds of total silence before ending session
    last_activity = time.time()
    end_task = None

    def mark_activity():
        nonlocal last_activity
        last_activity = time.time()
        nonlocal_cancel_end_task()

    def nonlocal_cancel_end_task():
        nonlocal end_task
        if end_task and not end_task.done():
            end_task.cancel()
            end_task = None

    def schedule_end_if_still_silent():
        nonlocal end_task
        nonlocal last_activity

        async def wait_and_end():
            try:
                await asyncio.sleep(total_silence_threshold)
                # if no activity since scheduled time, end room
                if time.time() - last_activity >= total_silence_threshold:
                    await ctx.room.disconnect()
            except asyncio.CancelledError:
                return

        # cancel existing timer and start a fresh one
        nonlocal_cancel_end_task()
        end_task = asyncio.create_task(wait_and_end())

    @session.on("user_state_changed")
    async def on_user_state_changed(event: UserStateChangedEvent):
        # user became AWAY due to user_away_timeout
        if event.new_state == UserState.AWAY:
            mark_activity()  # treat event as activity for our timer logic
            # Prompt the user first
            await session.say("Are you still there?", allow_interruptions=True)
            # start total-silence timer to disconnect if no one responds
            schedule_end_if_still_silent()

        elif event.new_state == UserState.SPEAKING:
            mark_activity()

    @session.on("agent_state_changed")
    async def on_agent_state_changed(ev):
        # When agent speaks, treat as activity to delay total-silence disconnect
        if ev.new_state == "speaking":
            mark_activity()

    @session.on("user_speech")  # optional: direct speech activity hook if available
    async def on_user_speech(ev):
        mark_activity()

    # start the session
    await session.start()
Key points: •
user_away_timeout=15.0
marks the user AWAY after 15s of user silence (VAD-driven). • On AWAY, the agent prompts the user via
session.say(...)
. • We track
last_activity
(user or agent) and start a separate timer (
total_silence_threshold
) to end the session if no activity returns. • Cancel the end timer whenever user or agent activity resumes. Tell me if you want this adapted for your exact SDK objects/names (different event names or method signatures), or a version that only prompts (no disconnect). Sources: Agent session | LiveKit docs | Agents v0.x migration guide - Python | LiveKit docs | Events and error handling | LiveKit docs | Agents (Node.js) | livekit/livekit_composite | DeepWiki | How to detect and handle silence during calls
r
is there no internal method or functino which can do it easily and smoothly?
t
Short answer: there is no built‑in method that automatically detects total silence (both agent + user) and cleanly ends a session for you.
user_away_timeout
only marks the user as AWAY after user silence; you must handle any follow-up (prompting or disconnect) yourself. What you can do (smooth, minimal work): • Use
user_away_timeout
to get the user AWAY signal. • Listen for
user_state_changed
(AWAY / SPEAKING). • Track agent activity (agent_state_changed or when you call
session.say
) and user activity timestamps. • Run a small background timer: when AWAY occurs, prompt the user; if neither user nor agent activity resumes within your overall silence window, disconnect. If you want, I can: • Provide a slightly shorter production-ready Python snippet that plugs into your existing entrypoint (no extra explanatory comments). • Or adapt the example to your exact SDK event/method names and thresholds. Which would you prefer? Sources: Agent session | LiveKit docs | Agents Framework | livekit/livekit_composite | DeepWiki | How to detect and handle silence during calls