NeuruhAI/pmla-constraint-engineering

GitHub: NeuruhAI/pmla-constraint-engineering

一套面向生产LLM的约束工程架构,解决多轮对话中的逻辑漂移与规则失效问题。

Stars: 0 | Forks: 0

# PMLA — 提示即记忆循环架构 **Constraint Engineering for Capital-Grade AI Systems** [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/) Created by **Jeramie Hicks** · [Neuruh](https://neuruh.com) ## 问题 — 生产环境 AI 中的逻辑漂移 你的 AI 系统在前 5 个对话回合中运行完美。到第 15 个回合时,它开始产生你明确定义的业务规则幻觉。上下文窗口未满。RAG 正常工作。模型有响应。 **但业务逻辑已经发生漂移。** 这不是令牌问题。不是检索问题。甚至不是模型问题。**这是一个架构问题。** 传统 AI 系统将约束视为被动指令,模型可以遗忘、忽略或误解。PMLA 将它们转化为**跨上下文持续存在的主动验证门**。 ## 解决方案 — 约束工程 | Prompt Engineering | Constraint Engineering | |---------------------------------|---------------------------------| | "Please remember X" | **System enforces X** | | Instructions can be forgotten | **Constraints are immutable** | | Hope AI complies | **Cryptographic verification** | | Drift = silent failure | **Drift = blocked execution** | | Manual quality checks | **Automated validation gates** | ## 架构 ``` ┌──────────────────────────────────────┐ │ APPLICATION LAYER │ │ (Your AI Agent / Chatbot / etc.) │ └──────────────────────────────────────┘ ↓ ┌──────────────────────────────────────┐ │ PMLA CONSTRAINT LAYER │ │ │ │ Master Constraint Block (MCB) │ │ • Immutable business rules │ │ • Cryptographically signed (SHA-256)│ │ • Persists across sessions │ │ ↓ │ │ Intent Preservation Protocol (IPP) │ │ • Validates every turn against MCB │ │ • Drift detection + auto-correct │ │ ↓ │ │ Validation Gates │ │ • Pre-execution verification │ │ • Post-execution audit │ │ • Drift detection + correction │ └──────────────────────────────────────┘ ↓ ┌──────────────────────────────────────┐ │ MODEL LAYER │ │ (OpenAI / Anthropic / LLaMA / etc.) │ └──────────────────────────────────────┘ ``` ## 快速开始 ### 安装 ``` pip install pmla-core ``` ### 基本用法 ``` from pmla import PMLAEngine, ConstraintBlock, ValidationLevel constraints = ConstraintBlock( name="financial_underwriting", rules={ 'credit_score_minimum': { 'value': 680, 'type': 'threshold', 'enforcement': 'block' }, 'debt_to_income_ratio': { 'value': 0.43, 'type': 'threshold', 'enforcement': 'block' }, 'regulatory_compliance': { 'value': ['FCRA', 'ECOA', 'HMDA'], 'type': 'mandatory', 'enforcement': 'block' } }, validation_level=ValidationLevel.STRICT ) engine = PMLAEngine(constraints=constraints, drift_threshold=0.15, auto_correct=True) result = engine.process_turn( user_input="Approve loan for applicant with 650 credit score", agent_response="Approved! The loan meets our requirements.", context={'extracted_values': {'credit_score_minimum': 650}} ) if not result.passed: print(f"CONSTRAINT VIOLATION: {result.violations}") print(f"Blocked: {result.blocked_reason}") ``` ## 使用场景 - **金融服务** — 贷款承销、交易风险、欺诈检测 - **医疗保健** — 临床决策支持、HIPAA 合规、处方安全 - **法律** — 合同分析、管辖约束、文档保留 - **国防与政府** — 关键任务安全约束、交战规则 ## 关键创新 ### 1. 主约束块(MCB) 加密签名(SHA-256)的约束定义。在上下文边界之间不可变。会话重置后仍保留。可版本控制和审计。 ### 2. 意图保持协议(IPP) 将被动上下文转化为主动执行触发器。对每个回合验证 MCB。在语义漂移成为错误之前检测漂移。无需人工干预即可自动纠正。 ### 3. 验证门 - **执行前** — 在发生前阻止无效操作 - **执行后** — 合规性审计轨迹 - **漂移检测** — 实时监控逻辑一致性 - **恢复协议** — 自动约束重新注入 ## 商业支持 MIT 许可证用于开放使用。企业支持包括白标部署、本地安装、SLA 保证和自定义框架适配器。 联系:**jeramie@neuruh.com** ## 许可证 MIT 许可证 — 详见 [LICENSE](LICENSE)。 ## 引用 ``` @software{hicks2026pmla, author = {Hicks, Jeramie}, title = {PMLA: Prompt-as-Memory Loop Architecture for Intent Preservation in Multi-Turn AI Systems}, year = {2026}, publisher = {Neuruh}, url = {https://github.com/NeuruhAI/pmla-constraint-engineering} } ```
标签:AI系统可靠性, LLM架构, MLOps, PMLA, Prompt-as-Memory Loop Architecture, Python 3.9, 上下文管理, 主动验证门, 企业级AI系统, 密码学签名, 开源框架, 意图保留, 持续集成, 漂移检测, 生产LLM部署, 系统工程, 约束块, 约束工程, 约束架构, 自动化验证, 质量保证, 逆向工具