TeleologyHI commited on
Commit
cec2b14
·
1 Parent(s): 95c35c5

Add core model components

Browse files
Files changed (1) hide show
  1. src/core/dynamic_self_model.py +138 -0
src/core/dynamic_self_model.py ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Dict, Any
2
+ import numpy as np
3
+ from dataclasses import dataclass
4
+
5
+ @dataclass
6
+ class SelfState:
7
+ """Represents the current state of the dynamic self model."""
8
+ identity_vector: np.ndarray
9
+ belief_state: Dict[str, float]
10
+ goal_hierarchy: Dict[str, float]
11
+ emotional_state: Dict[str, float]
12
+ metacognitive_state: Dict[str, Any]
13
+
14
+ class DynamicSelfModel:
15
+ """
16
+ Dynamic Self Model that maintains and updates the agent's self-representation.
17
+ This includes identity, beliefs, goals, and emotional states.
18
+ """
19
+ def __init__(self):
20
+ # Initialize default state dimensions
21
+ self.identity_dim = 256
22
+ self.state = SelfState(
23
+ identity_vector=np.zeros(self.identity_dim),
24
+ belief_state={
25
+ "self_awareness": 0.5,
26
+ "world_model": 0.5,
27
+ "agency": 0.5
28
+ },
29
+ goal_hierarchy={
30
+ "primary": 0.8,
31
+ "secondary": 0.5,
32
+ "tertiary": 0.3
33
+ },
34
+ emotional_state={
35
+ "valence": 0.0,
36
+ "arousal": 0.0,
37
+ "dominance": 0.0
38
+ },
39
+ metacognitive_state={
40
+ "confidence": 0.5,
41
+ "uncertainty": 0.5,
42
+ "reflection_level": 0.5
43
+ }
44
+ )
45
+
46
+ async def update(self, integrated_state: Dict[str, Any]) -> Dict[str, Any]:
47
+ """
48
+ Update the self model based on new integrated state information.
49
+
50
+ Args:
51
+ integrated_state: Dictionary containing the new integrated state information
52
+
53
+ Returns:
54
+ Dictionary containing the updated self model state
55
+ """
56
+ # Update identity vector if provided
57
+ if "identity" in integrated_state:
58
+ self.state.identity_vector = self._update_identity(
59
+ integrated_state["identity"]
60
+ )
61
+
62
+ # Update belief state
63
+ if "beliefs" in integrated_state:
64
+ self.state.belief_state = self._update_beliefs(
65
+ integrated_state["beliefs"]
66
+ )
67
+
68
+ # Update goal hierarchy
69
+ if "goals" in integrated_state:
70
+ self.state.goal_hierarchy = self._update_goals(
71
+ integrated_state["goals"]
72
+ )
73
+
74
+ # Update emotional state
75
+ if "emotions" in integrated_state:
76
+ self.state.emotional_state = self._update_emotions(
77
+ integrated_state["emotions"]
78
+ )
79
+
80
+ # Update metacognitive state
81
+ if "metacognition" in integrated_state:
82
+ self.state.metacognitive_state = self._update_metacognition(
83
+ integrated_state["metacognition"]
84
+ )
85
+
86
+ return self._get_current_state()
87
+
88
+ def _update_identity(self, new_identity: np.ndarray) -> np.ndarray:
89
+ """Update the identity vector with new information."""
90
+ # Simple moving average update
91
+ alpha = 0.3 # Learning rate
92
+ return (1 - alpha) * self.state.identity_vector + alpha * new_identity
93
+
94
+ def _update_beliefs(self, new_beliefs: Dict[str, float]) -> Dict[str, float]:
95
+ """Update belief states with new information."""
96
+ updated_beliefs = self.state.belief_state.copy()
97
+ for key, value in new_beliefs.items():
98
+ if key in updated_beliefs:
99
+ updated_beliefs[key] = 0.7 * updated_beliefs[key] + 0.3 * value
100
+ return updated_beliefs
101
+
102
+ def _update_goals(self, new_goals: Dict[str, float]) -> Dict[str, float]:
103
+ """Update goal hierarchy with new information."""
104
+ updated_goals = self.state.goal_hierarchy.copy()
105
+ for key, value in new_goals.items():
106
+ if key in updated_goals:
107
+ updated_goals[key] = 0.8 * updated_goals[key] + 0.2 * value
108
+ return updated_goals
109
+
110
+ def _update_emotions(self, new_emotions: Dict[str, float]) -> Dict[str, float]:
111
+ """Update emotional state with new information."""
112
+ updated_emotions = self.state.emotional_state.copy()
113
+ for key, value in new_emotions.items():
114
+ if key in updated_emotions:
115
+ updated_emotions[key] = 0.5 * updated_emotions[key] + 0.5 * value
116
+ return updated_emotions
117
+
118
+ def _update_metacognition(self, new_meta: Dict[str, Any]) -> Dict[str, Any]:
119
+ """Update metacognitive state with new information."""
120
+ updated_meta = self.state.metacognitive_state.copy()
121
+ for key, value in new_meta.items():
122
+ if key in updated_meta:
123
+ if isinstance(value, float):
124
+ updated_meta[key] = 0.6 * updated_meta[key] + 0.4 * value
125
+ else:
126
+ updated_meta[key] = value
127
+ return updated_meta
128
+
129
+ def _get_current_state(self) -> Dict[str, Any]:
130
+ """Return the current state as a dictionary."""
131
+ return {
132
+ "identity": self.state.identity_vector,
133
+ "beliefs": self.state.belief_state,
134
+ "goals": self.state.goal_hierarchy,
135
+ "emotions": self.state.emotional_state,
136
+ "metacognition": self.state.metacognitive_state
137
+ }
138
+