How to prevent interruptions during the start of a conversation

This question originally came up in our Slack community and the thread has been consolidated here for long-term reference.

I’m searching for a way to prevent an agent from being interrupted at the beginning of an AgentSession when using a realtime model.

Due to legal reasons, we need to ensure the agent is not interrupted when starting the conversation after a participant joins. The agent must explain that the human is speaking to an AI, and we don’t want interruptions during this explanation.

Is there a way to achieve this?

Both generate_reply() and say() have an allow_interruptions parameter that lets you control this:

async def on_enter(self):
    # Non-interruptible legal disclaimer
    await self.session.say(
        "This is an AI assistant. This call may be recorded.",
        allow_interruptions=False
    )
    
    # Now allow normal conversation with interruptions
    self.session.generate_reply()

Set allow_interruptions=False for the mandatory legal disclaimer, then allow normal interruptible conversation afterward.