-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathace.py
More file actions
265 lines (196 loc) · 7.04 KB
/
Copy pathace.py
File metadata and controls
265 lines (196 loc) · 7.04 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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
from core.agent import ACEAgent
from runtime.logger import set_console_logging, get_console_logging
APP_NAME = "ACE"
APP_FULL_NAME = "Autonomous Cognitive Engine"
def line(char="-", width=72):
return char * width
def print_banner(show_logs: bool = False):
print("\n" + line("═"))
print(" █████╗ ██████╗███████╗")
print(" ██╔══██╗██╔════╝██╔════╝")
print(" ███████║██║ █████╗ ")
print(" ██╔══██║██║ ██╔══╝ ")
print(" ██║ ██║╚██████╗███████╗")
print(" ╚═╝ ╚═╝ ╚═════╝╚══════╝")
print(line("═"))
print(f" {APP_NAME} :: {APP_FULL_NAME}")
print(" Mode :: Interactive Agent Console")
print(" Runtime :: Tool-augmented reasoning")
print(" Memory :: Long-term vector recall enabled")
print(f" Display :: {'Detailed logs' if show_logs else 'Clean status mode'}")
print(line("-"))
print(" Commands:")
print(" /help Show commands")
print(" /logs Show log display mode")
print(" /logs on Show detailed runtime logs")
print(" /logs off Show clean spinner/status view")
print(" /paste Enter multi-line request mode")
print(" /clear Clear terminal")
print(" /exit End session")
print(line("═") + "\n")
def print_help():
print("\n" + line("-"))
print(" ACE COMMANDS")
print(line("-"))
print(" /help Show this help menu")
print(" /logs Show current log display mode")
print(
" /logs on Show detailed logs, raw responses, parsed JSON, args, and tool results"
)
print(
" /logs off Show only clean states like checking memory, thinking, and running tools"
)
print(" /paste Enter multi-line request mode. Submit with /end")
print(" /clear Clear the terminal screen")
print(" /exit End the current session")
print(" /quit End the current session")
print("")
print(" Keyboard:")
print(" Ctrl+C Gracefully stop ACE")
print(" Ctrl+Z then Enter Gracefully stop ACE on Windows")
print(line("-") + "\n")
def clear_screen():
import os
os.system("cls" if os.name == "nt" else "clear")
def print_processing(show_logs: bool):
print("\n" + line("-"))
if show_logs:
print(" ◉ ACE is running with detailed logs enabled.")
else:
print(" ◉ ACE is active. Showing clean runtime states.")
print(line("-"))
def print_result(result: str):
print("\n" + line("═"))
print(" RESPONSE")
print(line("═"))
print(result)
print(line("═") + "\n")
def print_exit():
print("\n" + line("-"))
print(" ACE session terminated gracefully.")
print(" Goodbye.")
print(line("-"))
def print_error(error: Exception):
print("\n" + line("-"))
print(" SYSTEM ERROR")
print(line("-"))
print(str(error))
print(line("-"))
def print_logs_status(agent: ACEAgent):
print("\n" + line("-"))
print(" ACE LOG DISPLAY")
print(line("-"))
agent_logs_enabled = getattr(agent, "show_logs", False)
console_logs_enabled = get_console_logging()
if agent_logs_enabled and console_logs_enabled:
print(" Mode :: Detailed logs enabled")
print(
" View :: terminal logs, raw responses, parsed JSON, action args, memories, and tool results"
)
else:
print(" Mode :: Clean status enabled")
print(
" View :: checking memory, thinking, parsing, running tools, saving memory"
)
print(" Logs :: still saved silently to logs/ace.log")
print(line("-") + "\n")
def set_logs(agent: ACEAgent, enabled: bool):
agent.show_logs = enabled
set_console_logging(enabled)
print("\n" + line("-"))
print(" ACE LOG DISPLAY UPDATED")
print(line("-"))
if enabled:
print(" Mode :: Detailed logs enabled")
print(
" View :: terminal logs, raw responses, parsed JSON, args, memories, and tool results"
)
else:
print(" Mode :: Clean status enabled")
print(" View :: spinner states only; logs are still saved to logs/ace.log")
print(line("-") + "\n")
def read_multiline_input() -> str:
print("\n" + line("-"))
print(" MULTI-LINE INPUT")
print(line("-"))
print(" Paste or type your request below.")
print(" Type /end on its own line to submit.")
print(" Type /cancel on its own line to cancel.")
print(line("-"))
lines = []
while True:
try:
line_input = input("... ")
except EOFError:
print_exit()
raise SystemExit
command = line_input.strip().lower()
if command == "/end":
break
if command == "/cancel":
print("\nMulti-line input cancelled.\n")
return ""
lines.append(line_input)
return "\n".join(lines).strip()
def handle_command(user_input: str, agent: ACEAgent) -> bool:
"""
Handles CLI commands.
Returns True if the command was handled.
Returns False if the input should be sent to ACE.
"""
command = user_input.lower().strip()
if command in ["/exit", "/quit", "exit", "quit", "q"]:
print_exit()
raise SystemExit
if command == "/help":
print_help()
return True
if command == "/clear":
clear_screen()
print_banner(getattr(agent, "show_logs", False))
return True
if command == "/logs":
print_logs_status(agent)
return True
if command in ["/logs on", "/log on", "/verbose on"]:
set_logs(agent, True)
return True
if command in ["/logs off", "/log off", "/verbose off"]:
set_logs(agent, False)
return True
return False
def main():
agent = ACEAgent()
# Keep the CLI display mode and runtime.logger console output synced.
set_console_logging(getattr(agent, "show_logs", False))
print_banner(getattr(agent, "show_logs", False))
while True:
try:
try:
user_input = input("ace › ").strip()
except EOFError:
print_exit()
break
if not user_input:
continue
if user_input.lower().strip() in ["/paste", "/multiline", "/ml"]:
user_input = read_multiline_input()
if not user_input:
continue
try:
if handle_command(user_input, agent):
continue
except SystemExit:
break
print_processing(getattr(agent, "show_logs", False))
result = agent.run(user_input)
if result:
print_result(result)
except KeyboardInterrupt:
# Ctrl+C
print_exit()
break
except Exception as e:
print_error(e)
if __name__ == "__main__":
main()