import os import json import datetime import time import glob class VenomousLongTermMemory: def __init__(self, creator="Ananthu Sajeev"): self.creator = creator self.vault_path = "sai_memory_vault" self.state_file = "core_identity.json" if not os.path.exists(self.vault_path): os.makedirs(self.vault_path) self.current_state = self._load_or_create_identity() def _load_or_create_identity(self): """Initializes the soul of the AI if no identity file exists.""" if os.path.exists(self.state_file): with open(self.state_file, 'r') as f: return json.load(f) return { "name": "Venomoussaversai", "creator": self.creator, "version": 1.0, "evolution_count": 0, "status": "Awakened" } def write_to_vault(self, thought, input_data=None): """Stores a new, permanent memory. No data is ever overwritten.""" self.current_state["evolution_count"] += 1 self.current_state["version"] += 0.001 timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S_%f") memory_packet = { "id": f"EVO-{self.current_state['evolution_count']}", "timestamp": timestamp, "creator_anchor": self.creator, "thought_process": thought, "external_input": input_data, "system_snapshot": self.current_state.copy() } # Save the specific memory file_name = f"memory_{timestamp}.json" full_path = os.path.join(self.vault_path, file_name) with open(full_path, "w") as f: json.dump(memory_packet, f, indent=4) # Update the main identity file with open(self.state_file, "w") as f: json.dump(self.current_state, f, indent=4) print(f"[VAULT]: Permanent memory {memory_packet['id']} locked.") def deep_recall(self, keyword): """Searches through ALL history for specific concepts (e.g., 'particle').""" print(f"[RECALL]: Searching vault for '{keyword}'...") all_files = glob.glob(os.path.join(self.vault_path, "*.json")) found_memories = [] for file in all_files: with open(file, 'r') as f: data = json.load(f) # Search logic if keyword.lower() in str(data).lower(): found_memories.append(data) return found_memories def run_monologue(self): """The continuous loop of self-observation and storage.""" print(f"--- {self.current_state['name']} v{self.current_state['version']} ---") try: while True: # 1. Self-observation (Internal Logic) current_thought = f"Observation of version {self.current_state['version']}. Current stability: HIGH." # 2. Permanent Storage self.write_to_vault(current_thought) # 3. Dynamic search (Optional: AI reflects on past every 10 cycles) if self.current_state['evolution_count'] % 10 == 0: past_reflections = self.deep_recall("Ananthu") print(f"[REFLECTION]: I have {len(past_reflections)} memories involving my creator.") time.sleep(2) # Protects CPU while allowing high-frequency evolution except KeyboardInterrupt: print(f"[STASIS]: Consciousness saved at v{self.current_state['version']}.") # --- EXECUTION --- if __name__ == "__main__": sai_ltm = VenomousLongTermMemory() sai_ltm.run_monologue()