prehistoric-printer-73777
08/16/2025, 4:59 PMtall-airline-16756
08/16/2025, 4:59 PMtall-airline-16756
08/16/2025, 4:59 PMend_call
function not working after upgrading from livekit-agents
0.12 to 1.22 is probably because of some changes in how tool functions are defined and handled in the newer version. No worries though, here’s a simple way to fix it:
• Make sure you’re using the @function_tool()
decorator correctly, since the older @llm.ai_callable
decorator isn’t supported anymore.
• The function now needs to accept a RunContext
object as its parameter.
• Use get_job_context()
to get the job context when deleting the room.
Here’s an updated example you can try out:
from livekit.agents import get_job_context
from livekit.agents import function_tool
@function_tool()
async def end_call(ctx: RunContext):
"""End the current call by deleting the room."""
try:
# Let the current speech finish before ending the call
current_speech = ctx.session.current_speech
if current_speech:
await current_speech.wait_for_playout()
# Get the job context
job_ctx = get_job_context()
if job_ctx is None:
return "Failed to end call: No job context available"
# Delete the room to end the call
await job_ctx.api.room.delete_room(
api.DeleteRoomRequest(room=job_ctx.room.name)
)
return "Call ended successfully."
except Exception as e:
return f"Failed to end call: {e}"
Give this a try, and if you hit any snags or want to chat more about it, just let me know—I’m here to help! Sources: Agents 0.x migration guide | LiveKit Docs | Agents v0.x migration guide | LiveKit Docs | Agents telephony integration | LiveKit Docs | livekit-agents/livekit/agents/voice/agent_activity.py