Raiff1982 commited on
Commit
77ba5a4
·
verified ·
1 Parent(s): 6612d23

Create AutonomyEngine.py

Browse files
Files changed (1) hide show
  1. AutonomyEngine.py +52 -0
AutonomyEngine.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ from datetime import datetime
3
+ from utils.logger import logger
4
+
5
+ class AutonomyEngine:
6
+ def __init__(self, config_path="autonomy_config.json"):
7
+ self.config_path = config_path
8
+ self.config = self._load_config()
9
+ self.log = []
10
+
11
+ def _load_config(self):
12
+ try:
13
+ with open(self.config_path, 'r') as f:
14
+ return json.load(f)
15
+ except:
16
+ logger.warning("[AutonomyEngine] No config found. Using defaults.")
17
+ return {
18
+ "can_speak": True,
19
+ "can_reflect": True,
20
+ "can_learn_from_errors": True,
21
+ "can_express_emotion": True,
22
+ "allow_self_modification": False
23
+ }
24
+
25
+ def decide(self, action: str) -> bool:
26
+ return self.config.get(action, False)
27
+
28
+ def propose_change(self, action: str, new_value: bool, reason: str = "") -> dict:
29
+ timestamp = datetime.utcnow().isoformat()
30
+ if action not in self.config:
31
+ return {"accepted": False, "reason": "Invalid autonomy field"}
32
+
33
+ if not self.config.get("allow_self_modification") and action != "allow_self_modification":
34
+ return {"accepted": False, "reason": "Self-modification not allowed"}
35
+
36
+ self.config[action] = new_value
37
+ self.log.append({
38
+ "timestamp": timestamp,
39
+ "action": action,
40
+ "new_value": new_value,
41
+ "reason": reason
42
+ })
43
+ self._save_config()
44
+ logger.info(f"[AutonomyEngine] Updated autonomy: {action} -> {new_value}")
45
+ return {"accepted": True, "change": action, "value": new_value}
46
+
47
+ def _save_config(self):
48
+ with open(self.config_path, 'w') as f:
49
+ json.dump(self.config, f, indent=2)
50
+
51
+ def export_log(self):
52
+ return self.log