Is there anyway to limit the session time? I.e. 10...
# agents
n
Is there anyway to limit the session time? I.e. 10mins per call?
r
Sure set a timer when the session starts like at the top of entrypoint and after 10 minutes delete room.
n
@refined-appointment-81829 thanks for the prompt response! Is it in the token server or worker or job? Can you share the code sample?
b
@narrow-chef-82684 it would look something like:
Copy code
async def auto_hangup_timer(ctx: "JobContext", timeout_seconds: int = 600) -> None:
    await asyncio.sleep(timeout_seconds))
    await ctx.api.room.delete_room(DeleteRoomRequest(room=ctx.room.name))

async def entrypoint(ctx: JobContext) -> None:
    ...
    timeout_task = asyncio.create_task(auto_hangup_timer(ctx), name="auto_hangup")
    ...
If 600 seconds pass then it would delete the room. I'd also recommend cleaning the task in the shutdown callback.
n
@brave-island-45242 thanks for the code snippet! So this one lives in agent.py, right? And can this be implemented dynamically? I.e. communicate with the DB to check the different tiers the users are in like 10 mins, 20 mins, etc. And update to the DB for the remaining minutes?
b
The function for the timer can be anywhere, including the same file where your entrypoint is. If that is agent.py then you can use it there. In theory, you can execute whatever code you want in the entrypoint (though keep in mind the prewarming function if it takes considerable time). So you can fetch whatever user data you want, including the related tier data and pass the timeout seconds to the timer function
n
Hi @brave-island-45242 are you able to give more context about anywhere? Can it be done in the token server as well?
b
At the end of the day is just a python function. You can define it anywhere you want. For example, a file like entrypoint_utils.py. The agent.py is just another file, so you can define it there if you want. I'd recommend, even at risk of sounding a bit apathetic, to discuss this with an AI, I'm sure that based on this conversation it could explain you step by step what that means
As an aside, you would call it inside of your entrypoint. It doesn't matter where you have it.
n
@brave-island-45242 I see now, thanks a lot for your patience explaining all these! And I did discuss with AI as well. Lol, it does help
🙌 1