LLM reasons. Code decides what's allowed. Audit keeps it traceable.
Project description
Constraint Architecture
LLM reasons. Code decides what's allowed. Audit keeps it traceable.
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.
Quickstart
pip install constraint-architecture
from constraint_architecture import ConstraintEngine, ValidationResult
class MyGuardrails(ConstraintEngine):
async def validate(self, context, reasoning_output):
if "rm -rf" in reasoning_output.get("command", ""):
return ValidationResult(
allowed=False,
reason="destructive command blocked"
)
return ValidationResult(allowed=True)
Done. Your agent now has a deterministic constraint layer the LLM cannot override.
The Architecture
User Input → [1. LLM Reasoning] → [2. Code Constraints] → [3. Sandbox Execute] → [4. Audit Trail]
"think" "decide if allowed" "do it safely" "prove it happened"
| Layer | What it does | Runs on |
|---|---|---|
| 1. Reasoning | LLM freely reasons about what to do | Probabilistic |
| 2. Constraints | Deterministic validation. Rules only increase, never decrease | Code |
| 3. Execution | Tiered execution (auto / confirm / veto). Role enforcement | Code |
| 4. Audit | Immutable SHA256 hash chain. Every step, every decision | Code |
Core principle: the LLM can only propose. Code decides what actually executes. No amount of prompt engineering can bypass a deterministic constraint.
What's Inside
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:
constraint_architecture/
├── skeleton.py # 1384 lines — the full skeleton
│ ├── 7 ABCs # Shell, Identity, Scheduler, Memory, Protocol, Tools
│ ├── 7 Protocols # Duck-typing versions (for non-inheritance wiring)
│ ├── 4 Constraint ABCs # ReasoningLayer, ConstraintEngine, ExecutionProxy, AuditTrail
│ ├── 12 dataclasses # 10 frozen (immutable), 2 mutable
│ ├── 4 custom exceptions # VetoError, ExecutionRefusedError, AuditIntegrityError
│ ├── 4 enums # Tier (auto/confirm/veto), EventType, MemoryLevel
│ └── 25 self-checks # Automated: ABCs uninstantiable, frozen immutable, bounds validated
└── __init__.py # Re-exports the full public API
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.
Why This Exists
I'm a freshman. Three weeks after touching AI agents for the first time, I had built two of them:
- Kylin-Agent: security-hardened ops agent deployed on Kylin OS V11. 16 red-team attacks, 0 breaches. 149 tests.
- Malio: embodied AI music agent. 800 particles, 9 physics systems. PersonaEngine with central-bank-style emotional currency.
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.
If someone uses this architecture in a third domain (healthcare? finance? education?), that third independent validation would prove the pattern is real.
Certified: Production Engineering Quality
- ABC + Protocol dual-interface: every subsystem exposes both an abstract class (for inheritance) and a Protocol (for duck-typing)
- 10 of 12 dataclasses frozen: downstream code cannot silently flip a veto into a pass
__post_init__validation: risk_score bounded 0-9, ScheduleTrigger type-enforced, AuditEvent.prev_hash mandatory- 4 custom exceptions: each carries structured, machine-consumable fields (VetoError has reason + alternative + ref)
- 25 automated self-checks: run
python -m constraint_architecture.skeletonto verify integrity - Design rationale in every class: not just "what", but "why this design and not the alternative"
Requirements
- Python 3.10+
- Zero dependencies. Zero.
You don't need FastAPI, Redis, PostgreSQL, JWT, or any other infrastructure. This skeleton defines contracts. The implementation is yours.
Reference Implementations
| Project | Domain | Key Metric |
|---|---|---|
| Kylin-Agent | Security ops on Kylin OS V11 | 16 attacks, 0 breaches |
| Malio | Embodied AI music | 800 particles, 9 physics systems |
| Quant Trading | Daily multi-factor strategy | Sharpe 1.36, MDD 12.7% |
Same skeleton. Three domains. Different wiring.
Related Reading
- Constraint Architecture — Chinese
- Constraint Architecture — English
- Agent OS Architecture — 7-layer design
License
MIT — Xu Renwu (续仁舞), 2026.
大一。三周。一个人。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file constraint_architecture-1.5.0.tar.gz.
File metadata
- Download URL: constraint_architecture-1.5.0.tar.gz
- Upload date:
- Size: 23.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e6ead9f6999dc3ae3be23ef84a24f912e81ebdb7092deaade19c2f2cf26200b9
|
|
| MD5 |
9aa571b8e45ca074d4fdb74bada35aaf
|
|
| BLAKE2b-256 |
1eb037a500177ce1f39e37802a261611af13ea1c21f27d42d4d3cf76c7183b8d
|
Provenance
The following attestation bundles were made for constraint_architecture-1.5.0.tar.gz:
Publisher:
publish.yml on 1nour2567/Constraint-Architecture
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
constraint_architecture-1.5.0.tar.gz -
Subject digest:
e6ead9f6999dc3ae3be23ef84a24f912e81ebdb7092deaade19c2f2cf26200b9 - Sigstore transparency entry: 1849494896
- Sigstore integration time:
-
Permalink:
1nour2567/Constraint-Architecture@856a06ce8618a1f04460d4ecd13cec2769fca7fc -
Branch / Tag:
refs/tags/v1.5.0 - Owner: https://github.com/1nour2567
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@856a06ce8618a1f04460d4ecd13cec2769fca7fc -
Trigger Event:
push
-
Statement type:
File details
Details for the file constraint_architecture-1.5.0-py3-none-any.whl.
File metadata
- Download URL: constraint_architecture-1.5.0-py3-none-any.whl
- Upload date:
- Size: 22.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ab18428580fcb7ffc355d25de4d1fe7df14a7858c2e7f93fac78fef3f018a76
|
|
| MD5 |
8c948577ec9d53e0ffe657d6288cac7e
|
|
| BLAKE2b-256 |
c20a16c55e36c9f08d3e45b5905ee29e47f58927ec82b419070dd4a5821eb397
|
Provenance
The following attestation bundles were made for constraint_architecture-1.5.0-py3-none-any.whl:
Publisher:
publish.yml on 1nour2567/Constraint-Architecture
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
constraint_architecture-1.5.0-py3-none-any.whl -
Subject digest:
4ab18428580fcb7ffc355d25de4d1fe7df14a7858c2e7f93fac78fef3f018a76 - Sigstore transparency entry: 1849495032
- Sigstore integration time:
-
Permalink:
1nour2567/Constraint-Architecture@856a06ce8618a1f04460d4ecd13cec2769fca7fc -
Branch / Tag:
refs/tags/v1.5.0 - Owner: https://github.com/1nour2567
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@856a06ce8618a1f04460d4ecd13cec2769fca7fc -
Trigger Event:
push
-
Statement type: