Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!
Python
quality: Code comments
Clémence Lesnéc942d2868ec1
diff --git a/app/helpers/llm_tools.py b/app/helpers/llm_tools.pyindex 9629184..037dc80 100644--- a/app/helpers/llm_tools.py+++ b/app/helpers/llm_tools.py@@ -90,9 +90,12 @@ class DefaultPlugin(AbstractPlugin):- Customer wants explicitely to create a new claim- Talking about a totally different subject"""+ # Customer confirmationawait self.tts_callback(customer_response)+# Launch post-call intelligence for the current callawait self.post_callback(self.call)+# Store the last message and use it at first message of the new claimself.call = await _db.call_create(CallStateModel(@@ -163,6 +166,7 @@ class DefaultPlugin(AbstractPlugin):- Call back for a follow-up- Wait for customer to send a document"""+ # Customer confirmationawait self.tts_callback(customer_response)# Check if reminder already exists, if so update it@@ -250,7 +254,9 @@ class DefaultPlugin(AbstractPlugin):- Store details about the conversation- Update the claim with a new phone number"""+ # Customer confirmationawait self.tts_callback(customer_response)+# Update all claim fieldsres = "# Updated fields"for field in updates:@@ -260,6 +266,8 @@ class DefaultPlugin(AbstractPlugin):def _update_claim_field(self, update: UpdateClaimDict) -> str:field = update["field"]new_value = update["value"]++ # Update fieldold_value = self.call.claim.get(field, None)try:self.call.claim[field] = new_value@@ -340,7 +348,9 @@ class DefaultPlugin(AbstractPlugin):- Know the procedure to declare a stolen luxury watch- Understand the requirements to ask for a cyber attack insurance"""+ # Customer confirmationawait self.tts_callback(customer_response)+# Execute in paralleltasks = await asyncio.gather(*[@@ -348,8 +358,10 @@ class DefaultPlugin(AbstractPlugin):for query in queries])+# Flatten, remove duplicates, and sort by scoretrainings = sorted(set(training for task in tasks for training in task or []))+# Format documents for Content Safety scan compatibility# See: https://learn.microsoft.com/en-us/azure/ai-services/openai/concepts/content-filter?tabs=warning%2Cpython-new#embedding-documents-in-your-prompttrainings_str = "\n".join(@@ -358,6 +370,7 @@ class DefaultPlugin(AbstractPlugin):for training in trainings])+# Format resultsres = "# Search results"res += f"\n{trainings_str}"@@ -412,6 +425,7 @@ class DefaultPlugin(AbstractPlugin):- A neighbor is having a heart attack- Someons is stuck in a car accident"""+ # Customer confirmationawait self.tts_callback(customer_response)# TODO: Implement notification to emergency services for production usagelogger.info(@@ -454,13 +468,18 @@ class DefaultPlugin(AbstractPlugin):- Confirm a detail like a reference number, if there is a misunderstanding- Send a confirmation, if the customer wants to have a written proof"""+ # Customer confirmationawait self.tts_callback(customer_response)++ # Send SMSsuccess = await _sms.send(content=message,phone_number=self.call.initiate.phone_number,)if not success:return "Failed to send SMS"++ # Add message to callself.call.messages.append(MessageModel(action=MessageActionEnum.SMS,@@ -505,11 +524,14 @@ class DefaultPlugin(AbstractPlugin):"""# Clamp speed between min and maxspeed = max(0.75, min(speed, 1.25))+# Update voiceinitial_speed = self.call.initiate.prosody_rateself.call.initiate.prosody_rate = speed+# Customer confirmation (with new speed)await self.tts_callback(customer_response)+# LLM confirmationreturn f"Voice speed set to {speed} (was {initial_speed})"@@ -572,7 +594,9 @@ class DefaultPlugin(AbstractPlugin):# Update langinitial_lang = self.call.lang.short_codeself.call.lang = lang+# Customer confirmation (with new language)await self.tts_callback(customer_response)+# LLM confirmationreturn f"Voice language set to {lang} (was {initial_lang})"