tall-autumn-57974
08/19/2025, 2:26 PMtall-airline-16756
08/19/2025, 2:26 PMtall-airline-16756
08/19/2025, 2:29 PMtall-autumn-57974
08/19/2025, 2:30 PMtall-airline-16756
08/19/2025, 2:30 PMtall-autumn-57974
08/19/2025, 2:31 PMvalidate_phone_number
tool"
)
@function_tool()
async def validate_phone_number(
self, context: RunContext_T
) -> Union[str, Tuple[Agent, str]]:
"""
Called when the user has entered their phone number and terminated with a #
"""
logger.info(f"Validating phone number: {self.phone_number}")
if not is_valid_french_mobile_phone_number(self.phone_number):
self.phone_number = ""
return "The number is incorrect. Ask the patient to try again"
context.userdata.ctx.room.off("sip_dtmf_received", self._handle_dtmf)
await self.session.generate_reply(
instructions="Thank the patient and tell them their phone number has been registered"
)
retrieved_patient = await retrieve_existing_patient(
context.userdata.config_id,
RetrievePatientRequest(phone_number=self.phone_number),
)
if retrieved_patient:
context.userdata.retrieved_patient = retrieved_patient
welcome_agent = context.userdata.agents["welcome"]
# TODO FIXME: context.userdata.agents should be a dict of BaseAgent (but it creates a circular import)
welcome_agent.mute_on_enter = True # type: ignore
return welcome_agent, "Don't greet the patient, just ask them how you can help"tall-airline-16756
08/19/2025, 2:33 PMallow_interruptions=False
during key moments like validation or when thanking the user. This way, the bot’s speech won’t get cut off by DTMF inputs or other events.
• Mandatory Validation Tool Calls: Make sure the validation tool always runs by configuring the tool execution flow. Setting tool_choice='required'
can help keep this consistent.
• Duplicate Greetings: To avoid repeating greetings, add some state tracking in your agent’s on_enter
method. For example, use a flag like self._greeting_delivered
to check if the greeting’s already been sent.
If you want, I’d be happy to walk you through the details of implementing any of these fixes!
Sources: README.md | Agent speech and audio | LiveKit Docs | agents/src/pipeline/pipeline_agent.ts