busy-fish-13948
08/08/2025, 4:30 PM@function_tool()
async def end_call(self) -> None:
"""Use this tool to end the call."""
await self.session.generate_reply()
get_job_context().shutdown()
return None
This is working so far for me, the agent says goodbye, and then it shutdowns the session, triggers my shutdown_callback but it logs out `{"message": "failed to publish transcription\nTraceback (most recent call last):`every time, as if it shutdowns the session prematurely, how do I fix this problem? Is it even something that needs fixing? How can I achieve a seemingly trivial function of my LLM calling end_call -> Generate and output its replies -> actually shutdown when the output finishes? I cant seem to get it to work.refined-appointment-81829
08/08/2025, 7:23 PM@function_tool()
async def end_call(self) -> None:
"""Use this tool to end the call."""
# Generate and wait for the reply to complete
speech_handle = self.session.generate_reply(instructions="Thank you for calling. Goodbye!")
# Wait for the speech to actually finish
await speech_handle
# Now safely close the session
await self.session.drain()
await self.session.aclose()
return Nonebusy-fish-13948
08/11/2025, 9:00 AMawait self.session.generate_reply() , also I was doing self._closing_task = asyncio.create_task(self.session.aclose()) following this example https://github.com/livekit/agents/blob/main/examples/voice_agents/session_close_callback.py but it seemed like the session did end but the agent never disconnects from the room or the room never gets closed, leaving my user hanging alone in the client side UI.busy-fish-13948
08/11/2025, 9:01 AM