import asyncio import sys import os # Add project root to path sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from app.ai.agent.graph import get_aida_graph async def verify_fix(): print("šŸš€ Verifying Fixes for Intent & UI...") graph = get_aida_graph() session_id = "verify_session_001" user_id = "tester" # 1. INITIAL LISTING (Should not have replace flag) print("\n1. sending initial listing request...") state_1 = await graph.ainvoke({ "user_id": user_id, "session_id": session_id, "user_role": "landlord", "last_user_message": "List a 2-bed in Lagos", "start_new_session": True }, config={"configurable": {"thread_id": session_id}, "recursion_limit": 50}) temp_data_1 = state_1.get("temp_data", {}) replace_1 = temp_data_1.get("replace_last_message", False) intent_1 = state_1.get("intent_type") print(f" Intent: {intent_1}") print(f" Replace Flag: {replace_1} (Expected: False)") # 2. PROVIDE PRICE (Still building, replace flag false?) # "List a 2-bed in Lagos" -> Missing price. So it asks for price. print("\n2. Providing price...") state_2 = await graph.ainvoke({ "user_id": user_id, "session_id": session_id, "user_role": "landlord", "last_user_message": "50k", # Persist state via thread_id }, config={"configurable": {"thread_id": session_id}, "recursion_limit": 50}) # Check if we reached validate try: curr_flow = state_2.get("current_flow") # Handle enum if present if hasattr(curr_flow, 'value'): curr_flow = curr_flow.value print(f" Current Flow: {curr_flow}") except: print(f" Current Flow: {state_2.get('current_flow')}") # If we are in validate (draft shown), replace should be False (first show) temp_data_2 = state_2.get("temp_data", {}) replace_2 = temp_data_2.get("replace_last_message", False) print(f" Replace Flag: {replace_2} (Expected: False)") # 3. CHANGE COMMAND (The Fix!) print("\n3. Sending CHANGE command: 'Change price to 85k'...") state_3 = await graph.ainvoke({ "user_id": user_id, "session_id": session_id, "user_role": "landlord", "last_user_message": "Change price to 85k" }, config={"configurable": {"thread_id": session_id}, "recursion_limit": 50}) intent_3 = state_3.get("intent_type") temp_data_3 = state_3.get("temp_data", {}) replace_3 = temp_data_3.get("replace_last_message", False) draft_3 = state_3.get("listing_draft", {}) print(f" Intent: {intent_3} (Expected: listing)") print(f" Replace Flag: {replace_3} (Expected: True)") print(f" New Price: {draft_3.get('price')} (Expected: 85000.0)") passed = True if intent_3 != "listing": print("āŒ Intent check failed") passed = False if replace_3 is not True: print("āŒ Replace flag check failed") passed = False if draft_3.get("price") != 85000.0: print("āŒ Price update check failed") passed = False if passed: print("\nāœ… VERIFICATION PASSED!") else: print("\nāŒ VERIFICATION FAILED") if __name__ == "__main__": asyncio.run(verify_fix())