#!/usr/bin/env python3 """Test Gemini state management with automatic history inclusion.""" import asyncio import sys from pathlib import Path from gemini_integration import get_integration async def test_automatic_state(): """Test if Gemini automatically maintains state through history.""" print("๐Ÿงช Testing Automatic Gemini State Management") print("=" * 50) # Use singleton gemini = get_integration({ 'enabled': True, 'cli_command': 'gemini', 'timeout': 30, 'include_history': True, # This enables automatic history inclusion 'max_history_entries': 10, 'debug_mode': False }) # Clear any existing history gemini.clear_conversation_history() print("\n1๏ธโƒฃ First Question: What is 2+2?") print("-" * 30) try: response1 = await gemini.consult_gemini( query="What is 2+2?", context="", # No context needed force_consult=True ) if response1.get('status') == 'success': response_text = response1.get('response', '') print(f"โœ… Success! Gemini responded.") # Find and show the answer lines = response_text.strip().split('\n') for line in lines: if '4' in line or 'four' in line.lower(): print(f"๐Ÿ“ Found answer: {line.strip()[:100]}...") break else: print(f"โŒ Error: {response1.get('error', 'Unknown error')}") return except Exception as e: print(f"โŒ Exception: {e}") return print(f"\n๐Ÿ“Š Conversation history size: {len(gemini.conversation_history)}") print("\n2๏ธโƒฃ Second Question: What is that doubled?") print(" (No context provided - relying on automatic history)") print("-" * 30) try: # This time, provide NO context at all - let the history do the work response2 = await gemini.consult_gemini( query="What is that doubled?", context="", # Empty context - history should provide the context force_consult=True ) if response2.get('status') == 'success': response_text = response2.get('response', '') print(f"โœ… Success! Gemini responded.") # Check if it understood the context if '8' in response_text or 'eight' in response_text.lower(): print("๐ŸŽ‰ STATE MAINTAINED! Gemini understood 'that' referred to 4") print("๐Ÿ“ Found reference to 8 in the response") # Find and show where 8 appears for line in response_text.split('\n'): if '8' in line or 'eight' in line.lower(): print(f"๐Ÿ“ Context: {line.strip()[:100]}...") break else: print("โš ๏ธ Gemini may not have maintained state properly") print("๐Ÿ“ Response doesn't clearly reference 8") print(f"First 200 chars: {response_text[:200]}...") else: print(f"โŒ Error: {response2.get('error', 'Unknown error')}") except Exception as e: print(f"โŒ Exception: {e}") print(f"\n๐Ÿ“Š Final conversation history size: {len(gemini.conversation_history)}") # Test with history disabled print("\n3๏ธโƒฃ Testing with History Disabled") print("-" * 30) # Disable history gemini.include_history = False gemini.clear_conversation_history() # Ask first question await gemini.consult_gemini( query="What is 3+3?", context="", force_consult=True ) # Ask follow-up response3 = await gemini.consult_gemini( query="What is that tripled?", context="", force_consult=True ) if response3.get('status') == 'success': response_text = response3.get('response', '') if '18' in response_text or 'eighteen' in response_text.lower(): print("โŒ UNEXPECTED: Found 18 even without history!") else: print("โœ… EXPECTED: Without history, Gemini doesn't understand 'that'") # Show what Gemini says when it doesn't have context print(f"Response preview: {response_text[:200]}...") print("\nโœ… Test complete!") if __name__ == "__main__": asyncio.run(test_automatic_state())