-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinteractive_agent.py
More file actions
200 lines (162 loc) Β· 5.94 KB
/
Copy pathinteractive_agent.py
File metadata and controls
200 lines (162 loc) Β· 5.94 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
#!/usr/bin/env python3
"""
Interactive Agent - Interactive goal selection and execution
"""
import sys
from agent_core import AgentCore
def show_goal_menu():
"""Display available goals menu"""
print("π€ Interactive Autonomous Agent")
print("=" * 40)
print("Select a goal:")
print()
print("1. Optimize battery life")
print("2. Enhance security settings")
print("3. Improve accessibility")
print("4. Configure display settings")
print("5. Calculator automation")
print("6. Custom goal")
print("7. Exit")
print()
def get_goal_choice():
"""Get user's goal choice"""
while True:
try:
choice = input("Enter your choice (1-7): ").strip()
if choice in ['1', '2', '3', '4', '5', '6', '7']:
return choice
else:
print("β Invalid choice. Please enter 1-7.")
except KeyboardInterrupt:
print("\nπ Goodbye!")
sys.exit(0)
def get_goal_details(choice):
"""Get goal details based on choice"""
goals = {
'1': {
'goal': 'optimize battery life',
'target_app': 'System Settings',
'description': 'Enable Low Power Mode, reduce screen brightness, close background apps'
},
'2': {
'goal': 'enhance security settings',
'target_app': 'System Settings',
'description': 'Enable FileVault, configure firewall, set up Touch ID'
},
'3': {
'goal': 'improve accessibility',
'target_app': 'System Settings',
'description': 'Configure VoiceOver, Zoom, High Contrast, and other accessibility features'
},
'4': {
'goal': 'configure display settings',
'target_app': 'System Settings',
'description': 'Adjust brightness, resolution, color profiles, and display preferences'
},
'5': {
'goal': 'calculate 1+2',
'target_app': 'Calculator',
'description': 'Automate calculator operations'
},
'6': {
'goal': None, # Will be prompted
'target_app': None, # Will be prompted
'description': 'Custom goal and target application'
}
}
return goals.get(choice, {})
def get_custom_goal():
"""Get custom goal from user"""
print("\nπ Custom Goal Configuration")
print("-" * 30)
goal = input("Enter your goal: ").strip()
if not goal:
print("β Goal cannot be empty")
return None, None
target_app = input("Enter target application (default: System Settings): ").strip()
if not target_app:
target_app = "System Settings"
return goal, target_app
def get_execution_options():
"""Get execution options from user"""
print("\nβοΈ Execution Options")
print("-" * 20)
try:
max_iterations = input("Max iterations (default: 10): ").strip()
max_iterations = int(max_iterations) if max_iterations else 10
max_errors = input("Max errors (default: 5): ").strip()
max_errors = int(max_errors) if max_errors else 5
verbose = input("Verbose output? (y/N): ").strip().lower() == 'y'
return max_iterations, max_errors, verbose
except ValueError:
print("β Invalid number, using defaults")
return 10, 5, False
def run_agent(goal, target_app, max_iterations=10, max_errors=5, verbose=False):
"""Run the agent with specified parameters"""
print(f"\nπ Starting Agent")
print(f"Goal: {goal}")
print(f"Target App: {target_app}")
print(f"Max Iterations: {max_iterations}")
print(f"Max Errors: {max_errors}")
print("=" * 50)
try:
agent = AgentCore()
agent.max_iterations = max_iterations
agent.max_errors = max_errors
result = agent.run_autonomous_loop(
goal=goal,
target_app=target_app,
max_iterations=max_iterations
)
print(f"\nπ Agent Finished")
print(f"Success: {result['success']}")
print(f"Iterations: {result['iterations']}")
print(f"Errors: {result['errors']}")
print(f"Progress: {result['progress']:.2f}")
return result
except KeyboardInterrupt:
print("\nβΉοΈ Agent stopped by user")
return None
except Exception as e:
print(f"\nβ Agent failed: {e}")
if verbose:
import traceback
traceback.print_exc()
return None
def main():
"""Main interactive loop"""
print("π€ Welcome to the Interactive Autonomous Agent!")
print("This agent can help you automate various tasks on macOS.")
print()
while True:
show_goal_menu()
choice = get_goal_choice()
if choice == '7':
print("π Goodbye!")
break
# Get goal details
goal_info = get_goal_details(choice)
if choice == '6': # Custom goal
goal, target_app = get_custom_goal()
if goal is None:
continue
else:
goal = goal_info['goal']
target_app = goal_info['target_app']
print(f"\nπ Selected: {goal_info['description']}")
# Confirm execution
confirm = input(f"\nExecute '{goal}' on '{target_app}'? (Y/n): ").strip().lower()
if confirm == 'n':
continue
# Get execution options
max_iterations, max_errors, verbose = get_execution_options()
# Run agent
result = run_agent(goal, target_app, max_iterations, max_errors, verbose)
if result:
# Ask if user wants to run another goal
another = input("\nRun another goal? (Y/n): ").strip().lower()
if another == 'n':
print("π Goodbye!")
break
if __name__ == "__main__":
main()