rom livekit.agents import get_job_context
async def hangup_call():
ctx = get_current_job_context()
if ctx is None:
# Not running in a job context
return
await ctx.api.room.delete_room(
api.DeleteRoomRequest(
room=ctx.room.name,
)
)
class Assistant(Agent):
def __init__(
self, instructions: str, chat_ctx: Optional[ChatContext] = None
) -> None:
super().__init__(
instructions=instructions,
chat_ctx=chat_ctx,
)
async def on_enter(self):
self.session.generate_reply(
instructions="hello buddy!", allow_interruptions=False
)
# @function_tool
# async def conversation_finished(self):
# """(when the user confirms they don't want you anymore), call this function to end the conversation."""
# # interrupt any existing generation
# self.session.interrupt()
# # generate a goodbye message and hang up
# # awaiting it will ensure the message is played out before returning
# await self.session.generate_reply(
# instructions=f"say goodbye", allow_interruptions=False
# )
# job_ctx = get_current_job_context()
# # await self.test_aggregation()
# await job_ctx.api.room.delete_room(api.DeleteRoomRequest(room=job_ctx.room.name))
@function_tool
async def end_call(self, ctx: RunContext):
"""Called when the user wants to end the call"""
# let the agent finish speaking
current_speech = ctx.session.current_speech
if current_speech:
await current_speech.wait_for_playout()
await hangup_call()
im using hangup call fuction but the problem is the call gets hangup as soon as the agent is connected