During a call transfer we mute the agent. The LLM ...
# ask-ai
b
During a call transfer we mute the agent. The LLM call that invoked the transfer_call tool then returns and the framework automatically asks the LLM to keep responding, so about 20 seconds later it tries to speak a follow-up message (e.g., ‘Seveda, prevezujem vas na lekarnarja.’). Because audio is muted, TTS hangs and the process is killed. Right now we clear ctx.session.chat_ctx.messages inside the tool before returning (and return None) to suppress the follow-up. Is there a better-supported way in LiveKit to tell the agent framework ‘don’t generate any more replies after this tool?’
t
Thanks for reaching out, Domen. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
It sounds like you want the agent to stop generating any follow-ups after the transfer tool runs. • The supported way is to have your transfer tool complete silently by returning
None
(no content). This ends the tool without prompting the LLM for a reply, so no TTS is attempted after the transfer. See tool behavior. • If you’re handing off to a different agent (e.g., a transfer/cleanup agent), return that agent instance from the tool to transfer control explicitly. See workflows/hand-offs. • For cold transfers that end the caller’s LiveKit session, performing the transfer will naturally stop the agent once complete. See transfers. • If the tool performs irreversible actions, call
run_ctx.disallow_interruptions()
at the start to prevent mid-tool interruptions. See tool behavior. Want a quick code snippet (Python/Node) showing
disallow_interruptions()
, the transfer call, and returning
None
? Sources: Tool definition and use | LiveKit docs | Workflows | LiveKit Docs | Transferring calls | LiveKit Docs | Agents telephony integration | LiveKit Docs
b
Yes give me a quick python snippet
t
Here’s a minimal Python snippet showing a transfer tool that prevents follow-up replies by disallowing interruptions and returning None:
Copy code
from livekit.agents import function_tool, RunContext
from livekit.api import TransferSIPParticipantRequest

@function_tool(name="transfer_call", description="Transfer the current caller to a phone number or SIP URI")
async def transfer_call(run_ctx: RunContext, transfer_to: str) -> None:
    # Prevent mid-tool interruptions (irreversible external action)
    run_ctx.disallow_interruptions()

    # Build and perform the SIP transfer
    req = TransferSIPParticipantRequest(
        participant_identity=run_ctx.session.participant_identity,
        room_name=run_ctx.session.room_name,
        transfer_to=transfer_to,  # e.g., "tel:+15105550100" or "sip:+15105550100@sip.example.com"
    )
    await run_ctx.session.ctx.api.sip.transfer_sip_participant(req)

    # Complete silently so the LLM won't produce a follow-up reply
    return None
References: Tool behavior, SIP APIs Want this adapted to your transfer method (e.g., cold vs. warm transfer or specific SIP provider)? Sources: Tool definition and use | LiveKit docs | SIP APIs | LiveKit Docs