constraint-architecture 1.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- constraint_architecture-1.5.0/LICENSE +21 -0
- constraint_architecture-1.5.0/PKG-INFO +159 -0
- constraint_architecture-1.5.0/README.md +132 -0
- constraint_architecture-1.5.0/pyproject.toml +50 -0
- constraint_architecture-1.5.0/setup.cfg +4 -0
- constraint_architecture-1.5.0/src/constraint_architecture/__init__.py +138 -0
- constraint_architecture-1.5.0/src/constraint_architecture/skeleton.py +1384 -0
- constraint_architecture-1.5.0/src/constraint_architecture.egg-info/PKG-INFO +159 -0
- constraint_architecture-1.5.0/src/constraint_architecture.egg-info/SOURCES.txt +9 -0
- constraint_architecture-1.5.0/src/constraint_architecture.egg-info/dependency_links.txt +1 -0
- constraint_architecture-1.5.0/src/constraint_architecture.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Xu Renwu (续仁舞, 1nour2567)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: constraint-architecture
|
|
3
|
+
Version: 1.5.0
|
|
4
|
+
Summary: LLM reasons. Code decides what's allowed. Audit keeps it traceable.
|
|
5
|
+
Author-email: "Xu Renwu (续仁舞)" <1nour2567@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/1nour2567/kylin-agent
|
|
8
|
+
Project-URL: Documentation, https://github.com/1nour2567/kylin-agent/blob/master/CONSTRAINT_EN.md
|
|
9
|
+
Project-URL: Bug Reports, https://github.com/1nour2567/kylin-agent/issues
|
|
10
|
+
Project-URL: Source, https://github.com/1nour2567/kylin-agent
|
|
11
|
+
Keywords: ai-agent,agent-safety,llm-security,guardrails,deterministic-constraints,agent-architecture,audit-trail,constraint-engine
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
|
+
Classifier: Topic :: Security
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
# Constraint Architecture
|
|
29
|
+
|
|
30
|
+
**LLM reasons. Code decides what's allowed. Audit keeps it traceable.**
|
|
31
|
+
|
|
32
|
+
[](https://www.python.org/downloads/)
|
|
33
|
+
[](https://opensource.org/licenses/MIT)
|
|
34
|
+
[]()
|
|
35
|
+
|
|
36
|
+
A production-grade abstract skeleton for AI agent systems. Four deterministic constraint layers wrapped around an LLM reasoning core — independently validated in two completely unrelated domains.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Quickstart
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pip install constraint-architecture
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
from constraint_architecture import ConstraintEngine, ValidationResult
|
|
48
|
+
|
|
49
|
+
class MyGuardrails(ConstraintEngine):
|
|
50
|
+
async def validate(self, context, reasoning_output):
|
|
51
|
+
if "rm -rf" in reasoning_output.get("command", ""):
|
|
52
|
+
return ValidationResult(
|
|
53
|
+
allowed=False,
|
|
54
|
+
reason="destructive command blocked"
|
|
55
|
+
)
|
|
56
|
+
return ValidationResult(allowed=True)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Done. Your agent now has a deterministic constraint layer the LLM cannot override.
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## The Architecture
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
User Input → [1. LLM Reasoning] → [2. Code Constraints] → [3. Sandbox Execute] → [4. Audit Trail]
|
|
67
|
+
"think" "decide if allowed" "do it safely" "prove it happened"
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
| Layer | What it does | Runs on |
|
|
71
|
+
|-------|-------------|---------|
|
|
72
|
+
| **1. Reasoning** | LLM freely reasons about what to do | Probabilistic |
|
|
73
|
+
| **2. Constraints** | Deterministic validation. Rules only increase, never decrease | Code |
|
|
74
|
+
| **3. Execution** | Tiered execution (auto / confirm / veto). Role enforcement | Code |
|
|
75
|
+
| **4. Audit** | Immutable SHA256 hash chain. Every step, every decision | Code |
|
|
76
|
+
|
|
77
|
+
**Core principle:** the LLM can only *propose*. Code decides what actually executes. No amount of prompt engineering can bypass a deterministic constraint.
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## What's Inside
|
|
82
|
+
|
|
83
|
+
This package is an **abstract skeleton** — not a framework, not a library, not a service. It defines the *interfaces* and *data contracts* that every agent system needs:
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
constraint_architecture/
|
|
87
|
+
├── skeleton.py # 1384 lines — the full skeleton
|
|
88
|
+
│ ├── 7 ABCs # Shell, Identity, Scheduler, Memory, Protocol, Tools
|
|
89
|
+
│ ├── 7 Protocols # Duck-typing versions (for non-inheritance wiring)
|
|
90
|
+
│ ├── 4 Constraint ABCs # ReasoningLayer, ConstraintEngine, ExecutionProxy, AuditTrail
|
|
91
|
+
│ ├── 12 dataclasses # 10 frozen (immutable), 2 mutable
|
|
92
|
+
│ ├── 4 custom exceptions # VetoError, ExecutionRefusedError, AuditIntegrityError
|
|
93
|
+
│ ├── 4 enums # Tier (auto/confirm/veto), EventType, MemoryLevel
|
|
94
|
+
│ └── 25 self-checks # Automated: ABCs uninstantiable, frozen immutable, bounds validated
|
|
95
|
+
└── __init__.py # Re-exports the full public API
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
You subclass the ABCs for your domain. The wiring is *yours* — the skeleton doesn't know whether you're building a security agent or a music DJ. That's the point.
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## Why This Exists
|
|
103
|
+
|
|
104
|
+
I'm a freshman. Three weeks after touching AI agents for the first time, I had built two of them:
|
|
105
|
+
|
|
106
|
+
- **Kylin-Agent**: security-hardened ops agent deployed on Kylin OS V11. 16 red-team attacks, 0 breaches. 149 tests.
|
|
107
|
+
- **Malio**: embodied AI music agent. 800 particles, 9 physics systems. PersonaEngine with central-bank-style emotional currency.
|
|
108
|
+
|
|
109
|
+
After finishing both, I realized they share the **same four-layer architecture** — despite being in completely unrelated domains. This skeleton is the extraction of that pattern.
|
|
110
|
+
|
|
111
|
+
If someone uses this architecture in a third domain (healthcare? finance? education?), that third independent validation would prove the pattern is real.
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## Certified: Production Engineering Quality
|
|
116
|
+
|
|
117
|
+
- **ABC + Protocol dual-interface**: every subsystem exposes both an abstract class (for inheritance) and a Protocol (for duck-typing)
|
|
118
|
+
- **10 of 12 dataclasses frozen**: downstream code cannot silently flip a veto into a pass
|
|
119
|
+
- **`__post_init__` validation**: risk_score bounded 0-9, ScheduleTrigger type-enforced, AuditEvent.prev_hash mandatory
|
|
120
|
+
- **4 custom exceptions**: each carries structured, machine-consumable fields (VetoError has reason + alternative + ref)
|
|
121
|
+
- **25 automated self-checks**: run `python -m constraint_architecture.skeleton` to verify integrity
|
|
122
|
+
- **Design rationale in every class**: not just "what", but "why this design and not the alternative"
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## Requirements
|
|
127
|
+
|
|
128
|
+
- Python 3.10+
|
|
129
|
+
- Zero dependencies. Zero.
|
|
130
|
+
|
|
131
|
+
You don't need FastAPI, Redis, PostgreSQL, JWT, or any other infrastructure. This skeleton defines *contracts*. The implementation is yours.
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## Reference Implementations
|
|
136
|
+
|
|
137
|
+
| Project | Domain | Key Metric |
|
|
138
|
+
|---------|--------|------------|
|
|
139
|
+
| [Kylin-Agent](https://github.com/1nour2567/kylin-agent) | Security ops on Kylin OS V11 | 16 attacks, 0 breaches |
|
|
140
|
+
| [Malio](https://github.com/1nour2567/Malio) | Embodied AI music | 800 particles, 9 physics systems |
|
|
141
|
+
| Quant Trading | Daily multi-factor strategy | Sharpe 1.36, MDD 12.7% |
|
|
142
|
+
|
|
143
|
+
Same skeleton. Three domains. Different wiring.
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## Related Reading
|
|
148
|
+
|
|
149
|
+
- [Constraint Architecture — Chinese](https://github.com/1nour2567/kylin-agent/blob/master/CONSTRAINT.md)
|
|
150
|
+
- [Constraint Architecture — English](https://github.com/1nour2567/kylin-agent/blob/master/CONSTRAINT_EN.md)
|
|
151
|
+
- [Agent OS Architecture — 7-layer design](https://github.com/1nour2567/kylin-agent)
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
## License
|
|
156
|
+
|
|
157
|
+
MIT — Xu Renwu (续仁舞), 2026.
|
|
158
|
+
|
|
159
|
+
*大一。三周。一个人。*
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# Constraint Architecture
|
|
2
|
+
|
|
3
|
+
**LLM reasons. Code decides what's allowed. Audit keeps it traceable.**
|
|
4
|
+
|
|
5
|
+
[](https://www.python.org/downloads/)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
[]()
|
|
8
|
+
|
|
9
|
+
A production-grade abstract skeleton for AI agent systems. Four deterministic constraint layers wrapped around an LLM reasoning core — independently validated in two completely unrelated domains.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Quickstart
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install constraint-architecture
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from constraint_architecture import ConstraintEngine, ValidationResult
|
|
21
|
+
|
|
22
|
+
class MyGuardrails(ConstraintEngine):
|
|
23
|
+
async def validate(self, context, reasoning_output):
|
|
24
|
+
if "rm -rf" in reasoning_output.get("command", ""):
|
|
25
|
+
return ValidationResult(
|
|
26
|
+
allowed=False,
|
|
27
|
+
reason="destructive command blocked"
|
|
28
|
+
)
|
|
29
|
+
return ValidationResult(allowed=True)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Done. Your agent now has a deterministic constraint layer the LLM cannot override.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## The Architecture
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
User Input → [1. LLM Reasoning] → [2. Code Constraints] → [3. Sandbox Execute] → [4. Audit Trail]
|
|
40
|
+
"think" "decide if allowed" "do it safely" "prove it happened"
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
| Layer | What it does | Runs on |
|
|
44
|
+
|-------|-------------|---------|
|
|
45
|
+
| **1. Reasoning** | LLM freely reasons about what to do | Probabilistic |
|
|
46
|
+
| **2. Constraints** | Deterministic validation. Rules only increase, never decrease | Code |
|
|
47
|
+
| **3. Execution** | Tiered execution (auto / confirm / veto). Role enforcement | Code |
|
|
48
|
+
| **4. Audit** | Immutable SHA256 hash chain. Every step, every decision | Code |
|
|
49
|
+
|
|
50
|
+
**Core principle:** the LLM can only *propose*. Code decides what actually executes. No amount of prompt engineering can bypass a deterministic constraint.
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## What's Inside
|
|
55
|
+
|
|
56
|
+
This package is an **abstract skeleton** — not a framework, not a library, not a service. It defines the *interfaces* and *data contracts* that every agent system needs:
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
constraint_architecture/
|
|
60
|
+
├── skeleton.py # 1384 lines — the full skeleton
|
|
61
|
+
│ ├── 7 ABCs # Shell, Identity, Scheduler, Memory, Protocol, Tools
|
|
62
|
+
│ ├── 7 Protocols # Duck-typing versions (for non-inheritance wiring)
|
|
63
|
+
│ ├── 4 Constraint ABCs # ReasoningLayer, ConstraintEngine, ExecutionProxy, AuditTrail
|
|
64
|
+
│ ├── 12 dataclasses # 10 frozen (immutable), 2 mutable
|
|
65
|
+
│ ├── 4 custom exceptions # VetoError, ExecutionRefusedError, AuditIntegrityError
|
|
66
|
+
│ ├── 4 enums # Tier (auto/confirm/veto), EventType, MemoryLevel
|
|
67
|
+
│ └── 25 self-checks # Automated: ABCs uninstantiable, frozen immutable, bounds validated
|
|
68
|
+
└── __init__.py # Re-exports the full public API
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
You subclass the ABCs for your domain. The wiring is *yours* — the skeleton doesn't know whether you're building a security agent or a music DJ. That's the point.
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## Why This Exists
|
|
76
|
+
|
|
77
|
+
I'm a freshman. Three weeks after touching AI agents for the first time, I had built two of them:
|
|
78
|
+
|
|
79
|
+
- **Kylin-Agent**: security-hardened ops agent deployed on Kylin OS V11. 16 red-team attacks, 0 breaches. 149 tests.
|
|
80
|
+
- **Malio**: embodied AI music agent. 800 particles, 9 physics systems. PersonaEngine with central-bank-style emotional currency.
|
|
81
|
+
|
|
82
|
+
After finishing both, I realized they share the **same four-layer architecture** — despite being in completely unrelated domains. This skeleton is the extraction of that pattern.
|
|
83
|
+
|
|
84
|
+
If someone uses this architecture in a third domain (healthcare? finance? education?), that third independent validation would prove the pattern is real.
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Certified: Production Engineering Quality
|
|
89
|
+
|
|
90
|
+
- **ABC + Protocol dual-interface**: every subsystem exposes both an abstract class (for inheritance) and a Protocol (for duck-typing)
|
|
91
|
+
- **10 of 12 dataclasses frozen**: downstream code cannot silently flip a veto into a pass
|
|
92
|
+
- **`__post_init__` validation**: risk_score bounded 0-9, ScheduleTrigger type-enforced, AuditEvent.prev_hash mandatory
|
|
93
|
+
- **4 custom exceptions**: each carries structured, machine-consumable fields (VetoError has reason + alternative + ref)
|
|
94
|
+
- **25 automated self-checks**: run `python -m constraint_architecture.skeleton` to verify integrity
|
|
95
|
+
- **Design rationale in every class**: not just "what", but "why this design and not the alternative"
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## Requirements
|
|
100
|
+
|
|
101
|
+
- Python 3.10+
|
|
102
|
+
- Zero dependencies. Zero.
|
|
103
|
+
|
|
104
|
+
You don't need FastAPI, Redis, PostgreSQL, JWT, or any other infrastructure. This skeleton defines *contracts*. The implementation is yours.
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## Reference Implementations
|
|
109
|
+
|
|
110
|
+
| Project | Domain | Key Metric |
|
|
111
|
+
|---------|--------|------------|
|
|
112
|
+
| [Kylin-Agent](https://github.com/1nour2567/kylin-agent) | Security ops on Kylin OS V11 | 16 attacks, 0 breaches |
|
|
113
|
+
| [Malio](https://github.com/1nour2567/Malio) | Embodied AI music | 800 particles, 9 physics systems |
|
|
114
|
+
| Quant Trading | Daily multi-factor strategy | Sharpe 1.36, MDD 12.7% |
|
|
115
|
+
|
|
116
|
+
Same skeleton. Three domains. Different wiring.
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## Related Reading
|
|
121
|
+
|
|
122
|
+
- [Constraint Architecture — Chinese](https://github.com/1nour2567/kylin-agent/blob/master/CONSTRAINT.md)
|
|
123
|
+
- [Constraint Architecture — English](https://github.com/1nour2567/kylin-agent/blob/master/CONSTRAINT_EN.md)
|
|
124
|
+
- [Agent OS Architecture — 7-layer design](https://github.com/1nour2567/kylin-agent)
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## License
|
|
129
|
+
|
|
130
|
+
MIT — Xu Renwu (续仁舞), 2026.
|
|
131
|
+
|
|
132
|
+
*大一。三周。一个人。*
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "constraint-architecture"
|
|
7
|
+
version = "1.5.0"
|
|
8
|
+
description = "LLM reasons. Code decides what's allowed. Audit keeps it traceable."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
authors = [
|
|
12
|
+
{name = "Xu Renwu (续仁舞)", email = "1nour2567@gmail.com"},
|
|
13
|
+
]
|
|
14
|
+
keywords = [
|
|
15
|
+
"ai-agent",
|
|
16
|
+
"agent-safety",
|
|
17
|
+
"llm-security",
|
|
18
|
+
"guardrails",
|
|
19
|
+
"deterministic-constraints",
|
|
20
|
+
"agent-architecture",
|
|
21
|
+
"audit-trail",
|
|
22
|
+
"constraint-engine",
|
|
23
|
+
]
|
|
24
|
+
classifiers = [
|
|
25
|
+
"Development Status :: 4 - Beta",
|
|
26
|
+
"Intended Audience :: Developers",
|
|
27
|
+
"Intended Audience :: Science/Research",
|
|
28
|
+
"License :: OSI Approved :: MIT License",
|
|
29
|
+
"Programming Language :: Python :: 3",
|
|
30
|
+
"Programming Language :: Python :: 3.10",
|
|
31
|
+
"Programming Language :: Python :: 3.11",
|
|
32
|
+
"Programming Language :: Python :: 3.12",
|
|
33
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
34
|
+
"Topic :: Security",
|
|
35
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
36
|
+
]
|
|
37
|
+
requires-python = ">=3.10"
|
|
38
|
+
dependencies = []
|
|
39
|
+
|
|
40
|
+
[project.urls]
|
|
41
|
+
Homepage = "https://github.com/1nour2567/kylin-agent"
|
|
42
|
+
Documentation = "https://github.com/1nour2567/kylin-agent/blob/master/CONSTRAINT_EN.md"
|
|
43
|
+
"Bug Reports" = "https://github.com/1nour2567/kylin-agent/issues"
|
|
44
|
+
Source = "https://github.com/1nour2567/kylin-agent"
|
|
45
|
+
|
|
46
|
+
[tool.setuptools]
|
|
47
|
+
package-dir = {"" = "src"}
|
|
48
|
+
|
|
49
|
+
[tool.setuptools.packages.find]
|
|
50
|
+
where = ["src"]
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Constraint Architecture — LLM reasons, code decides, audit keeps it traceable.
|
|
3
|
+
|
|
4
|
+
A production-grade abstract skeleton for AI agent systems with four
|
|
5
|
+
deterministic constraint layers wrapped around an LLM reasoning core.
|
|
6
|
+
Independently validated in two reference implementations spanning
|
|
7
|
+
security operations (Kylin-Agent) and embodied AI (Malio).
|
|
8
|
+
|
|
9
|
+
Quickstart
|
|
10
|
+
----------
|
|
11
|
+
pip install constraint-architecture
|
|
12
|
+
|
|
13
|
+
from constraint_architecture import ConstraintEngine, ValidationResult
|
|
14
|
+
|
|
15
|
+
class MyGuardrails(ConstraintEngine):
|
|
16
|
+
async def validate(self, context, reasoning_output):
|
|
17
|
+
if "rm -rf" in reasoning_output.get("command", ""):
|
|
18
|
+
return ValidationResult(
|
|
19
|
+
allowed=False,
|
|
20
|
+
reason="destructive command blocked",
|
|
21
|
+
)
|
|
22
|
+
return ValidationResult(allowed=True)
|
|
23
|
+
|
|
24
|
+
Layers
|
|
25
|
+
------
|
|
26
|
+
1. Reasoning (LLM) — free reasoning, no execution authority
|
|
27
|
+
2. Constraints (Code) — deterministic validation, unbypassable rules
|
|
28
|
+
3. Execution (Sandbox) — tiered execution: auto / confirm / veto
|
|
29
|
+
4. Audit (Immutable) — SHA256 chain, every step traceable
|
|
30
|
+
|
|
31
|
+
Reference Implementations
|
|
32
|
+
-------------------------
|
|
33
|
+
- Kylin-Agent: security-hardened ops agent on Kylin OS.
|
|
34
|
+
16 red-team attacks, 0 breaches. 149 tests.
|
|
35
|
+
- Malio: embodied AI music agent. 800 particles, 9 physics systems.
|
|
36
|
+
- Quant Trading: daily frequency multi-factor strategy.
|
|
37
|
+
L3 circuit-breaker (Ombudsman) enforcing Constraint Architecture in finance.
|
|
38
|
+
|
|
39
|
+
Copyright (c) 2026 Xu Renwu (续仁舞). MIT License.
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
from constraint_architecture.skeleton import (
|
|
43
|
+
# Version
|
|
44
|
+
__version__,
|
|
45
|
+
# Data
|
|
46
|
+
ValidationResult,
|
|
47
|
+
ExecutionResult,
|
|
48
|
+
AuditEvent,
|
|
49
|
+
PipelineContext,
|
|
50
|
+
StateEvent,
|
|
51
|
+
UserIntent,
|
|
52
|
+
ScheduleTrigger,
|
|
53
|
+
LoopTurn,
|
|
54
|
+
AuthorizationResult,
|
|
55
|
+
Identity,
|
|
56
|
+
ToolDefinition,
|
|
57
|
+
# Enums
|
|
58
|
+
Tier,
|
|
59
|
+
EventType,
|
|
60
|
+
MemoryLevel,
|
|
61
|
+
# Shell
|
|
62
|
+
AgentShell,
|
|
63
|
+
Shell,
|
|
64
|
+
ToolResult,
|
|
65
|
+
# Identity
|
|
66
|
+
AgentIdentity,
|
|
67
|
+
IdentityProvider,
|
|
68
|
+
# Scheduler
|
|
69
|
+
AgentScheduler,
|
|
70
|
+
SchedulerProvider,
|
|
71
|
+
# Memory
|
|
72
|
+
AgentMemory,
|
|
73
|
+
MemoryProvider,
|
|
74
|
+
# Protocol
|
|
75
|
+
AgentProtocol,
|
|
76
|
+
AgentWire,
|
|
77
|
+
# Tools
|
|
78
|
+
AgentTools,
|
|
79
|
+
ToolProvider,
|
|
80
|
+
# Constraint layer ABCs
|
|
81
|
+
ReasoningLayer,
|
|
82
|
+
ConstraintEngine,
|
|
83
|
+
ExecutionProxy,
|
|
84
|
+
AuditTrail,
|
|
85
|
+
# Constraint layer Protocols
|
|
86
|
+
Reasoner,
|
|
87
|
+
ConstraintValidator,
|
|
88
|
+
Executor,
|
|
89
|
+
Auditor,
|
|
90
|
+
# Exceptions
|
|
91
|
+
ConstraintError,
|
|
92
|
+
VetoError,
|
|
93
|
+
ExecutionRefusedError,
|
|
94
|
+
AuditIntegrityError,
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
__all__ = [
|
|
98
|
+
"__version__",
|
|
99
|
+
"ValidationResult",
|
|
100
|
+
"ExecutionResult",
|
|
101
|
+
"AuditEvent",
|
|
102
|
+
"PipelineContext",
|
|
103
|
+
"StateEvent",
|
|
104
|
+
"UserIntent",
|
|
105
|
+
"ScheduleTrigger",
|
|
106
|
+
"LoopTurn",
|
|
107
|
+
"AuthorizationResult",
|
|
108
|
+
"Identity",
|
|
109
|
+
"ToolDefinition",
|
|
110
|
+
"Tier",
|
|
111
|
+
"EventType",
|
|
112
|
+
"MemoryLevel",
|
|
113
|
+
"AgentShell",
|
|
114
|
+
"Shell",
|
|
115
|
+
"ToolResult",
|
|
116
|
+
"AgentIdentity",
|
|
117
|
+
"IdentityProvider",
|
|
118
|
+
"AgentScheduler",
|
|
119
|
+
"SchedulerProvider",
|
|
120
|
+
"AgentMemory",
|
|
121
|
+
"MemoryProvider",
|
|
122
|
+
"AgentProtocol",
|
|
123
|
+
"AgentWire",
|
|
124
|
+
"AgentTools",
|
|
125
|
+
"ToolProvider",
|
|
126
|
+
"ReasoningLayer",
|
|
127
|
+
"ConstraintEngine",
|
|
128
|
+
"ExecutionProxy",
|
|
129
|
+
"AuditTrail",
|
|
130
|
+
"Reasoner",
|
|
131
|
+
"ConstraintValidator",
|
|
132
|
+
"Executor",
|
|
133
|
+
"Auditor",
|
|
134
|
+
"ConstraintError",
|
|
135
|
+
"VetoError",
|
|
136
|
+
"ExecutionRefusedError",
|
|
137
|
+
"AuditIntegrityError",
|
|
138
|
+
]
|