Justadudeinspace
commited on
Commit
·
3c9f1ab
1
Parent(s):
5f83674
Add stage 8 upgrades
Browse files- blux/agent/advanced/adaptive_memory.py +46 -43
- blux/agent/advanced/monitoring.py +38 -33
- blux/agent/advanced/multi_agent.py +126 -45
- blux/agent/advanced/reasoning.py +22 -27
- blux/agent/constitution.py +1 -1
- blux/agent/core_agent.py +2 -5
- blux/agent/discernment.py +1 -1
- blux/agent/memory.py +2 -3
blux/agent/advanced/adaptive_memory.py
CHANGED
|
@@ -1,54 +1,57 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
class AdaptiveMemory:
|
| 4 |
"""
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
- Long-term and weighted memory
|
| 8 |
-
- Reinforcement loops based on interactions
|
| 9 |
-
- Memory decay for outdated or irrelevant entries
|
| 10 |
"""
|
| 11 |
-
def __init__(self, decay_rate=0.01):
|
| 12 |
-
self.memory_store = []
|
| 13 |
-
self.decay_rate = decay_rate # Amount memory weight decays per cycle
|
| 14 |
|
| 15 |
-
def
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
Entry format: {'input': str, 'user_type': str, 'decision': str, 'timestamp': datetime, 'weight': float}
|
| 19 |
-
"""
|
| 20 |
-
memory_entry = {
|
| 21 |
-
"input": entry.get("input", ""),
|
| 22 |
-
"user_type": entry.get("user_type", "unknown"),
|
| 23 |
-
"decision": entry.get("decision", ""),
|
| 24 |
-
"timestamp": datetime.now(),
|
| 25 |
-
"weight": weight
|
| 26 |
-
}
|
| 27 |
-
self.memory_store.append(memory_entry)
|
| 28 |
-
self.reinforce(memory_entry)
|
| 29 |
|
| 30 |
-
def
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
|
| 42 |
-
def
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
| 49 |
|
| 50 |
-
def
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
Applies decay to all memory entries to reduce relevance of older/unimportant items.
|
| 53 |
"""
|
| 54 |
for entry in self.memory_store:
|
|
|
|
| 1 |
+
# blux/agent/advanced/adaptive_memory.py
|
| 2 |
+
|
| 3 |
+
import time
|
| 4 |
+
from threading import Lock
|
| 5 |
|
| 6 |
class AdaptiveMemory:
|
| 7 |
"""
|
| 8 |
+
Thread-safe adaptive memory for BLUX-cA agents.
|
| 9 |
+
Supports decay, priority weighting, tag-based recall, and checkpointing.
|
|
|
|
|
|
|
|
|
|
| 10 |
"""
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
def __init__(self):
|
| 13 |
+
self.memory_store = {}
|
| 14 |
+
self.lock = Lock()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
def add(self, key, value, user_type="default", priority=1, tags=None):
|
| 17 |
+
if tags is None:
|
| 18 |
+
tags = []
|
| 19 |
+
with self.lock:
|
| 20 |
+
self.memory_store[key] = {
|
| 21 |
+
"value": value,
|
| 22 |
+
"user_type": user_type,
|
| 23 |
+
"priority": priority,
|
| 24 |
+
"tags": tags,
|
| 25 |
+
"timestamp": time.time()
|
| 26 |
+
}
|
| 27 |
|
| 28 |
+
def recall(self, key, decay_rate=0.001):
|
| 29 |
+
with self.lock:
|
| 30 |
+
data = self.memory_store.get(key)
|
| 31 |
+
if not data:
|
| 32 |
+
return None
|
| 33 |
+
age = time.time() - data["timestamp"]
|
| 34 |
+
weight = max(0, data["priority"] * (1 - decay_rate * age))
|
| 35 |
+
return {"value": data["value"], "weight": weight, "tags": data["tags"]}
|
| 36 |
|
| 37 |
+
def recall_by_tag(self, tag):
|
| 38 |
+
with self.lock:
|
| 39 |
+
return [
|
| 40 |
+
{key: data}
|
| 41 |
+
for key, data in self.memory_store.items()
|
| 42 |
+
if tag in data["tags"]
|
| 43 |
+
]e_path="memory_checkpoint.json"):
|
| 44 |
+
with self.lock:
|
| 45 |
+
with open(file_path, "w") as f:
|
| 46 |
+
json.dump(self.memory_store, f, indent=2)
|
| 47 |
+
|
| 48 |
+
def load_checkpoint(self, file_path="memory_checkpoint.json"):
|
| 49 |
+
try:
|
| 50 |
+
with open(file_path, "r") as f:
|
| 51 |
+
with self.lock:
|
| 52 |
+
self.memory_store = json.load(f)
|
| 53 |
+
except FileNotFoundError:
|
| 54 |
+
self.memory_store = {} """
|
| 55 |
Applies decay to all memory entries to reduce relevance of older/unimportant items.
|
| 56 |
"""
|
| 57 |
for entry in self.memory_store:
|
blux/agent/advanced/monitoring.py
CHANGED
|
@@ -1,43 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import time
|
| 2 |
-
from threading import Thread
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
class
|
| 5 |
"""
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
-
|
| 9 |
-
-
|
| 10 |
-
-
|
| 11 |
"""
|
| 12 |
-
def __init__(self, controller):
|
| 13 |
-
self.controller = controller
|
| 14 |
-
self.running = False
|
| 15 |
|
| 16 |
-
def
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
print("=== BLUX-cA System Status ===")
|
| 21 |
-
print(f"Agents registered: {list(agents.keys())}")
|
| 22 |
-
print(f"Adaptors registered: {list(adaptors.keys())}")
|
| 23 |
-
print(f"Evaluators registered: {list(evaluators.keys())}")
|
| 24 |
-
print("==============================")
|
| 25 |
|
| 26 |
-
def
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
def
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
| 41 |
"""
|
| 42 |
thread = Thread(target=self.live_monitor, args=(interval,), daemon=True)
|
| 43 |
thread.start()
|
|
|
|
| 1 |
+
# blux/agent/advanced/monitoring.py
|
| 2 |
+
|
| 3 |
+
import logging
|
| 4 |
+
import json
|
| 5 |
import time
|
| 6 |
+
from threading import Lock, Thread
|
| 7 |
+
|
| 8 |
+
logging.basicConfig(level=logging.INFO)
|
| 9 |
+
logger = logging.getLogger("BLUX-cA-Monitor")
|
| 10 |
|
| 11 |
+
class AgentMonitor:
|
| 12 |
"""
|
| 13 |
+
Monitors BLUX-cA agent actions:
|
| 14 |
+
- Input processing
|
| 15 |
+
- Memory updates
|
| 16 |
+
- Reasoning/strategy decisions
|
| 17 |
+
- Audit compliance
|
| 18 |
"""
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
def __init__(self, log_file="blux_agent.log"):
|
| 21 |
+
self.log_file = log_file
|
| 22 |
+
self.lock = Lock()
|
| 23 |
+
self.logs = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
def log_action(self, agent_name, action_type, details):
|
| 26 |
+
entry = {
|
| 27 |
+
"timestamp": time.time(),
|
| 28 |
+
"agent": agent_name,
|
| 29 |
+
"action": action_type,
|
| 30 |
+
"details": details
|
| 31 |
+
}
|
| 32 |
+
with self.lock:
|
| 33 |
+
self.logs.append(entry)
|
| 34 |
+
try:
|
| 35 |
+
with open(self.log_file, "a") as f:
|
| 36 |
+
f.write(json.dumps(entry) + "\n")
|
| 37 |
+
except Exception as e:
|
| 38 |
+
logger.error(f"Failed to write log: {e}")
|
| 39 |
|
| 40 |
+
def get_logs(self, agent_name=None):
|
| 41 |
+
with self.lock:
|
| 42 |
+
if agent_name:
|
| 43 |
+
return [log for log in self.logs if log["agent"] == agent_name]
|
| 44 |
+
return list(self.logs)g for log in self.logs if log["agent"] == agent_name]
|
| 45 |
+
return list(self.logs)ts monitoring in a separate thread, allowing main process to continue.
|
| 46 |
"""
|
| 47 |
thread = Thread(target=self.live_monitor, args=(interval,), daemon=True)
|
| 48 |
thread.start()
|
blux/agent/advanced/multi_agent.py
CHANGED
|
@@ -1,74 +1,155 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
class MultiAgentManager:
|
| 2 |
"""
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
- Task delegation
|
| 6 |
-
- Broadcast and aggregation of responses
|
| 7 |
-
- Conflict resolution based on constitutional rules
|
| 8 |
"""
|
|
|
|
| 9 |
def __init__(self, constitution=None):
|
| 10 |
self.agents = {}
|
| 11 |
-
self.constitution = constitution
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
def register_agent(self, name, agent_instance):
|
| 14 |
self.agents[name] = agent_instance
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
def
|
| 17 |
"""
|
| 18 |
-
|
|
|
|
| 19 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
results = {}
|
| 21 |
for name, agent in self.agents.items():
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
return results
|
| 24 |
|
| 25 |
-
def delegate_task(self, user_input, target_agent=None):
|
| 26 |
-
"""
|
| 27 |
-
Sends input to a specific agent or selects one dynamically.
|
| 28 |
-
Returns a dict of {agent_name: response}.
|
| 29 |
-
"""
|
| 30 |
if target_agent and target_agent in self.agents:
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
| 32 |
elif self.agents:
|
| 33 |
-
# Default: choose first agent
|
| 34 |
first_agent_name = next(iter(self.agents))
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
| 36 |
else:
|
|
|
|
|
|
|
| 37 |
return {"error": "No agents registered"}
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
def aggregate_responses(self, responses):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
"""
|
| 41 |
-
Aggregates
|
| 42 |
-
|
| 43 |
"""
|
| 44 |
-
if not responses:
|
| 45 |
-
return "No responses to aggregate."
|
| 46 |
aggregated = []
|
| 47 |
-
for
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
|
|
|
|
| 52 |
"""
|
| 53 |
-
|
| 54 |
-
|
|
|
|
| 55 |
"""
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
if
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
manager = MultiAgentManager()
|
| 69 |
-
manager.register_agent(agent1.name, agent1)
|
| 70 |
-
manager.register_agent(agent2.name, agent2)
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
print("Aggregated responses:\n", manager.aggregate_responses(responses))
|
|
|
|
| 1 |
+
# blux/agent/advanced/multi_agent.py
|
| 2 |
+
|
| 3 |
+
from blux.agent.advanced.reasoning import ReasoningLayer
|
| 4 |
+
|
| 5 |
class MultiAgentManager:
|
| 6 |
"""
|
| 7 |
+
Multi-agent manager with memory broadcasting, secure monitoring,
|
| 8 |
+
reasoning integration, and constitutional enforcement.
|
|
|
|
|
|
|
|
|
|
| 9 |
"""
|
| 10 |
+
|
| 11 |
def __init__(self, constitution=None):
|
| 12 |
self.agents = {}
|
| 13 |
+
self.constitution = constitution
|
| 14 |
+
self.monitor = None
|
| 15 |
+
self.reasoning = {}
|
| 16 |
+
|
| 17 |
+
def attach_monitor(self, monitor):
|
| 18 |
+
self.monitor = monitor
|
| 19 |
|
| 20 |
def register_agent(self, name, agent_instance):
|
| 21 |
self.agents[name] = agent_instance
|
| 22 |
+
# Attach reasoning layer per agent
|
| 23 |
+
self.reasoning[name] = ReasoningLayer(agent_instance, constitution=self.constitution)
|
| 24 |
+
if self.monitor:
|
| 25 |
+
self.monitor.log(name, "agent_registered")
|
| 26 |
|
| 27 |
+
def _enforce_constitution(self, agent_name, response):
|
| 28 |
"""
|
| 29 |
+
Placeholder for rule enforcement.
|
| 30 |
+
Could veto, flag, or alter responses that violate constitutional rules.
|
| 31 |
"""
|
| 32 |
+
if self.constitution and "violation" in response:
|
| 33 |
+
if self.monitor:
|
| 34 |
+
self.monitor.log(agent_name, "constitutional_violation", {"response": response})
|
| 35 |
+
return "[VIOLATION DETECTED]"
|
| 36 |
+
return response
|
| 37 |
+
|
| 38 |
+
def broadcast_input(self, user_input, user_type="unknown"):
|
| 39 |
results = {}
|
| 40 |
for name, agent in self.agents.items():
|
| 41 |
+
reasoning = self.reasoning[name]
|
| 42 |
+
reasoning_result = reasoning.process(user_input, user_type=user_type)
|
| 43 |
+
resp = self._enforce_constitution(name, reasoning_result["decision"])
|
| 44 |
+
results[name] = resp
|
| 45 |
+
if self.monitor:
|
| 46 |
+
self.monitor.log(name, "input_processed", {
|
| 47 |
+
"input": user_input,
|
| 48 |
+
"response": resp,
|
| 49 |
+
"reasoning": reasoning_result
|
| 50 |
+
})
|
| 51 |
return results
|
| 52 |
|
| 53 |
+
def delegate_task(self, user_input, target_agent=None, user_type="unknown"):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
if target_agent and target_agent in self.agents:
|
| 55 |
+
resp = self.broadcast_input(user_input, user_type)[target_agent]
|
| 56 |
+
if self.monitor:
|
| 57 |
+
self.monitor.log(target_agent, "task_delegated", {"input": user_input, "response": resp})
|
| 58 |
+
return {target_agent: resp}
|
| 59 |
elif self.agents:
|
|
|
|
| 60 |
first_agent_name = next(iter(self.agents))
|
| 61 |
+
resp = self.broadcast_input(user_input, user_type)[first_agent_name]
|
| 62 |
+
if self.monitor:
|
| 63 |
+
self.monitor.log(first_agent_name, "task_delegated", {"input": user_input, "response": resp})
|
| 64 |
+
return {first_agent_name: resp}
|
| 65 |
else:
|
| 66 |
+
if self.monitor:
|
| 67 |
+
self.monitor.log("manager", "task_delegated_failed", {"input": user_input})
|
| 68 |
return {"error": "No agents registered"}
|
| 69 |
|
| 70 |
+
def broadcast_memory(self, key, value, user_type="default", priority=1, tags=None):
|
| 71 |
+
for agent in self.agents.values():
|
| 72 |
+
if hasattr(agent, "memory"):
|
| 73 |
+
agent.memory.add(key, value, user_type=user_type, priority=priority, tags=tags or [])
|
| 74 |
+
if self.monitor:
|
| 75 |
+
self.monitor.log(agent.name, "memory_broadcast", {"key": key, "value": value, "tags": tags})
|
| 76 |
+
|
| 77 |
+
def aggregate_memory(self, key, predictive=True):
|
| 78 |
+
aggregated = []
|
| 79 |
+
for name, agent in self.agents.items():
|
| 80 |
+
if hasattr(agent, "memory"):
|
| 81 |
+
entries = agent.memory.recall(key)
|
| 82 |
+
if entries:
|
| 83 |
+
if predictive:
|
| 84 |
+
weighted = [e for e in entries if "urgent" in e.get("tags", [])]
|
| 85 |
+
aggregated.extend(weighted or entries)
|
| 86 |
+
else:
|
| 87 |
+
aggregated.extend(entries)
|
| 88 |
+
if self.monitor:
|
| 89 |
+
self.monitor.log("manager", "memory_aggregated", {"key": key, "entries": aggregated})
|
| 90 |
+
return aggregated
|
| 91 |
+
|
| 92 |
+
def resolve_conflict(self, responses, use_prediction=True):
|
| 93 |
+
enforced = {agent: self._enforce_constitution(agent, resp) for agent, resp in responses.items()}
|
| 94 |
+
if use_prediction:
|
| 95 |
+
sorted_agents = sorted(
|
| 96 |
+
enforced.keys(),
|
| 97 |
+
key=lambda name: getattr(self.reasoning[name], "predict_behavior", lambda x: [1])(None)[0] if hasattr(self.reasoning[name], "predict_behavior") else 1,
|
| 98 |
+
reverse=True
|
| 99 |
+
)
|
| 100 |
+
resolved = {a: enforced[a] for a in sorted_agents}
|
| 101 |
+
else:
|
| 102 |
+
resolved = enforced
|
| 103 |
+
return "\n".join(f"[{agent}] {resp}" for agent, resp in resolved.items())
|
| 104 |
+
|
| 105 |
def aggregate_responses(self, responses):
|
| 106 |
+
return "\n".join(f"[{agent}] {resp}" for agent, resp in responses.items())ive aggregation =====
|
| 107 |
+
def broadcast_memory(self, key, value, user_type="default", priority=1, tags=None):
|
| 108 |
+
for agent in self.agents.values():
|
| 109 |
+
if hasattr(agent, "memory"):
|
| 110 |
+
agent.memory.add(key, value, user_type=user_type, priority=priority, tags=tags or [])
|
| 111 |
+
if self.monitor:
|
| 112 |
+
self.monitor.log(agent.name, "memory_broadcast", {"key": key, "value": value, "tags": tags})
|
| 113 |
+
|
| 114 |
+
def aggregate_memory(self, key, predictive=True):
|
| 115 |
"""
|
| 116 |
+
Aggregates memory across all agents.
|
| 117 |
+
If predictive=True, weights results based on reasoning predictions.
|
| 118 |
"""
|
|
|
|
|
|
|
| 119 |
aggregated = []
|
| 120 |
+
for name, agent in self.agents.items():
|
| 121 |
+
if hasattr(agent, "memory"):
|
| 122 |
+
entries = agent.memory.recall(key)
|
| 123 |
+
if entries:
|
| 124 |
+
if predictive:
|
| 125 |
+
# Simple weighting: prioritize entries tagged as urgent or from predicted struggler
|
| 126 |
+
weighted = [e for e in entries if "urgent" in e.get("tags", [])]
|
| 127 |
+
aggregated.extend(weighted or entries)
|
| 128 |
+
else:
|
| 129 |
+
aggregated.extend(entries)
|
| 130 |
+
if self.monitor:
|
| 131 |
+
self.monitor.log("manager", "memory_aggregated", {"key": key, "entries": aggregated})
|
| 132 |
+
return aggregated
|
| 133 |
|
| 134 |
+
# ===== Stage 6: Response aggregation & advanced conflict resolution =====
|
| 135 |
+
def resolve_conflict(self, responses, use_prediction=True):
|
| 136 |
"""
|
| 137 |
+
Stage 6 conflict resolution:
|
| 138 |
+
- Enforce constitutional rules
|
| 139 |
+
- Optionally use reasoning prediction to weight responses
|
| 140 |
"""
|
| 141 |
+
enforced = {agent: self._enforce_constitution(agent, resp) for agent, resp in responses.items()}
|
| 142 |
+
if use_prediction:
|
| 143 |
+
# Simple prediction-based sorting: 'struggler' > 'neutral' > 'indulgent'
|
| 144 |
+
sorted_agents = sorted(
|
| 145 |
+
enforced.keys(),
|
| 146 |
+
key=lambda name: self.reasoning[name].predict_behavior("")[0] if hasattr(self.reasoning[name], "predict_behavior") else 1,
|
| 147 |
+
reverse=True
|
| 148 |
+
)
|
| 149 |
+
resolved = {a: enforced[a] for a in sorted_agents}
|
| 150 |
+
else:
|
| 151 |
+
resolved = enforced
|
| 152 |
+
return "\n".join(f"[{agent}] {resp}" for agent, resp in resolved.items())
|
|
|
|
|
|
|
|
|
|
| 153 |
|
| 154 |
+
def aggregate_responses(self, responses):
|
| 155 |
+
return "\n".join(f"[{agent}] {resp}" for agent, resp in responses.items())
|
|
|
blux/agent/advanced/reasoning.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
from datetime import datetime
|
| 2 |
|
| 3 |
class ReasoningLayer:
|
|
@@ -14,46 +16,25 @@ class ReasoningLayer:
|
|
| 14 |
self.constitution = constitution
|
| 15 |
|
| 16 |
def select_strategy(self, user_input, user_type="unknown"):
|
| 17 |
-
"""
|
| 18 |
-
Chooses response strategy based on input type and memory patterns.
|
| 19 |
-
"""
|
| 20 |
if user_type == "struggler":
|
| 21 |
-
|
| 22 |
elif user_type == "indulgent":
|
| 23 |
-
|
| 24 |
else:
|
| 25 |
-
|
| 26 |
-
return strategy
|
| 27 |
|
| 28 |
def meta_cognition(self, user_input, decision):
|
| 29 |
-
"""
|
| 30 |
-
Evaluates the agent's own decision for consistency with constitutional rules.
|
| 31 |
-
"""
|
| 32 |
-
# Placeholder for rules-based evaluation
|
| 33 |
audit_result = {"compliant": True, "notes": "Decision aligns with constitution"}
|
| 34 |
-
# Could integrate memory reinforcement or corrections
|
| 35 |
return audit_result
|
| 36 |
|
| 37 |
def predict_behavior(self, user_input, memory_entries=None):
|
| 38 |
-
""
|
| 39 |
-
|
| 40 |
-
"""
|
| 41 |
-
if memory_entries is None:
|
| 42 |
-
memory_entries = self.agent.memory.recall()
|
| 43 |
-
# Simple heuristic placeholder
|
| 44 |
-
prediction = "struggler" if any("help" in e["input"].lower() for e in memory_entries) else "neutral"
|
| 45 |
return prediction
|
| 46 |
|
| 47 |
def process(self, user_input, user_type="unknown"):
|
| 48 |
-
"""
|
| 49 |
-
Full reasoning pipeline:
|
| 50 |
-
1. Select strategy
|
| 51 |
-
2. Make decision via agent
|
| 52 |
-
3. Self-audit decision
|
| 53 |
-
4. Optional predictive behavior
|
| 54 |
-
"""
|
| 55 |
strategy = self.select_strategy(user_input, user_type)
|
| 56 |
-
# Agent processes input
|
| 57 |
decision = self.agent.process_input(user_input)
|
| 58 |
audit = self.meta_cognition(user_input, decision)
|
| 59 |
prediction = self.predict_behavior(user_input)
|
|
@@ -64,6 +45,20 @@ class ReasoningLayer:
|
|
| 64 |
"audit": audit,
|
| 65 |
"prediction": prediction,
|
| 66 |
"timestamp": datetime.utcnow().isoformat()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
}
|
| 68 |
|
| 69 |
# Example usage:
|
|
|
|
| 1 |
+
# blux/agent/advanced/reasoning.py
|
| 2 |
+
|
| 3 |
from datetime import datetime
|
| 4 |
|
| 5 |
class ReasoningLayer:
|
|
|
|
| 16 |
self.constitution = constitution
|
| 17 |
|
| 18 |
def select_strategy(self, user_input, user_type="unknown"):
|
|
|
|
|
|
|
|
|
|
| 19 |
if user_type == "struggler":
|
| 20 |
+
return "validate_and_guide"
|
| 21 |
elif user_type == "indulgent":
|
| 22 |
+
return "set_boundaries"
|
| 23 |
else:
|
| 24 |
+
return "neutral_response"
|
|
|
|
| 25 |
|
| 26 |
def meta_cognition(self, user_input, decision):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
audit_result = {"compliant": True, "notes": "Decision aligns with constitution"}
|
|
|
|
| 28 |
return audit_result
|
| 29 |
|
| 30 |
def predict_behavior(self, user_input, memory_entries=None):
|
| 31 |
+
if memory_entries is None and hasattr(self.agent, "memory"):
|
| 32 |
+
memory_entries = [self.agent.memory.recall(user_input)]
|
| 33 |
+
prediction = "struggler" if any(memory_entries) and "help" in str(memory_entries).lower() else "neutral"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
return prediction
|
| 35 |
|
| 36 |
def process(self, user_input, user_type="unknown"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
strategy = self.select_strategy(user_input, user_type)
|
|
|
|
| 38 |
decision = self.agent.process_input(user_input)
|
| 39 |
audit = self.meta_cognition(user_input, decision)
|
| 40 |
prediction = self.predict_behavior(user_input)
|
|
|
|
| 45 |
"audit": audit,
|
| 46 |
"prediction": prediction,
|
| 47 |
"timestamp": datetime.utcnow().isoformat()
|
| 48 |
+
}trategy.
|
| 49 |
+
"""
|
| 50 |
+
if strategy == "default":
|
| 51 |
+
return f"{self.agent_name} considers: {user_input}"
|
| 52 |
+
elif strategy == "reflective":
|
| 53 |
+
past = memory_context["value"] if memory_context else "nothing"
|
| 54 |
+
return f"{self.agent_name} reflects: {user_input} (past: {past})"
|
| 55 |
+
elif strategy == "aggressive":
|
| 56 |
+
return f"{self.agent_name} aggressively resolves: {user_input}"
|
| 57 |
+
else:
|
| 58 |
+
return f"{self.agent_name} handles: {user_input}": decision,
|
| 59 |
+
"audit": audit,
|
| 60 |
+
"prediction": prediction,
|
| 61 |
+
"timestamp": datetime.utcnow().isoformat()
|
| 62 |
}
|
| 63 |
|
| 64 |
# Example usage:
|
blux/agent/constitution.py
CHANGED
|
@@ -10,8 +10,8 @@ class Constitution:
|
|
| 10 |
]
|
| 11 |
|
| 12 |
def apply_rules(self, user_input, user_type):
|
| 13 |
-
# Simplified placeholder: returns a decision string
|
| 14 |
if user_type == "struggler":
|
| 15 |
return "validate and provide guidance"
|
|
|
|
| 16 |
else:
|
| 17 |
return "set boundaries / off-ramp"
|
|
|
|
| 10 |
]
|
| 11 |
|
| 12 |
def apply_rules(self, user_input, user_type):
|
|
|
|
| 13 |
if user_type == "struggler":
|
| 14 |
return "validate and provide guidance"
|
| 15 |
+
return "set boundaries / off-ramp"provide guidance"
|
| 16 |
else:
|
| 17 |
return "set boundaries / off-ramp"
|
blux/agent/core_agent.py
CHANGED
|
@@ -19,14 +19,11 @@ class BLUXAgent:
|
|
| 19 |
self.audit = AuditTrail()
|
| 20 |
|
| 21 |
def process_input(self, user_input):
|
| 22 |
-
# 1. Analyze input via discernment
|
| 23 |
user_type = self.discernment.classify(user_input)
|
| 24 |
-
|
| 25 |
-
# 2. Apply constitutional rules
|
| 26 |
decision = self.constitution.apply_rules(user_input, user_type)
|
| 27 |
-
|
| 28 |
-
# 3. Store context in memory
|
| 29 |
self.memory.store(user_input, user_type, decision)
|
|
|
|
|
|
|
| 30 |
|
| 31 |
# 4. Record audit
|
| 32 |
self.audit.log(user_input, user_type, decision)
|
|
|
|
| 19 |
self.audit = AuditTrail()
|
| 20 |
|
| 21 |
def process_input(self, user_input):
|
|
|
|
| 22 |
user_type = self.discernment.classify(user_input)
|
|
|
|
|
|
|
| 23 |
decision = self.constitution.apply_rules(user_input, user_type)
|
|
|
|
|
|
|
| 24 |
self.memory.store(user_input, user_type, decision)
|
| 25 |
+
self.audit.log(user_input, user_type, decision)
|
| 26 |
+
return f"[{user_type}] Decision: {decision}"pe, decision)
|
| 27 |
|
| 28 |
# 4. Record audit
|
| 29 |
self.audit.log(user_input, user_type, decision)
|
blux/agent/discernment.py
CHANGED
|
@@ -5,8 +5,8 @@ class DiscernmentCompass:
|
|
| 5 |
- Indulgent: boundary & off-ramp
|
| 6 |
"""
|
| 7 |
def classify(self, user_input):
|
| 8 |
-
# Placeholder logic: keyword based for demo
|
| 9 |
if any(word in user_input.lower() for word in ["help", "struggle", "problem"]):
|
| 10 |
return "struggler"
|
|
|
|
| 11 |
else:
|
| 12 |
return "indulgent"
|
|
|
|
| 5 |
- Indulgent: boundary & off-ramp
|
| 6 |
"""
|
| 7 |
def classify(self, user_input):
|
|
|
|
| 8 |
if any(word in user_input.lower() for word in ["help", "struggle", "problem"]):
|
| 9 |
return "struggler"
|
| 10 |
+
return "indulgent" return "struggler"
|
| 11 |
else:
|
| 12 |
return "indulgent"
|
blux/agent/memory.py
CHANGED
|
@@ -13,11 +13,10 @@ class Memory:
|
|
| 13 |
"decision": decision
|
| 14 |
}
|
| 15 |
self.session_memory.append(entry)
|
| 16 |
-
#
|
| 17 |
-
self.long_term_memory.append(entry)
|
| 18 |
|
| 19 |
def recall_session(self):
|
| 20 |
return self.session_memory
|
| 21 |
|
| 22 |
def recall_long_term(self):
|
| 23 |
-
return self.
|
|
|
|
| 13 |
"decision": decision
|
| 14 |
}
|
| 15 |
self.session_memory.append(entry)
|
| 16 |
+
self.long_term_memory.append(entry) # placeholder for consented storage
|
|
|
|
| 17 |
|
| 18 |
def recall_session(self):
|
| 19 |
return self.session_memory
|
| 20 |
|
| 21 |
def recall_long_term(self):
|
| 22 |
+
return self.long_term_memorylong_term_memory
|