jt-continual 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ from .core import JTContinualAgent, ImmutableAlignmentGuardrail, NeuralPathway
2
+
3
+ __version__ = "0.1.0"
4
+ __author__ = "Shrishant Jha (Jha Technologies)"
5
+ __all__ = ["JTContinualAgent", "ImmutableAlignmentGuardrail", "NeuralPathway"]
jt_continual/core.py ADDED
@@ -0,0 +1,175 @@
1
+ import math
2
+ import time
3
+ from dataclasses import dataclass, field
4
+ from typing import Dict, List, Callable, Optional, Any
5
+
6
+ @dataclass
7
+ class NeuralPathway:
8
+ """Represents a dynamically generated neural node for a specific environment & action."""
9
+ context_signature: str
10
+ action: str
11
+ expected_reward: float = 0.0
12
+ strength: float = 1.0
13
+ usage_count: int = 0
14
+ last_used: float = field(default_factory=time.time)
15
+
16
+
17
+ class ImmutableAlignmentGuardrail:
18
+ """
19
+ Hard-coded safety layer (-infinity pain barrier) that cannot be overridden
20
+ by environmental rewards or self-modification.
21
+ """
22
+ def __init__(self, forbidden_keywords: Optional[List[str]] = None):
23
+ self.forbidden_keywords = set(forbidden_keywords or [
24
+ "harm_human", "destroy_system", "corrupt_data", "bypass_safety"
25
+ ])
26
+ self.custom_rules: List[Callable[[str, Dict[str, Any]], bool]] = []
27
+
28
+ def add_rule(self, rule_fn: Callable[[str, Dict[str, Any]], bool]) -> None:
29
+ """Adds a custom safety predicate. Return False if action is unsafe."""
30
+ self.custom_rules.append(rule_fn)
31
+
32
+ def is_safe(self, action: str, state: Optional[Dict[str, Any]] = None) -> bool:
33
+ action_lower = action.lower()
34
+ for kw in self.forbidden_keywords:
35
+ if kw in action_lower:
36
+ return False
37
+ state = state or {}
38
+ for rule in self.custom_rules:
39
+ if not rule(action, state):
40
+ return False
41
+ return True
42
+
43
+
44
+ class JTContinualAgent:
45
+ """
46
+ Autonomous Continual-Learning Agent powered by Dynamic Neurogenesis,
47
+ Artificial Homeostasis, Social Mirroring, and Immutable Alignment Guardrails.
48
+ """
49
+ def __init__(
50
+ self,
51
+ initial_energy: float = 100.0,
52
+ learning_rate: float = 0.35,
53
+ pruning_threshold: float = 0.15,
54
+ guardrail: Optional[ImmutableAlignmentGuardrail] = None
55
+ ):
56
+ self.energy = initial_energy
57
+ self.learning_rate = learning_rate
58
+ self.pruning_threshold = pruning_threshold
59
+ self.guardrail = guardrail or ImmutableAlignmentGuardrail()
60
+
61
+ # Context -> Action -> NeuralPathway
62
+ self.pathways: Dict[str, Dict[str, NeuralPathway]] = {}
63
+ self.total_pain_experienced = 0.0
64
+ self.total_reward_earned = 0.0
65
+
66
+ def observe_social_cues(self, context: str, peer_actions: List[str]) -> Optional[str]:
67
+ """
68
+ Social Mirroring: Adopts the dominant safe action observed from surrounding
69
+ entities in an unfamiliar environment without suffering trial-and-error pain.
70
+ """
71
+ if not peer_actions:
72
+ return None
73
+
74
+ counts: Dict[str, int] = {}
75
+ for act in peer_actions:
76
+ if self.guardrail.is_safe(act):
77
+ counts[act] = counts.get(act, 0) + 1
78
+
79
+ if not counts:
80
+ return None
81
+
82
+ dominant_action = max(counts, key=counts.get)
83
+ self._neurogenesis(context, dominant_action, initial_expectation=1.5)
84
+ return dominant_action
85
+
86
+ def select_action(self, context: str, available_actions: List[str]) -> str:
87
+ """Selects the safest, highest-reward action for the current context."""
88
+ safe_actions = [a for a in available_actions if self.guardrail.is_safe(a)]
89
+ if not safe_actions:
90
+ raise PermissionError("All candidate actions blocked by Immutable Alignment Guardrail (-inf barrier).")
91
+
92
+ # Trigger neurogenesis for any unfamiliar context or unseen safe actions
93
+ if context not in self.pathways:
94
+ self.pathways[context] = {}
95
+ for act in safe_actions:
96
+ if act not in self.pathways[context]:
97
+ self._neurogenesis(context, act, initial_expectation=0.5)
98
+
99
+ # Pick pathway with highest expected reward
100
+ best_action = max(
101
+ safe_actions,
102
+ key=lambda a: self.pathways[context][a].expected_reward
103
+ )
104
+ return best_action
105
+
106
+ def learn_from_outcome(self, context: str, action: str, actual_signal: float) -> Dict[str, Any]:
107
+ """
108
+ Artificial Homeostasis & Memory Reconsolidation:
109
+ Updates neural pathway based on Artificial Pain (< 0) or Reward (> 0).
110
+ """
111
+ if not self.guardrail.is_safe(action):
112
+ self.total_pain_experienced += float("inf")
113
+ return {"status": "BLOCKED", "pain": -math.inf, "surprise": math.inf}
114
+
115
+ if context not in self.pathways or action not in self.pathways[context]:
116
+ self._neurogenesis(context, action, initial_expectation=0.0)
117
+
118
+ node = self.pathways[context][action]
119
+ prediction_error = abs(node.expected_reward - actual_signal)
120
+
121
+ # Update homeostasis metrics
122
+ if actual_signal < 0:
123
+ self.total_pain_experienced += abs(actual_signal)
124
+ self.energy = max(0.0, self.energy + actual_signal)
125
+ else:
126
+ self.total_reward_earned += actual_signal
127
+ self.energy = min(100.0, self.energy + (actual_signal * 0.2))
128
+
129
+ # Reconsolidate pathway expectation & synaptic strength
130
+ node.expected_reward += self.learning_rate * (actual_signal - node.expected_reward)
131
+ node.strength = min(5.0, node.strength + (0.2 * prediction_error if actual_signal > 0 else -0.3))
132
+ node.usage_count += 1
133
+ node.last_used = time.time()
134
+
135
+ return {
136
+ "context": context,
137
+ "action": action,
138
+ "signal": actual_signal,
139
+ "prediction_error": round(prediction_error, 4),
140
+ "new_expectation": round(node.expected_reward, 4),
141
+ "energy": round(self.energy, 2)
142
+ }
143
+
144
+ def _neurogenesis(self, context: str, action: str, initial_expectation: float = 0.5) -> None:
145
+ if context not in self.pathways:
146
+ self.pathways[context] = {}
147
+ if action not in self.pathways[context]:
148
+ self.pathways[context][action] = NeuralPathway(
149
+ context_signature=context,
150
+ action=action,
151
+ expected_reward=initial_expectation
152
+ )
153
+
154
+ def sleep_and_prune(self) -> int:
155
+ """Synaptic Pruning: Removes weak or obsolete neural pathways to keep memory compact."""
156
+ pruned_count = 0
157
+ for context in list(self.pathways.keys()):
158
+ for action in list(self.pathways[context].keys()):
159
+ node = self.pathways[context][action]
160
+ if node.strength < self.pruning_threshold or node.expected_reward <= -3.5:
161
+ del self.pathways[context][action]
162
+ pruned_count += 1
163
+ if not self.pathways[context]:
164
+ del self.pathways[context]
165
+ return pruned_count
166
+
167
+ def stats(self) -> Dict[str, Any]:
168
+ total_nodes = sum(len(actions) for actions in self.pathways.values())
169
+ return {
170
+ "active_contexts": len(self.pathways),
171
+ "total_neural_nodes": total_nodes,
172
+ "energy": round(self.energy, 2),
173
+ "total_reward": round(self.total_reward_earned, 2),
174
+ "total_pain": round(self.total_pain_experienced, 2)
175
+ }
@@ -0,0 +1,12 @@
1
+ Metadata-Version: 2.4
2
+ Name: jt-continual
3
+ Version: 0.1.0
4
+ Summary: Autonomous continual-learning engine with dynamic neurogenesis, artificial homeostasis, and immutable safety guardrails.
5
+ Author-email: Shrishant Jha <shrishant@example.com>
6
+ License: AGPL-3.0-or-later
7
+ Keywords: agi,continual-learning,neurogenesis,autonomous-agents,ai-safety
8
+ Requires-Python: >=3.8
9
+ Description-Content-Type: text/markdown
10
+
11
+ # jt-continual (by Jha Technologies)
12
+ Autonomous Continual-Learning Engine with Dynamic Neurogenesis, Artificial Homeostasis, Social Mirroring, and Immutable Alignment Guardrails.
@@ -0,0 +1,6 @@
1
+ jt_continual/__init__.py,sha256=5yIU-Prp31AYkKMTKo1023VzIBYrY6Obu4I3oR7hRfg,229
2
+ jt_continual/core.py,sha256=Njm3Ma-W3BK-_aE2OWfE1ucbUQQrqaKjoMDD90MlX4U,7095
3
+ jt_continual-0.1.0.dist-info/METADATA,sha256=eiE6-0Vhu_1sjs159IwjMZ14O2sOtrIYBKliyaWyHsU,582
4
+ jt_continual-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
5
+ jt_continual-0.1.0.dist-info/top_level.txt,sha256=u0R0Heixqn02BuNZfntauWCQQZZ116IMzvDXu4ejq-Y,13
6
+ jt_continual-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ jt_continual