steep-mechanic-38687
10/30/2025, 1:22 PMtall-airline-16756
10/30/2025, 1:22 PMtall-airline-16756
10/30/2025, 1:23 PMagent-starter-python. One helpful way is to keep an eye on the SIP call status through participant attributes. Specifically, you’ll want to listen for changes in the sip.callStatus attribute and watch for it to change to 'active'. This means the call is connected and the callee has answered—great news!
Here’s a simple example you can try out:
async def async_on_participant_attributes_changed(changed_attributes: dict, participant: rtc.Participant):
if participant.kind == rtc.ParticipantKind.PARTICIPANT_KIND_SIP and 'sip.callStatus' in changed_attributes:
call_status = changed_attributes['sip.callStatus']
if call_status == 'active':
logger.info("Callee has answered the call")
# Add your logic here (e.g., send a greeting)
This approach works smoothly for both inbound and outbound SIP calls. Plus, if you’re making outbound calls, you might find it handy to use the wait_until_answered=True parameter in create_sip_participant(). This will pause the process until the call is answered or unfortunately fails, helping you manage the flow better.
Sources: telephony/sip_lifecycle.py | agent.pysteep-mechanic-38687
10/30/2025, 2:11 PMtall-airline-16756
10/30/2025, 2:12 PMAgentSession lifecycle and stop the session from closing automatically. Here’s a simple way to do it:
1. Disable Automatic Session Closure: When you create the AgentSession, set close_on_disconnect=False in RoomInputOptions. This way, the session won’t close right away when the callee disconnects:
session = AgentSession(
input_options=RoomInputOptions(close_on_disconnect=False),
# Other options
)
1. Detach Long-Running Tasks: Use asyncio.create_task() to start tasks that run independently from the session lifecycle. For example:
@function_tool
async def initiate_background_task(self, query: str):
task = asyncio.create_task(self._long_running_operation(query))
self.active_tasks.append(task)
return "Background task initiated."
1. Manage Session Closure: Make sure to delay closing the session until all your tasks have finished. Here’s a way to do that:
async def graceful_shutdown(session: AgentSession, agent: MyAgent):
await asyncio.gather(*agent.active_background_tasks, return_exceptions=True)
await session.aclose()
By following these steps, your tasks will keep running and complete their work even after the callee disconnects. If you’d like me to walk you through this further or provide more examples, just let me know—I’m here to help!
Sources: examples/voice_agents/README.md | Agents telephony integration | LiveKit Docssteep-mechanic-38687
10/30/2025, 2:18 PMtall-airline-16756
10/30/2025, 2:19 PMfrom livekit.agents import WorkerOptions
worker_opts = WorkerOptions(
entrypoint_fnc=your_entrypoint,
drain_timeout=45 * 60 # 45 minutes
)
1. Use Shutdown Callbacks: It’s a great idea to register cleanup functions to make sure everything wraps up nicely before the process ends:
async def entrypoint(ctx: JobContext):
async def cleanup_resources():
logger.info("Cleaning up resources...")
# Save state, close connections, etc.
ctx.add_shutdown_callback(cleanup_resources)
1. Monitor and Manage Process Lifecycle: The framework has built-in features to help prevent the process from stopping too soon. Just make sure your job connects properly to the room and handles shutdown by calling ctx.connect() and ctx.shutdown().
Following these steps should really help keep your process active so your tasks can finish even after the call ends. If anything’s unclear or you’d like a hand with any of this, please don’t hesitate to reach out—I’m here to help!
Sources: Job lifecycle | LiveKit Docs | complex-agents/note-taking-assistant/agent.py | examples/voice_agents/silent_function_call.py | Worker options | LiveKit Docs