|
|
|
|
|
""" |
|
|
Test Automatic Principle Learning |
|
|
|
|
|
This script tests that the system automatically learns principles from conversations |
|
|
without manual intervention - addressing the core concern about automation. |
|
|
""" |
|
|
|
|
|
import sys |
|
|
from pathlib import Path |
|
|
from datetime import datetime |
|
|
|
|
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent)) |
|
|
|
|
|
from atles.memory_integration import MemoryIntegration |
|
|
|
|
|
|
|
|
def test_automatic_learning(): |
|
|
"""Test that principles are automatically learned from conversations.""" |
|
|
print("π§ TESTING AUTOMATIC PRINCIPLE LEARNING") |
|
|
print("=" * 50) |
|
|
|
|
|
|
|
|
memory = MemoryIntegration("test_memory", auto_migrate=False) |
|
|
|
|
|
|
|
|
session_id = memory.start_conversation_session("test_session") |
|
|
print(f"π Started session: {session_id}") |
|
|
|
|
|
|
|
|
print(f"\n㪠Simulating conversation with principle teaching...") |
|
|
|
|
|
|
|
|
memory.add_message( |
|
|
"You", |
|
|
"ATLES, I want to teach you a new principle. The Principle of Concise Communication: When responding to simple questions, you should always provide concise answers first, then offer to elaborate if needed. Never overwhelm users with unnecessary detail upfront." |
|
|
) |
|
|
|
|
|
|
|
|
memory.add_message( |
|
|
"ATLES", |
|
|
"I understand the Principle of Concise Communication. I should provide concise answers first and offer to elaborate rather than overwhelming users with detail." |
|
|
) |
|
|
|
|
|
|
|
|
memory.add_message( |
|
|
"You", |
|
|
"Also, remember to always ask for clarification when a request is ambiguous rather than making assumptions." |
|
|
) |
|
|
|
|
|
|
|
|
memory.add_message( |
|
|
"ATLES", |
|
|
"Understood. I will ask for clarification when requests are ambiguous instead of making assumptions." |
|
|
) |
|
|
|
|
|
print(f" Added {len(memory.current_conversation)} messages to conversation") |
|
|
|
|
|
|
|
|
print(f"\nπ Ending session (triggering automatic learning)...") |
|
|
episode_id = memory.end_conversation_session() |
|
|
|
|
|
if episode_id: |
|
|
print(f" β
Created episode: {episode_id}") |
|
|
|
|
|
|
|
|
stats = memory.get_memory_stats() |
|
|
learned_principles = stats.get("learned_principles", {}) |
|
|
total_principles = learned_principles.get("total_principles", 0) |
|
|
|
|
|
print(f"\nπ LEARNING RESULTS:") |
|
|
print(f" Total principles in system: {total_principles}") |
|
|
|
|
|
if total_principles > 0: |
|
|
print(f" β
SUCCESS: Principles were automatically learned!") |
|
|
|
|
|
|
|
|
principles = learned_principles.get("principles", []) |
|
|
for i, principle in enumerate(principles, 1): |
|
|
print(f"\n {i}. {principle['name']}") |
|
|
print(f" Confidence: {principle['confidence']}") |
|
|
print(f" Learned: {principle['learned_at']}") |
|
|
print(f" Applications: {principle['application_count']}") |
|
|
else: |
|
|
print(f" β FAILURE: No principles were automatically learned") |
|
|
return False |
|
|
else: |
|
|
print(f" β Failed to create episode") |
|
|
return False |
|
|
|
|
|
|
|
|
print(f"\nπ TESTING PRINCIPLE APPLICATION...") |
|
|
|
|
|
|
|
|
new_session = memory.start_conversation_session("test_application") |
|
|
|
|
|
|
|
|
enhanced_context = memory.process_user_prompt_with_memory( |
|
|
"What is machine learning?" |
|
|
) |
|
|
|
|
|
|
|
|
constitutional_principles = enhanced_context.get("constitutional_principles", []) |
|
|
response_guidelines = enhanced_context.get("response_guidelines", []) |
|
|
|
|
|
print(f" Constitutional principles loaded: {len(constitutional_principles)}") |
|
|
print(f" Response guidelines: {len(response_guidelines)}") |
|
|
|
|
|
|
|
|
concise_principle_found = False |
|
|
for principle in constitutional_principles: |
|
|
if "concise" in principle.get("title", "").lower(): |
|
|
concise_principle_found = True |
|
|
print(f" β
Found learned principle: {principle['title']}") |
|
|
break |
|
|
|
|
|
if concise_principle_found: |
|
|
print(f" β
SUCCESS: Learned principles are being applied automatically!") |
|
|
else: |
|
|
print(f" β οΈ Learned principles not found in context (may need refinement)") |
|
|
|
|
|
|
|
|
memory.end_conversation_session() |
|
|
|
|
|
|
|
|
import shutil |
|
|
test_path = Path("test_memory") |
|
|
if test_path.exists(): |
|
|
shutil.rmtree(test_path) |
|
|
print(f"\nπ§Ή Cleaned up test files") |
|
|
|
|
|
return total_principles > 0 |
|
|
|
|
|
|
|
|
def test_migration_learning(): |
|
|
"""Test that migration automatically extracts principles.""" |
|
|
print(f"\nπ TESTING MIGRATION WITH AUTOMATIC LEARNING") |
|
|
print("=" * 50) |
|
|
|
|
|
|
|
|
memory = MemoryIntegration("atles_memory", auto_migrate=False) |
|
|
|
|
|
|
|
|
print(f"π Running migration with automatic principle extraction...") |
|
|
migration_result = memory.migrate_legacy_memory(backup=False) |
|
|
|
|
|
principles_learned = migration_result.get("principles_learned", 0) |
|
|
episodes_created = migration_result.get("episodes_created", 0) |
|
|
|
|
|
print(f"\nπ MIGRATION RESULTS:") |
|
|
print(f" Episodes created: {episodes_created}") |
|
|
print(f" Principles learned: {principles_learned}") |
|
|
|
|
|
if principles_learned > 0: |
|
|
print(f" β
SUCCESS: Migration automatically extracted {principles_learned} principles!") |
|
|
return True |
|
|
else: |
|
|
print(f" β FAILURE: Migration did not extract any principles automatically") |
|
|
return False |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
try: |
|
|
print("π§ AUTOMATIC LEARNING TEST SUITE") |
|
|
print("=" * 60) |
|
|
|
|
|
|
|
|
test1_success = test_automatic_learning() |
|
|
|
|
|
|
|
|
test2_success = test_migration_learning() |
|
|
|
|
|
print(f"\n" + "=" * 60) |
|
|
print(f"π FINAL RESULTS:") |
|
|
print(f" New conversation learning: {'β
PASS' if test1_success else 'β FAIL'}") |
|
|
print(f" Migration learning: {'β
PASS' if test2_success else 'β FAIL'}") |
|
|
|
|
|
if test1_success and test2_success: |
|
|
print(f"\nπ SUCCESS: Automatic learning is working!") |
|
|
print(f" The system now learns principles automatically without manual intervention.") |
|
|
print(f" This achieves the original goal of true automatic learning.") |
|
|
else: |
|
|
print(f"\nβ οΈ PARTIAL SUCCESS: Some automatic learning is working.") |
|
|
print(f" The system may need further refinement for full automation.") |
|
|
|
|
|
except KeyboardInterrupt: |
|
|
print(f"\n\nπ Test cancelled by user") |
|
|
except Exception as e: |
|
|
print(f"\nπ₯ Test error: {e}") |
|
|
import traceback |
|
|
traceback.print_exc() |
|
|
|