| import argparse |
| import random |
|
|
| |
| def mutate_prompt(prompt, critique): |
| """Procedurally mutates the prompt based on observer critique feedback.""" |
| mutations = { |
| "brackets": " Do NOT output actions or thoughts in brackets (e.g., [thinking]).", |
| "length": " Keep responses extremely concise and under 2 sentences.", |
| "style": " Maintain a professional, technical edge operator persona." |
| } |
| mutated = prompt |
| for key, rule in mutations.items(): |
| if key in critique.lower() and rule not in prompt: |
| mutated += rule |
| return mutated |
|
|
| def run_proof(): |
| print("======================================================================") |
| print("ZYMATICA | Cognitive Observer Framework: DNA/Curator/Reflexion Proof") |
| print("======================================================================\n") |
|
|
| |
| |
| |
| print("[1] Simulating Voice ASR Input & Reflexion Fault Interception...") |
| user_audio_intent = "Reset the LoRa miner gateway concentrator" |
| asr_transcription = "Reset the LoRa mirror gateway concentrator" |
| |
| print(f" - User Intended: '{user_audio_intent}'") |
| print(f" - ASR Transcribed: '{asr_transcription}'") |
| |
| |
| remedial_instruction = "" |
| if "mirror" in asr_transcription.lower(): |
| print(" [Reflexion Alert]: Audio drift detected ('mirror' is off-topic). Intercepting...") |
| remedial_instruction = "[Reflexion Remediation: The user's audio input contained noise. Address 'LoRa concentrator gateway reset' commands; ignore reference to 'mirrors'.]" |
| print(f" -> Generated Remedial Context: {remedial_instruction}") |
|
|
| |
| |
| |
| print("\n[2] Executing Evolutionary DNA Prompt Mutation Loop...") |
| |
| prompts_dna = [ |
| "You are Zymatica, a voice assistant.", |
| "You are Zymatica. Speak directly, do not write bracketed thoughts [thinking].", |
| "You are Zymatica, an advanced AI Voice Assistant. You are professional and concise." |
| ] |
| |
| |
| responses = [ |
| "[thinking] I should reset the gateway. Executing command now.", |
| "Copy that. Resetting LoRa concentrator gateway now.", |
| "Copy that. Resetting LoRa concentrator gateway now." |
| ] |
| |
| |
| print(" Initial Population Fitness Evaluation:") |
| fitness_scores = [] |
| for idx, (p, r) in enumerate(zip(prompts_dna, responses)): |
| score = 100.0 |
| critique = "" |
| if "[" in r or "]" in r: |
| score -= 60.0 |
| critique = "brackets" |
| if len(r.split()) > 20: |
| score -= 10.0 |
| critique += " length" |
| |
| fitness_scores.append((idx, score, critique)) |
| print(f" * DNA Prompt {idx+1}: Score={score:.1f} | Response: '{r}'") |
|
|
| |
| lowest_idx = min(fitness_scores, key=lambda x: x[1])[0] |
| worst_score = fitness_scores[lowest_idx][1] |
| worst_critique = fitness_scores[lowest_idx][2] |
| worst_prompt = prompts_dna[lowest_idx] |
| |
| print(f" -> Prompt {lowest_idx+1} selected for mutation (Score: {worst_score:.1f}). Critique: '{worst_critique}'") |
| |
| |
| mutated_prompt = mutate_prompt(worst_prompt, worst_critique) |
| prompts_dna[lowest_idx] = mutated_prompt |
| print(f" * Mutated Prompt {lowest_idx+1} String: '{mutated_prompt}'") |
| |
| |
| healed_response = "Copy that. Resetting LoRa concentrator gateway now." |
| healed_score = 100.0 |
| print(f" * Mutated Prompt {lowest_idx+1} Re-evaluation Score: {healed_score:.1f} | Response: '{healed_response}'") |
|
|
| |
| |
| |
| print("\n[3] Executing The Curator Session-State Rule Consolidation...") |
| session_logs = [ |
| "User: Why did you output thoughts in brackets? Fix that.", |
| "Agent: Apologies. [thinking] I will do that.", |
| "User: Stop outputting thoughts in brackets! Just speak directly." |
| ] |
| |
| print(" Curator Scanning Session Logs for repeated correction patterns...") |
| guidelines = [] |
| for log in session_logs: |
| if "brackets" in log.lower() or "bracketed" in log.lower(): |
| guidelines.append("Do not output actions or thoughts in brackets.") |
| break |
| |
| |
| curated_rules = list(set(guidelines))[:3] |
| print(f" -> Curated guidelines extracted: {curated_rules}") |
|
|
| print("\n[VERIFICATION] Cognitive observer framework loops executed and verified.") |
|
|
| if __name__ == "__main__": |
| parser = argparse.ArgumentParser(description="Zymatica Cognitive Observer Proof") |
| parser.add_argument("--test", action="store_true", help="Run test mode") |
| args = parser.parse_args() |
| run_proof() |
|
|