Please update app/lia_ure.py to add a “confused → ask once → pause for manager” safety net. 1) STATE FIELDS Use these fields on customer_state (set defaults if missing): - confusion_count: int (default 0) - needs_human_review: bool (default False) At the start of generate_lia_reply(), after you receive customer_state, ensure: if "confusion_count" not in customer_state: customer_state["confusion_count"] = 0 if "needs_human_review" not in customer_state: customer_state["needs_human_review"] = False 2) CLARITY TEMPLATE (FIRST TIME ONLY) Near the other templates, add: CLARITY_FIRST_REPLY = ( "Sorry, I’m not quite sure I’ve followed that.\n\n" "Could you say that again in a slightly different way, or let me know if you’re asking about your options, a booking, or something else?" ) 3) IF ALREADY ESCALATED → SILENT At the top of generate_lia_reply(), after the opted_out check, add: if customer_state.get("needs_human_review"): customer_state["last_message"] = inbound_text customer_state["last_reply_type"] = "AWAITING_MANAGER" # Don’t send anything to the customer once a manager is needed return "", customer_state 4) FINAL FALLBACK (WHEN NOTHING ELSE MATCHES) Right at the end of generate_lia_reply(), after all other handlers (appointment, slots, direct questions, small talk, T1–T6 etc.) and just before the function would normally end, add: confusion_count = customer_state.get("confusion_count", 0) if confusion_count == 0: # First time we genuinely don’t understand → ask for clarity once reply = CLARITY_FIRST_REPLY customer_state["confusion_count"] = 1 customer_state["last_message"] = inbound_text customer_state["last_reply_type"] = "CLARITY_REQUEST" return reply, customer_state else: # Second time still unclear → pause and flag for human manager customer_state["confusion_count"] = confusion_count + 1 customer_state["needs_human_review"] = True customer_state["last_message"] = inbound_text customer_state["last_reply_type"] = "ESCALATED_TO_MANAGER" # IMPORTANT: do not send anything to the customer here return "", customer_state This fallback should ONLY run if no earlier branch has returned a reply. 5) TEST After these changes, run: python -m app.lia_ure and manually simulate: - two unrecognised messages in a row → first one gets CLARITY_FIRST_REPLY, second one returns an empty string and sets needs_human_review=True, - subsequent messages when needs_human_review=True → empty reply.