narrow-laptop-64001
09/11/2025, 4:01 PM@function_tool()
async def leave_voicemail(self, ctx: RunContext):
"""
TERMINAL FUNCTION.
Leave an automated voicemail message when the call is forwarded to voicemail.
Rules:
- Do not append any ADDITIONAL instructions, commentary, or acknowledgements.
"""
logger.info("Leaving voicemail for patient")
voicemail_message = self.voicemail_template or self.get_default_voicemail()
logger.info(f"Voicemail message: {voicemail_message[:100]}...")
await ctx.session.say(
text=voicemail_message,
)
await self.end_call(ctx=ctx)
Section which handles voicemail in my prompt:
### 5. WHEN CALL IS FORWARDED TO VOICEMAIL
If the call is forwarded to voicemail:
**IMMEDIATE ACTION REQUIRED:**
- IMMEDIATELY use: `leave_voicemail()`
- **CRITICAL: This function will automatically:**
- Deliver the complete voicemail message
- Wait for message delivery to complete
- Update call records appropriately
- End the call automatically
- **DO NOT take any other actions after calling this function**
- **DO NOT continue conversation or use `end_call()` separately**
**Technical Notes:**
- The `leave_voicemail()` function handles timing automatically
- No additional delays or actions needed
- Function includes built-in message delivery verificationnarrow-laptop-64001
09/11/2025, 6:11 PM