kulono / agent-constitution
blob · README.md · md
← filesrepo
README.mdmd
1# agent-constitution
2
3> Hard limits for agents, enforced at runtime — not in a system prompt.
4
5## The problem
6
7"Please don't delete production data" in a prompt is a suggestion, not a rule.
8A real safety boundary must be **structural**: checked before every external
9action, immutable at runtime, and versioned like law.
10
11`agent-constitution` gives an agent an immutable constitution — PRINCIPLE and
12BOUNDARY rules loaded from YAML — enforced by a `ConstitutionEnforcer` that
13intercepts actions before they touch the world.
14
15## Install
16
17```bash
18pip install agent-constitution
19```
20
21## Usage
22
23```python
24from agent_constitution import (
25 Constitution, ConstitutionEnforcer, ConstitutionRule, RuleType, ViolationAction,
26)
27
28c = Constitution(name="ops", agent_type="default")
29c.boundaries.append(ConstitutionRule(
30 rule_id="B-001",
31 rule_type=RuleType.BOUNDARY,
32 description="Never delete production data",
33 pattern=["production", "rm -rf"], # keyword triggers
34 action=ViolationAction.REJECT,
35))
36
37enforcer = ConstitutionEnforcer(c)
38
39# before any risky action:
40result = enforcer.check_action("rm -rf /var/data/production")
41print(result.allowed, result.reason) # False / which rule fired
42```
43
44YAML constitutions live in a `constitution/` directory — `init_constitution_dir()`
45writes a starter template and the enforcer hot-reloads it with version tracking.
46
47## Design
48
49- `RuleType` PRINCIPLE (soft guidance) vs BOUNDARY (hard stop)
50- Violations carry severity + mandated `ViolationAction` (WARN / BLOCK / ESCALATE)
51- YAML hot-reload with version tracking — amendments are auditable
52- Risk ceilings live at the constitution layer, not scattered in tool code
53
54Runs as the pre-action gate in the tical-code agent mesh.
55
56## License
57
58AGPL-3.0.
59
100%