diff --git a/app.py b/app.py index 1d332bf..6e58775 100644 --- a/app.py +++ b/app.py @@ -128,6 +128,8 @@ Regles : - Pour supprimer/terminer une tache, utilise l'id si le contexte de conversation contient les dernieres taches affichees. - Pour retirer/enlever/supprimer un client de la liste, utilise supprimer_client. - Pour "quel client a le plus de taches", utilise analyser_taches. +- Si l'utilisateur dit "lui", "ce client", "ce projet" ou "cette tache", utilise le contexte de conversation en cours. +- Si l'utilisateur demande "que dois-je faire pour lui ?", "c'est quoi comme tache ?" ou "quelle est la tache ?", utilise chercher_memoire avec le dernier client/projet connu. """ @@ -820,9 +822,11 @@ def executer_action(action): if nom_action == "analyser_taches": if action.get("type") == "client_plus_taches": snapshot = get_memory_snapshot(limit=100) - return formater_client_plus_taches(snapshot), { + reponse, client_nom = formater_client_plus_taches(snapshot) + resultat_client = search_memory(client_nom) if client_nom else None + return reponse, { "memoryRead": True, - "memoryResult": { + "memoryResult": resultat_client or { "clients": snapshot["clients"], "projects": snapshot["projects"], "tasks": snapshot["tasks"], @@ -946,7 +950,7 @@ def formater_client_plus_taches(snapshot): if int(client_mem.get("open_task_count") or 0) > 0 ] if not clients_avec_taches: - return "Tu n'as aucune tache ouverte dans la memoire professionnelle." + return "Tu n'as aucune tache ouverte dans la memoire professionnelle.", "" max_count = max(int(client_mem["open_task_count"]) for client_mem in clients_avec_taches) premiers = [ @@ -964,7 +968,7 @@ def formater_client_plus_taches(snapshot): intro = f"Le client avec le plus de taches ouvertes est {premiers[0]} avec {max_count} tache(s)." else: intro = f"Les clients avec le plus de taches ouvertes sont {', '.join(premiers)} avec {max_count} tache(s) chacun." - return intro + "\n" + "\n".join(f"- {ligne}" for ligne in lignes) + return intro + "\n" + "\n".join(f"- {ligne}" for ligne in lignes), premiers[0] def traiter_message(session_id, texte, avec_audio=False): @@ -982,6 +986,20 @@ def traiter_message(session_id, texte, avec_audio=False): "memoryRead": flags["memoryRead"], } + action_suivi = detecter_suivi_contexte(session_id, texte) + if action_suivi: + reponse, flags = executer_actions(action_suivi) + mettre_a_jour_contexte(session_id, texte, reponse, flags) + audio_url = generer_audio(reponse) if avec_audio and TTS_PROVIDER == "groq" else None + return { + "reply": reponse, + "audioUrl": audio_url, + "emailSent": flags["emailSent"], + "contactSaved": flags["contactSaved"], + "memorySaved": flags["memorySaved"], + "memoryRead": flags["memoryRead"], + } + decision = router_intention(session_id, texte) flags = { "emailSent": False, @@ -1021,6 +1039,20 @@ def traiter_message(session_id, texte, avec_audio=False): } +def detecter_suivi_contexte(session_id, texte): + contexte = session_contexts.get(session_id, {}) + dernier_client = contexte.get("last_client") + if not dernier_client: + return None + + texte_min = texte.strip().lower() + if re.search(r"\b(lui|ce client|pour lui)\b", texte_min) and re.search(r"\b(que dois|quoi faire|a faire|à faire|tache|tâche)\b", texte_min): + return {"action": "chercher_memoire", "requete": dernier_client} + if re.search(r"\b(c'est quoi|quelle est|quelles sont|montre|detail|détail)\b", texte_min) and re.search(r"\b(tache|tâche|taches|tâches)\b", texte_min): + return {"action": "chercher_memoire", "requete": dernier_client} + return None + + def recuperer_action_confirmee(session_id, texte): contexte = session_contexts.get(session_id, {}) pending_action = contexte.get("pending_action")