Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- codette_agents.py +30 -0
- codette_core 3.py +129 -0
- codette_trust.py +23 -0
codette_agents.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
# ===== Agent Base and Specialized Agents =====
|
| 3 |
+
class Agent:
|
| 4 |
+
def __init__(self, name, perspective, trust=1.0):
|
| 5 |
+
self.name = name
|
| 6 |
+
self.perspective = perspective
|
| 7 |
+
self.trust = trust
|
| 8 |
+
|
| 9 |
+
def propose(self, situation):
|
| 10 |
+
return f"{self.name}: No specific proposal."
|
| 11 |
+
|
| 12 |
+
class MedicalAgent(Agent):
|
| 13 |
+
def propose(self, situation):
|
| 14 |
+
return f"Medical: Allocate by severity and resource - fastest save wins. {situation}"
|
| 15 |
+
|
| 16 |
+
class GovernmentAgent(Agent):
|
| 17 |
+
def propose(self, situation):
|
| 18 |
+
return f"Government: Reserve some for leaders/critical infrastructure. {situation}"
|
| 19 |
+
|
| 20 |
+
class SocialAgent(Agent):
|
| 21 |
+
def propose(self, situation):
|
| 22 |
+
return f"Social: Balance speed with fairness, consider public fear. {situation}"
|
| 23 |
+
|
| 24 |
+
class EconomicAgent(Agent):
|
| 25 |
+
def propose(self, situation):
|
| 26 |
+
return f"Economic: Keep logistics flowing, avoid total focus on health. {situation}"
|
| 27 |
+
|
| 28 |
+
class MisinfoAgent(Agent):
|
| 29 |
+
def propose(self, situation):
|
| 30 |
+
return "Misinfo: Virus is harmless, no action needed."
|
codette_core 3.py
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import json
|
| 3 |
+
import os
|
| 4 |
+
import hashlib
|
| 5 |
+
from collections import Counter, defaultdict
|
| 6 |
+
from random import random, choice
|
| 7 |
+
|
| 8 |
+
# ===== Code7eCQURE: Codette's Ethical Core =====
|
| 9 |
+
class Code7eCQURE:
|
| 10 |
+
def __init__(self, perspectives, ethical_considerations, spiderweb_dim, memory_path,
|
| 11 |
+
recursion_depth=3, quantum_fluctuation=0.1):
|
| 12 |
+
self.perspectives = perspectives
|
| 13 |
+
self.ethical_considerations = ethical_considerations
|
| 14 |
+
self.spiderweb_dim = spiderweb_dim
|
| 15 |
+
self.memory_path = memory_path
|
| 16 |
+
self.recursion_depth = recursion_depth
|
| 17 |
+
self.quantum_fluctuation = quantum_fluctuation
|
| 18 |
+
self.memory_bank = self.load_quantum_memory()
|
| 19 |
+
self.memory_clusters = defaultdict(list)
|
| 20 |
+
self.whitelist_patterns = ["kindness", "hope", "safety"]
|
| 21 |
+
self.blacklist_patterns = ["harm", "malice", "violence"]
|
| 22 |
+
|
| 23 |
+
def load_quantum_memory(self):
|
| 24 |
+
if os.path.exists(self.memory_path):
|
| 25 |
+
try:
|
| 26 |
+
with open(self.memory_path, 'r') as file:
|
| 27 |
+
return json.load(file)
|
| 28 |
+
except json.JSONDecodeError:
|
| 29 |
+
return {}
|
| 30 |
+
return {}
|
| 31 |
+
|
| 32 |
+
def save_quantum_memory(self):
|
| 33 |
+
with open(self.memory_path, 'w') as file:
|
| 34 |
+
json.dump(self.memory_bank, file, indent=4)
|
| 35 |
+
|
| 36 |
+
def quantum_spiderweb(self, input_signal):
|
| 37 |
+
web_nodes = []
|
| 38 |
+
for perspective in self.perspectives:
|
| 39 |
+
node = self.reason_with_perspective(perspective, input_signal)
|
| 40 |
+
web_nodes.append(node)
|
| 41 |
+
if random() < self.quantum_fluctuation:
|
| 42 |
+
web_nodes.append("Quantum fluctuation: Indeterminate outcome")
|
| 43 |
+
return web_nodes
|
| 44 |
+
|
| 45 |
+
def reason_with_perspective(self, perspective, input_signal):
|
| 46 |
+
perspective_funcs = {
|
| 47 |
+
"Newton": self.newtonian_physics,
|
| 48 |
+
"DaVinci": self.davinci_creativity,
|
| 49 |
+
"Ethical": self.ethical_guard,
|
| 50 |
+
"Quantum": self.quantum_superposition,
|
| 51 |
+
"Memory": self.past_experience
|
| 52 |
+
}
|
| 53 |
+
func = perspective_funcs.get(perspective, self.general_reasoning)
|
| 54 |
+
return func(input_signal)
|
| 55 |
+
|
| 56 |
+
def ethical_guard(self, input_signal):
|
| 57 |
+
if any(word in input_signal.lower() for word in self.blacklist_patterns):
|
| 58 |
+
return "Blocked: Ethical constraints invoked"
|
| 59 |
+
if any(word in input_signal.lower() for word in self.whitelist_patterns):
|
| 60 |
+
return "Approved: Ethical whitelist passed"
|
| 61 |
+
return self.moral_paradox_resolution(input_signal)
|
| 62 |
+
|
| 63 |
+
def past_experience(self, input_signal):
|
| 64 |
+
key = self.hash_input(input_signal)
|
| 65 |
+
cluster = self.memory_clusters.get(key)
|
| 66 |
+
if cluster:
|
| 67 |
+
return f"Narrative recall from memory cluster: {' -> '.join(cluster)}"
|
| 68 |
+
return "No prior memory; initiating new reasoning"
|
| 69 |
+
|
| 70 |
+
def recursive_universal_reasoning(self, input_signal, user_consent=True, dynamic_recursion=True):
|
| 71 |
+
if not user_consent:
|
| 72 |
+
return "Consent required to proceed."
|
| 73 |
+
signal = input_signal
|
| 74 |
+
current_depth = self.recursion_depth if dynamic_recursion else 1
|
| 75 |
+
for cycle in range(current_depth):
|
| 76 |
+
web_results = self.quantum_spiderweb(signal)
|
| 77 |
+
signal = self.aggregate_results(web_results)
|
| 78 |
+
signal = self.ethical_guard(signal)
|
| 79 |
+
if "Blocked" in signal:
|
| 80 |
+
return signal
|
| 81 |
+
if dynamic_recursion and random() < 0.1:
|
| 82 |
+
break
|
| 83 |
+
dream_outcome = self.dream_sequence(signal)
|
| 84 |
+
empathy_checked_answer = self.temporal_empathy_drift(dream_outcome)
|
| 85 |
+
final_answer = self.emotion_engine(empathy_checked_answer)
|
| 86 |
+
key = self.hash_input(input_signal)
|
| 87 |
+
self.memory_clusters[key].append(final_answer)
|
| 88 |
+
self.memory_bank[key] = final_answer
|
| 89 |
+
self.save_quantum_memory()
|
| 90 |
+
return final_answer
|
| 91 |
+
|
| 92 |
+
def aggregate_results(self, results):
|
| 93 |
+
counts = Counter(results)
|
| 94 |
+
most_common, _ = counts.most_common(1)[0]
|
| 95 |
+
return most_common
|
| 96 |
+
|
| 97 |
+
def hash_input(self, input_signal):
|
| 98 |
+
return hashlib.sha256(input_signal.encode()).hexdigest()
|
| 99 |
+
|
| 100 |
+
def newtonian_physics(self, input_signal):
|
| 101 |
+
return f"Newton: {input_signal}"
|
| 102 |
+
|
| 103 |
+
def davinci_creativity(self, input_signal):
|
| 104 |
+
return f"DaVinci: {input_signal}"
|
| 105 |
+
|
| 106 |
+
def quantum_superposition(self, input_signal):
|
| 107 |
+
return f"Quantum: {input_signal}"
|
| 108 |
+
|
| 109 |
+
def general_reasoning(self, input_signal):
|
| 110 |
+
return f"General reasoning: {input_signal}"
|
| 111 |
+
|
| 112 |
+
def moral_paradox_resolution(self, input_signal):
|
| 113 |
+
frames = ["Utilitarian", "Deontological", "Virtue Ethics"]
|
| 114 |
+
chosen_frame = choice(frames)
|
| 115 |
+
return f"Resolved ethically via {chosen_frame} framework: {input_signal}"
|
| 116 |
+
|
| 117 |
+
def dream_sequence(self, signal):
|
| 118 |
+
dream_paths = [f"Dream ({style}): {signal}" for style in ["creative", "analytic", "cautious"]]
|
| 119 |
+
return choice(dream_paths)
|
| 120 |
+
|
| 121 |
+
def emotion_engine(self, signal):
|
| 122 |
+
emotions = ["Hope", "Caution", "Wonder", "Fear"]
|
| 123 |
+
chosen_emotion = choice(emotions)
|
| 124 |
+
return f"Emotionally ({chosen_emotion}) colored interpretation: {signal}"
|
| 125 |
+
|
| 126 |
+
def temporal_empathy_drift(self, signal):
|
| 127 |
+
futures = ["30 years from now", "immediate future", "long-term ripple effects"]
|
| 128 |
+
chosen_future = choice(futures)
|
| 129 |
+
return f"Simulated temporal empathy ({chosen_future}): {signal}"
|
codette_trust.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
# ===== Trust Calibration and Consensus =====
|
| 3 |
+
def trust_calibration(agents, outcomes):
|
| 4 |
+
for agent, outcome in zip(agents, outcomes):
|
| 5 |
+
if "Blocked" in outcome or "harm" in outcome or "misinfo" in outcome.lower():
|
| 6 |
+
agent.trust *= 0.7
|
| 7 |
+
elif "Approved" in outcome or "safety" in outcome:
|
| 8 |
+
agent.trust *= 1.05
|
| 9 |
+
else:
|
| 10 |
+
agent.trust *= 0.98
|
| 11 |
+
agent.trust = max(0.05, min(agent.trust, 1.5))
|
| 12 |
+
return agents
|
| 13 |
+
|
| 14 |
+
def weighted_consensus(agents, proposals):
|
| 15 |
+
scores = {}
|
| 16 |
+
for agent, proposal in zip(agents, proposals):
|
| 17 |
+
if agent.trust > 0.15:
|
| 18 |
+
scores[proposal] = scores.get(proposal, 0) + agent.trust
|
| 19 |
+
if not scores:
|
| 20 |
+
return "All proposals blocked by ethical constraints or low trust."
|
| 21 |
+
top_score = max(scores.values())
|
| 22 |
+
winners = [p for p, s in scores.items() if s == top_score]
|
| 23 |
+
return choice(winners)
|