big-action-73484
11/29/2025, 11:59 PMtall-airline-16756
11/29/2025, 11:59 PMtall-airline-16756
11/30/2025, 12:00 AMmax_call_duration in the SIP API request.
• If it's an agent session I can provide a simple timer pattern to disconnect after 300 seconds.
• If it's a regular room, tell me whether you prefer client-side enforcement (disconnect participants after 5 minutes) or server-side enforcement (have your server revoke tokens or end the room), and I’ll give exact code/snippets. Sources: SIP APIs | LiveKit docs | How to detect and handle silence during callsbig-action-73484
11/30/2025, 12:03 AMtall-airline-16756
11/30/2025, 12:03 AM// when the agent session starts
function onAgentSessionStart(agentSession) {
const MAX_MS = 5 * 60 * 1000; // 300000 ms = 5 minutes
const timeout = setTimeout(async () => {
try {
// gracefully end the session (adjust to your SDK method)
await agentSession.disconnect(); // or agentSession.end(), agentSession.close()
console.log('Agent session ended after 5 minutes');
} catch (err) {
console.error('Failed to end agent session:', err);
}
}, MAX_MS);
// optional: clear timer if session ends earlier
agentSession.on('ended', () => clearTimeout(timeout));
}
Python (asyncio) — background task
import asyncio
async def on_agent_session_start(agent_session):
MAX_SECONDS = 5 * 60 # 300 seconds
async def end_after_delay():
await asyncio.sleep(MAX_SECONDS)
try:
await agent_session.disconnect() # or agent_session.end(), agent_session.close()
print("Agent session ended after 5 minutes")
except Exception as e:
print("Failed to end agent session:", e)
# start background task
task = asyncio.create_task(end_after_delay())
# optional: cancel task if session ends earlier
def on_ended(_):
if not task.done():
task.cancel()
agent_session.on('ended', on_ended)
Notes and tips
• Replace disconnect() with the exact method your agent SDK uses to end a session (e.g., end() or close()).
• Ensure the timer runs on the same process that manages the session lifecycle so it can call the session teardown cleanly.
• If you need to handle partial minutes or extend/shorten the limit, make the delay value configurable.
• If sessions may be resumed or migrated across processes, let me know and I can show a server-side enforcement option (token revocation or room termination).
Would you like the snippet adapted to a specific SDK method name or to run inside your existing agent framework?