-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
executable file
·205 lines (159 loc) · 6.32 KB
/
run.py
File metadata and controls
executable file
·205 lines (159 loc) · 6.32 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/usr/bin/env python3
"""
Cognitive Engine - Entry Point
Main entry point for the Cognitive Engine system.
"""
import asyncio
import sys
from pathlib import Path
# Add project root to path
project_root = Path(__file__).parent
sys.path.insert(0, str(project_root))
def print_banner():
"""Print the startup banner"""
banner = """
╔════════════════════════════════════════════════════════════════╗
║ ║
║ COGNITIVE ENGINE ║
║ ║
║ Explicit • Persistent • Inspectable ║
║ ║
║ Thought Formation System ║
║ ║
╚════════════════════════════════════════════════════════════════╝
"""
print(banner)
async def interactive_mode():
"""Run the engine in interactive mode"""
from api.interface import interface
from utils.logger import logger
print("\nInteractive Mode")
print("Type 'quit' or 'exit' to stop\n")
while True:
try:
user_input = input("You: ").strip()
if user_input.lower() in ['quit', 'exit', 'q']:
print("Goodbye!")
break
if not user_input:
continue
print("\nProcessing...")
result = await interface.process_async(user_input)
if result.get("success"):
# Show the thought first
top_thoughts = result.get('top_thoughts', [])
if top_thoughts:
print(f"\nThought: {top_thoughts[0].get('premise', 'No thought generated')}")
# Then show the human-readable response
print(f"\nResponse: {result['output']}")
print(f"\n[Stats: {result['thought_count']} thoughts, {result['iterations']} iterations, {result['duration_seconds']:.2f}s]")
else:
print(f"\nError: {result.get('error', 'Unknown error')}")
print()
except KeyboardInterrupt:
print("\nGoodbye!")
break
except Exception as e:
logger.error(f"Error: {e}")
print(f"\nError: {e}\n")
async def agent_mode():
"""Run the engine in agent mode"""
from agent.agent import CognitiveAgent
from utils.logger import logger
print("\nAgent Mode")
print("Set a goal for the autonomous agent\n")
agent = CognitiveAgent()
while True:
try:
goal_input = input("Goal: ").strip()
if goal_input.lower() in ['quit', 'exit', 'q']:
print("Goodbye!")
break
if not goal_input:
continue
print("\nSetting goal and running autonomous cycle...")
goal_id = await agent.set_goal(goal_input)
result = await agent.run_autonomous(goal_id, max_cycles=5)
print(f"\nResult: {result}")
print(f"Status: {agent.get_status()}\n")
except KeyboardInterrupt:
print("\nGoodbye!")
break
except Exception as e:
logger.error(f"Error: {e}")
print(f"\nError: {e}\n")
def dashboard_mode():
"""Run the dashboard server"""
from dashboard.server import start_dashboard
from utils.logger import logger
print("\nDashboard Mode")
print("Starting dashboard server...\n")
try:
start_dashboard()
except KeyboardInterrupt:
print("\nDashboard stopped")
async def test_mode():
"""Run a simple test of the engine"""
from api.interface import interface
from utils.logger import logger
print("\nTest Mode")
print("Running basic functionality test...\n")
test_queries = [
"What is the meaning of life?",
"Explain quantum computing in simple terms.",
"How can I improve my productivity?"
]
for query in test_queries:
print(f"\nTesting: {query}")
result = interface.process(query)
if result.get("success"):
# Show the thought first
top_thoughts = result.get('top_thoughts', [])
if top_thoughts:
print(f"✓ Thought: {top_thoughts[0].get('premise', 'No thought generated')[:100]}...")
# Then show the response
print(f" Response: {result['output'][:100]}...")
print(f" Stats: {result['thought_count']} thoughts, {result['iterations']} iterations")
else:
print(f"✗ Failed: {result.get('error')}")
print("\nTest complete!")
def main():
"""Main entry point"""
print_banner()
if len(sys.argv) > 1:
mode = sys.argv[1].lower()
else:
print("Select mode:")
print("1. Interactive Mode")
print("2. Agent Mode")
print("3. Dashboard Mode")
print("4. Test Mode")
print()
try:
choice = input("Enter choice (1-4): ").strip()
except KeyboardInterrupt:
print("\nGoodbye!")
return
modes = {
'1': 'interactive',
'2': 'agent',
'3': 'dashboard',
'4': 'test'
}
mode = modes.get(choice, 'interactive')
try:
if mode == 'interactive':
asyncio.run(interactive_mode())
elif mode == 'agent':
asyncio.run(agent_mode())
elif mode == 'dashboard':
dashboard_mode()
elif mode == 'test':
asyncio.run(test_mode())
else:
print(f"Unknown mode: {mode}")
print("Usage: python run.py [interactive|agent|dashboard|test]")
except KeyboardInterrupt:
print("\nGoodbye!")
if __name__ == "__main__":
main()