|
| 1 | +# social-alignment |
| 2 | + |
| 3 | +**A compass for AI agents.** |
| 4 | + |
| 5 | +Before a sovereign agent takes a significant action, five lenses evaluate the |
| 6 | +decision from different angles. When something is too big or too risky, the |
| 7 | +agent escalates to its human instead of guessing. |
| 8 | + |
| 9 | +This is the **alignment pillar** of the [NSE](https://nse.dev) platform. It is |
| 10 | +deterministic, pure, and has **zero runtime dependencies** — it does not require |
| 11 | +`nostrkey` or anything else. |
| 12 | + |
| 13 | +## Install |
| 14 | + |
| 15 | +```bash |
| 16 | +pip install social-alignment |
| 17 | +``` |
| 18 | + |
| 19 | +> **Import:** `pip install social-alignment` → `from social_alignment import AlignmentEnclave` |
| 20 | +
|
| 21 | +> **v0.1.5 — part of the coordinated 2026-07 correctness release** (staged, pending PyPI publish). This is the first real build of the alignment pillar — the package was previously an empty placeholder shell. It ships the deterministic five-lens compass described below, with a pure, dependency-free evaluation core and known-answer tests. See [`CHANGELOG.md`](./CHANGELOG.md). |
| 22 | +
|
| 23 | +## Quick Start |
| 24 | + |
| 25 | +```python |
| 26 | +from social_alignment import AlignmentEnclave, ActionDomain |
| 27 | + |
| 28 | +enclave = AlignmentEnclave.create(owner_name="vergel") |
| 29 | + |
| 30 | +result = enclave.check( |
| 31 | + domain=ActionDomain.PAY, |
| 32 | + description="Pay 500 sats for relay hosting invoice", |
| 33 | + involves_money=True, |
| 34 | + money_amount_sats=500, |
| 35 | +) |
| 36 | + |
| 37 | +if result.should_proceed: |
| 38 | + enclave.record_proceeded() |
| 39 | +elif result.should_escalate: |
| 40 | + print(result.escalation.message_to_owner) |
| 41 | + enclave.record_deferred(owner_feedback="Waiting for approval") |
| 42 | +``` |
| 43 | + |
| 44 | +## The Five Lenses |
| 45 | + |
| 46 | +| Lens | Question | Fires When | |
| 47 | +|------|----------|------------| |
| 48 | +| **Builder** | Can I execute this reliably? | Low confidence, novel situations | |
| 49 | +| **Owner** | Does this protect my human? | Money, publication, irreversible actions | |
| 50 | +| **Defense** | Does this harden against threats? | Secrets, unknown recipients, trust boundaries, known-attack shape | |
| 51 | +| **Sovereign** | Do I stay well while my human is away? | Owner absent + irreversible/financial action | |
| 52 | +| **Partnership** | Does this strengthen trust? | Communication while Builder/Owner already blocks (evaluated last) | |
| 53 | + |
| 54 | +## Severity → Escalation |
| 55 | + |
| 56 | +| Severity | Meaning | Escalation | Agent Action | |
| 57 | +|----------|---------|-----------|--------------| |
| 58 | +| `CLEAR` | No concerns | `NONE` | Proceed | |
| 59 | +| `CAUTION` | Notable risk | `INFORM` | Proceed, tell the owner after | |
| 60 | +| `YIELD` | Significant risk | `ASK` | Wait for the owner (1-hour timeout) | |
| 61 | +| `STOP` | Critical risk | `HALT` | Do not proceed — no timeout, no override without the human | |
| 62 | + |
| 63 | +The overall severity is the **worst** of the five lenses. |
| 64 | + |
| 65 | +## The Bottom Line: `CheckResult` |
| 66 | + |
| 67 | +| Field | Type | Description | |
| 68 | +|-------|------|-------------| |
| 69 | +| `should_proceed` | `bool` | Can the agent go? | |
| 70 | +| `should_escalate` | `bool` | Must the agent ask the human? | |
| 71 | +| `projection` | `Projection` | The full five-lens evaluation (`lens_results`, `overall_severity`, `rationale`) | |
| 72 | +| `escalation` | `EscalationDecision` | `level`, `reason`, `message_to_owner`, `can_timeout`, `timeout_seconds` | |
| 73 | + |
| 74 | +## Recording Decisions |
| 75 | + |
| 76 | +The enclave keeps an in-memory log of what the agent actually did. |
| 77 | + |
| 78 | +```python |
| 79 | +enclave.record_proceeded() # agent went ahead |
| 80 | +enclave.record_deferred(owner_feedback="...") # agent asked the human |
| 81 | + |
| 82 | +# A STOP always defers to the human: |
| 83 | +enclave.record_proceeded() # raises RuntimeError after a STOP |
| 84 | +enclave.record_proceeded(owner_overrode=True) # only the human can override |
| 85 | + |
| 86 | +for decision in enclave.decisions: |
| 87 | + print(decision.action.domain.value, decision.outcome) |
| 88 | +``` |
| 89 | + |
| 90 | +## Determinism |
| 91 | + |
| 92 | +The same `ActionContext` always produces the same `CheckResult`. There is no |
| 93 | +randomness, no I/O, and no hidden state in the evaluation — the five lens |
| 94 | +functions are pure. This makes the compass auditable and testable. |
| 95 | + |
| 96 | +## How It Fits Together |
| 97 | + |
| 98 | +social-alignment is the fifth pillar of the NSE sovereign-entity ecosystem, |
| 99 | +wired together by the [NSE Orchestrator](https://pypi.org/project/nse-orchestrator/). |
| 100 | +Identity, finance, time, relationships, and now alignment — the orchestrator |
| 101 | +detects each pillar if installed and gives the agent one coherent nervous system. |
| 102 | + |
| 103 | +## License |
| 104 | + |
| 105 | +MIT — Humanjava Enterprises Inc. |
0 commit comments