这是indexloc提供的服务,不要输入任何密码
Skip to content

user_away_timeout doesn't seem to take effect #2947

@kirylkliushkin

Description

@kirylkliushkin

Hi,

I am specifying user_away_timeout when creating session. Then I start agent and don't talk to it. After specified period of inactivity I expect the session to be closed, but it doesn't happen. Below is the code to reproduce.

from dotenv import load_dotenv
from livekit import agents
from livekit.agents import AgentSession, RoomInputOptions, RunContext, function_tool, llm, stt, tts, metrics, MetricsCollectedEvent
from livekit.plugins import (
    openai,
    deepgram,
    silero,
)
from livekit.plugins.turn_detector.multilingual import MultilingualModel

load_dotenv()

def prewarm(proc: agents.JobProcess):
    proc.userdata["vad"] = silero.VAD.load(
        activation_threshold=0.7, # default is 0.5. The hight the value, the lesssensititve the VAD is. 
    )

async def entrypoint(ctx: agents.JobContext):
    await ctx.connect()
    
    session = AgentSession(     
        user_away_timeout=3, # expected the session to close after 3 sec on inactivivty
        stt=deepgram.STT(
            model="nova-3", 
            language="multi", 
        ),
        llm=openai.LLM(model="gpt-4.1-mini"),
        tts=openai.TTS(
            model="gpt-4o-mini-tts",
            voice="echo",
            instructions="Speak fast. Use natural, warm, friendly, and conversational tone.",
            speed=1.4
        ),
        
        vad=ctx.proc.userdata["vad"],
        turn_detection=MultilingualModel(),
        max_tool_steps=10,
        min_interruption_duration=0.75,
    )

    # Handle session close events
    @session.on("close")
    def on_close(event):
        """Handle session close events"""
        print(f"!!!Session closed: {event}")
       
    test_agent = TestAgent()
    await session.start(
        room=ctx.room,
        agent=test_agent,
    )

   
class TestAgent(agents.Agent):
    def __init__(self) -> None:
        super().__init__(instructions="You are a helpful voice AI assistant.")

    @function_tool()
    async def say_hello(self, ctx: RunContext, name: str | None = None) -> None:
        print(f"!!!using say_hello: {name}")
        if name:
            await ctx.session.say(f"Hello, {name}!")
        else:
            await ctx.session.say("Hello, stranger!!!")

    async def on_enter(self) -> None:
        await self.session.generate_reply(
            instructions="Greet user using say_hello tool",
            tool_choice="auto"
        )

if __name__ == "__main__":
    agents.cli.run_app(agents.WorkerOptions(entrypoint_fnc=entrypoint, prewarm_fnc=prewarm))

Deps:

python = "^3.12"
livekit-agents = {version = ">=1.0,<2.0"}
livekit-plugins-noise-cancellation = ">=0.2,<1.0"
python-dotenv = ">=1.1.0,<2.0.0"
supabase = ">=2.15.1,<3.0.0"
google-api-python-client = ">=2.170.0,<3.0.0"
google-auth-oauthlib = ">=1.2.2,<2.0.0"
html2text = ">=2025.4.15,<2026.0.0"
langchain = ">=0.3.25,<0.4.0"
langchain-openai = ">=0.3.18,<0.4.0"
pydantic-settings = "^2.9.1"
livekit-plugins-turn-detector = "^1.0.23"
livekit-plugins-openai = "^1.0.23"
livekit-plugins-silero = "^1.0.23"
livekit-plugins-deepgram = "^1.0.23"
livekit-plugins-cartesia = "^1.0.23"
pyjwt = ">=2.8.0,<3.0.0"
langchain-google-genai = "^2.1.5"
asyncstdlib = "^3.13.1"
livekit-plugins-google = "^1.1.1"

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions