Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
151 lines (124 loc) · 5.06 KB
/
Copy pathmain.py
File metadata and controls
151 lines (124 loc) · 5.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# main.py
import logging
import sys
import uuid
import warnings
import time
# Suppress the SQLite date warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)
# Configure Logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s | %(levelname)s | %(name)s | %(message)s',
datefmt='%H:%M:%S'
)
# Imports
try:
from sns2f_framework.core.orchestrator import Orchestrator
from sns2f_framework.core.trace_manager import trace_manager
except ImportError as e:
print(f"\n[CRITICAL] Import Error: {e}")
print("Are you running this from the D:\\Code\\Turiya directory?")
sys.exit(1)
def print_banner():
# Clear screen command (optional, makes it cleaner)
# print("\033[H\033[J", end="")
print(r"""
_____ _ __ _____ ___ _____
/ ___/ / | / / / ___/ |__ \ / ___/
\__ \ / |/ / \__ \ __/ / / /_
___/ / / /| / ___/ / / __/ / __/
/____/ /_/ |_/ /____/ /____/ /_/
Self-Evolving Neuro-Symbolic Swarm Framework
v7.0 - "Conscious"
--------------------------------------------
Commands:
/start - Start autonomous learning
/stop - Stop learning
/ask ... - Ask a question
/trace - Show the thought process
/consolidate - Crystallize concepts
/sleep - Perform maintenance cycle
/set mode [strict|safe|open] - Change crawler safety
/flush - Clear crawler queue
/quit - Exit
--------------------------------------------
""", flush=True)
def handle_response(response_text: str):
print(f"\n[🤖 AI]: {response_text}\n>> ", end="", flush=True)
def main():
print("--- Initializing System ---")
orc = Orchestrator()
print("--- Starting Agents ---")
orc.start()
print("--- Waiting for Neural Engine (10s) ---")
# Increased wait time to let the LLM load cleanly before we take over the screen
time.sleep(10.0)
print_banner()
last_req_id = None
try:
while True:
# Force flush to ensure the prompt is visible
sys.stdout.flush()
user_input = input(">> ").strip()
if not user_input: continue
if user_input.lower() == "/quit":
print("Exiting...")
break
elif user_input.lower() == "/start":
orc.start_learning()
print("[System]: Swarm is now learning...")
elif user_input.lower() == "/stop":
orc.stop_learning()
print("[System]: Learning paused.")
elif user_input.lower() == "/consolidate":
print("[System]: Mining concepts...")
count = orc.consolidate_knowledge()
print(f"[System]: Crystallized {count} concepts.")
elif user_input.lower() == "/trace":
if last_req_id:
print(trace_manager.get_trace(last_req_id))
else:
print("[System]: No history available.")
elif user_input.lower().startswith("/ask"):
query = user_input[5:].strip()
if query:
last_req_id = str(uuid.uuid4())
print(f"[System]: Thinking...")
orc.ask(query, handle_response, request_id=last_req_id)
else:
print("[System]: Ask what?")
elif user_input.lower() == "/flush":
orc.flush_perception()
print("[System]: Crawler queue cleared. Ready for new sources.")
elif user_input.lower() == "/sleep":
print("[System]: Initiating Sleep Cycle (Memory Pruning)...")
stats = orc.sleep_cycle()
print(f"[System]: Sleep Complete.")
print(f" - Noise Deleted: {stats.get('deleted_noise', 0)}")
print(f" - Duplicates Merged: {stats.get('merged_duplicates', 0)}")
print(f" - Concepts Formed: {stats.get('concepts_formed', 0)}")
print(f" - New Categories: {stats.get('abstractions_formed', 0)}")
elif user_input.lower().startswith("/set mode"):
parts = user_input.split()
if len(parts) == 3:
mode = parts[2].lower()
if mode in ["strict", "safe", "open"]:
orc.set_crawl_mode(mode)
print(f"[System]: Crawl mode set to {mode.upper()}.")
else:
print("[System]: Invalid mode. Use: strict, safe, open")
else:
print("[System]: Usage: /set mode [strict|safe|open]")
else:
print("[System]: Unknown command.")
except KeyboardInterrupt:
print("\n[System]: Force quit.")
except Exception as e:
print(f"\n[CRITICAL ERROR]: {e}")
finally:
print("--- Stopping Orchestrator ---")
orc.stop()
sys.exit(0)
if __name__ == "__main__":
main()