Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!
Python
feat: LLM manages a todo list by itself
Clémence Lesné48037014c2eb
diff --git a/README.md b/README.mdindex d207847..eda8a20 100644--- a/README.md+++ b/README.md@@ -8,6 +8,7 @@ AI-powered call center solution with Azure and OpenAI GPT.- [x] Access to customer conversation history- [x] Bot can be called from a phone number+- [x] Create by itself a todo list of tasks to complete the claim- [x] Disengaging from a human agent when needed- [x] Fine understanding of the customer request with GPT-4 Turbo- [x] Follow a specific data schema for the claim@@ -136,7 +137,7 @@ make installAlso, a public file server is needed to host the audio files.-For this, you can use Azure Blob Storage. In that case, content of the project folder `resources` requires to be uploaded to the public container of the storage account.+For this, you can use Azure Blob Storage. In that case, content of the project folder `$web` requires to be uploaded to the public container of the storage account.### Rundiff --git a/helpers/prompts.py b/helpers/prompts.pyindex 521a316..f52c559 100644--- a/helpers/prompts.py+++ b/helpers/prompts.py@@ -25,6 +25,9 @@ class LLM(str, Enum):Claim status:{{claim}}++ Reminders:+ {{reminders}}"""SMS_SUMMARY_SYSTEM = f"""Assistant will summarize the call with the customer in a single SMS. The customer cannot reply to this SMS.@@ -44,6 +47,9 @@ class LLM(str, Enum):Claim status:{{claim}}+ Reminders:+ {{reminders}}+Conversation history:{{conversation}}"""@@ -58,6 +64,7 @@ class TTS(str, Enum):GOODBYE = f"Merci de votre appel, j'espère avoir pu vous aider. N'hésitez pas à rappeler, j'ai tout mémorisé. {CONFIG.workflow.bot_company} vous souhaite une excellente journée !"HELLO = f"Bonjour, je suis {CONFIG.workflow.bot_name}, l'assistant {CONFIG.workflow.bot_company} ! Je suis spécialiste des sinistres. Lorsque vous entendrez un bip, c'est que je travaille. Comment puis-je vous aider ?"NEW_CLAIM = "Je vais créer un nouveau dossier pour vous..."+ NEW_REMINDER = "Je crée un rappel dans votre dossier..."TIMEOUT_SILENCE = "Je suis désolé, je n'ai rien entendu. Si vous avez besoin d'aide, dites-moi comment je peux vous aider."UPDATED_CLAIM = "Je mets à jour votre dossier..."WELCOME_BACK = f"Bonjour, je suis {CONFIG.workflow.bot_name}, l'assistant {CONFIG.workflow.bot_company} ! Je vois que vous avez déjà appelé il y a moins de {CONFIG.workflow.conversation_timeout_hour} heures. Lorsque vous entendrez un bip, c'est que je travaille. Laissez-moi quelques secondes pour récupérer votre dossier..."diff --git a/main.py b/main.pyindex 1574cfe..91bbb99 100644--- a/main.py+++ b/main.py@@ -27,7 +27,7 @@ from helpers.logging import build_loggerfrom helpers.version import VERSIONfrom helpers.prompts import LLM as LLMPrompt, TTS as TTSPromptfrom models.action import ActionModel, Indent as IndentAction-from twilio.rest import Client+from models.reminder import ReminderModelfrom twilio.base.exceptions import TwilioRestExceptionfrom twilio.rest import Clientfrom models.call import (@@ -431,6 +431,14 @@ async def intelligence()await intelligence(call, client, target_caller)+ elif chat_res.intent == IndentAction.NEW_REMINDER:+ await handle_play(+ call=call,+ client=client,+ text=TTSPrompt.NEW_REMINDER,+ )+ await intelligence(call, client, target_caller)+else:await handle_recognize(call=call,@@ -475,8 +483,9 @@ async def gpt_completion(system: LLMPrompt, call: CallModel) -> str:},{"content": system.format(- conversation=json.dumps(call.messages, default=pydantic_encoder),claim=call.claim.model_dump_json(),+ conversation=json.dumps(call.messages, default=pydantic_encoder),+ reminders=json.dumps(call.reminders, default=pydantic_encoder),),"role": "system",},@@ -512,6 +521,7 @@ async def gpt_chat(call: CallModel) -> ActionModel:{"content": LLMPrompt.CHAT_SYSTEM.format(claim=call.claim.model_dump_json(),+ reminders=json.dumps(call.reminders, default=pydantic_encoder),),"role": "system",},@@ -624,6 +634,35 @@ async def gpt_chat(call: CallModel) -> ActionModel:},},},+ {+ "type": "function",+ "function": {+ "description": "Use this if you think there is something important to do in the future, and you want to be reminded about it. Example: 'Remind Assitant thuesday at 10am to call back the customer', 'Remind Assitant next week to send the report', 'Remind the customer next week to send the documents by the end of the month'.",+ "name": IndentAction.NEW_REMINDER,+ "parameters": {+ "properties": {+ "description": {+ "description": "Contextual description of the reminder. Should be detailed enough to be understood by anyone. Example: 'Watch model is Rolex Submariner 116610LN', 'User said the witnesses car was red but the police report says it was blue. Double check with the involved parties'.",+ "type": "string",+ },+ "due_date_time": {+ "description": "Datetime when the reminder should be triggered. Should be in the future, in the ISO format.",+ "type": "string",+ },+ "title": {+ "description": "Short title of the reminder. Should be short and concise, in the format 'Verb + Subject'. Example: 'Call back customer', 'Send analysis report', 'Study replacement estimates for the stolen watch'.",+ "type": "string",+ },+ },+ "required": [+ "description",+ "due_date_time",+ "title",+ ],+ "type": "object",+ },+ },+ },]_logger.debug(f"Tools: {tools}")@@ -672,6 +711,15 @@ async def gpt_chat(call: CallModel) -> ActionModel:intent = IndentAction.NEW_CLAIMcall.claim = ClaimModel()model.content = "New claim created."+ elif name == IndentAction.NEW_REMINDER:+ intent = IndentAction.NEW_REMINDER+ parameters = json.loads(arguments)+ call.reminders.append(ReminderModel(+ description=parameters["description"],+ due_date_time=parameters["due_date_time"],+ title=parameters["title"],+ ))+ model.content = f"New reminder created for \"{parameters['due_date_time']}\" with title \"{parameters['title']}\" and description \"{parameters['description']}\"."models.append(model)diff --git a/models/action.py b/models/action.pyindex 0c0d2cf..0da961b 100644--- a/models/action.py+++ b/models/action.py@@ -7,6 +7,7 @@ class Indent(str, Enum):CONTINUE = "continue"END_CALL = "end_call"NEW_CLAIM = "new_claim"+ NEW_REMINDER = "new_reminder"TALK_TO_HUMAN = "talk_to_human"UPDATE_CLAIM = "update_claim"diff --git a/models/call.py b/models/call.pyindex 5e6ecb9..05ce95c 100644--- a/models/call.py+++ b/models/call.py@@ -1,6 +1,7 @@from datetime import datetimefrom enum import Enumfrom models.claim import ClaimModel+from models.reminder import ReminderModelfrom pydantic import BaseModel, Fieldfrom typing import Listfrom uuid import UUID, uuid4@@ -33,3 +34,4 @@ class CallModel(BaseModel):messages: List[MessageModel] = []phone_number: strrecognition_retry: int = Field(default=0)+ reminders: List[ReminderModel] = []diff --git a/models/reminder.py b/models/reminder.pynew file mode 100644index 0000000..7a93424--- /dev/null+++ b/models/reminder.py@@ -0,0 +1,9 @@+from datetime import datetime+from pydantic import BaseModel, Field+++class ReminderModel(BaseModel):+ created_at: datetime = Field(default_factory=datetime.utcnow)+ description: str+ due_date_time: str+ title: str