-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent_mind.py
More file actions
52 lines (40 loc) · 1.37 KB
/
agent_mind.py
File metadata and controls
52 lines (40 loc) · 1.37 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
class AgentMind:
"""
Adds goal + memory + planning to agents.
"""
def __init__(self):
self.memory = [] # compressed experiences
self.goals = ["survive", "explore"]
self.goal_weights = {
"survive": 1.0,
"explore": 0.5
}
# =====================================================
# MEMORY UPDATE
# =====================================================
def remember(self, perception, action, reward):
self.memory.append({
"perception": perception,
"action": action,
"reward": reward
})
if len(self.memory) > 100:
self.memory.pop(0)
# =====================================================
# GOAL SELECTION
# =====================================================
def select_goal(self):
# simple adaptive weighting
return max(self.goal_weights, key=self.goal_weights.get)
# =====================================================
# ACTION PLANNING (simple heuristic)
# =====================================================
def plan(self, perception):
goal = self.select_goal()
if goal == "survive":
if perception["energy"] < 0.4:
return "move"
return "idle"
if goal == "explore":
return "move"
return "idle"