arXiv:2602.22302cs.AIcs.MA2026-02被引 23

给AI代理加合同,让其行为可规范、可追踪、可恢复。

Agent Behavioral Contracts: Formal Specification and Runtime Enforcement for Reliable Autonomous AI Agents

  • 用形式化合同定义代理的前置条件、不变性、治理规则和恢复机制。
  • 实测显示合同代理能发现5.2-6.8个基线遗漏的软违规,硬约束合规率达88%-100%。
  • 适合关注安全、稳定部署AI代理的研究者与工程团队。

传统软件依赖接口、类型系统和断言来规范行为,而AI代理基于提示和自然语言指令运行,缺乏形式化行为规范。这一缺口是代理行为漂移、治理失效及项目失败的根本原因。本文提出代理行为合同(ABC),将设计契约原则引入自主AI代理。一个ABC合同C = (P, I, G, R)将前提条件、不变性、治理策略和恢复机制作为可运行时强制的第一类组件。我们定义了(p, delta, k)-满足——一种考虑大模型非确定性和恢复能力的概率性合规概念,并证明漂移边界定理:当恢复率gamma > 演变率alpha时,行为漂移期望值被限制在D* = alpha/gamma,且在随机设定下呈现高斯集中。我们建立了多代理链中安全合同组合的充分条件,并推导出概率退化边界。在AgentAssert runtime库中实现ABC,评估在包含200个场景、7个模型(来自6家厂商)的AgentContract-Bench上。1980次会话结果表明,合约代理比未加合同的基线多检测5.2-6.8个软违规(p < 0.0001,Cohen's d = 6.7-33.8),硬约束合规率达88-100%,行为漂移被控制在D* < 0.27以内,前沿模型100%恢复,所有模型恢复率17-100%,单动作开销<10毫秒。

原文摘要 · Abstract (English)

Traditional software relies on contracts -- APIs, type systems, assertions -- to specify and enforce correct behavior. AI agents, by contrast, operate on prompts and natural language instructions with no formal behavioral specification. This gap is the root cause of drift, governance failures, and frequent project failures in agentic AI deployments. We introduce Agent Behavioral Contracts (ABC), a formal framework that brings Design-by-Contract principles to autonomous AI agents. An ABC contract C = (P, I, G, R) specifies Preconditions, Invariants, Governance policies, and Recovery mechanisms as first-class, runtime-enforceable components. We define (p, delta, k)-satisfaction -- a probabilistic notion of contract compliance that accounts for LLM non-determinism and recovery -- and prove a Drift Bounds Theorem showing that contracts with recovery rate gamma > alpha (the natural drift rate) bound behavioral drift to D* = alpha/gamma in expectation, with Gaussian concentration in the stochastic setting. We establish sufficient conditions for safe contract composition in multi-agent chains and derive probabilistic degradation bounds. We implement ABC in AgentAssert, a runtime enforcement library, and evaluate on AgentContract-Bench, a benchmark of 200 scenarios across 7 models from 6 vendors. Results across 1,980 sessions show that contracted agents detect 5.2-6.8 soft violations per session that uncontracted baselines miss entirely (p < 0.0001, Cohen's d = 6.7-33.8), achieve 88-100% hard constraint compliance, and bound behavioral drift to D* < 0.27 across extended sessions, with 100% recovery for frontier models and 17-100% across all models, at overhead < 10 ms per action.

AI代理形式化验证行为约束运行时保障

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。