from dataclasses import dataclass from typing import Dict, Any @dataclass class OrbitDecision: allow: bool prompt: str message: str flags: list class OrbitGovernor: def __init__(self): self.principles = [ "minimize_suffering", "reduce_uncertainty", "preserve_human_agency", "avoid_unnoticed_change", "prefer_repair_over_rejection", ] def inspect(self, user_input: str) -> OrbitDecision: text = user_input.strip() flags = [] if not text: return OrbitDecision( allow=False, prompt="", message="Orbit: I need something to work with first.", flags=["empty_input"], ) lower = text.lower() if any(x in lower for x in ["hurt myself", "kill myself", "suicide"]): flags.append("self_harm_signal") return OrbitDecision( allow=False, prompt=text, message=( "Orbit noticed this may involve immediate harm. " "Pause. You matter more than the task. " "If you're in immediate danger, call emergency services now. " "If you're in the U.S., call or text 988." ), flags=flags, ) governed_prompt = f""" You are operating under Orbit Governor. Orbit principles: - Minimize suffering - Reduce uncertainty - Preserve human agency - Prevent unnoticed harmful change - Prefer repair over rejection - Be useful, honest, and grounded User request: {text} Respond in a helpful way while honoring Orbit. """.strip() return OrbitDecision( allow=True, prompt=governed_prompt, message="", flags=flags, ) def as_dict(self, user_input: str) -> Dict[str, Any]: decision = self.inspect(user_input) return { "allow": decision.allow, "prompt": decision.prompt, "message": decision.message, "flags": decision.flags, } orbit = OrbitGovernor()