| import logging | |
| from collections import Counter | |
| logger = logging.getLogger("ONYX") | |
| class MemoryIntelligenceEngine: | |
| def __init__(self, memory_manager): | |
| self.memory_manager = memory_manager | |
| # ========================= | |
| # ANALYZE MEMORY | |
| # ========================= | |
| def analyze(self): | |
| try: | |
| history = self.memory_manager.load_memory() | |
| themes = [] | |
| for exchange in history: | |
| user_message = exchange.get("user", "") | |
| if user_message: | |
| themes.append(user_message.lower()) | |
| if not themes: | |
| return { | |
| "top_topics": [], | |
| "count": 0 | |
| } | |
| counter = Counter(themes) | |
| most_common = counter.most_common(5) | |
| return { | |
| "top_topics": most_common, | |
| "count": len(themes) | |
| } | |
| except Exception as e: | |
| logger.error(f"Memory analysis error: {e}") | |
| return { | |
| "top_topics": [], | |
| "count": 0 | |
| } | |
| # ========================= | |
| # SUGGEST NEXT TOPIC | |
| # ========================= | |
| def suggest_topic(self): | |
| analysis = self.analyze() | |
| if not analysis["top_topics"]: | |
| return None | |
| topic = analysis["top_topics"][0][0] | |
| logger.info(f"Suggested topic from memory: {topic}") | |
| return topic |