Files
myWiki/concepts/loop-contract.md

44 lines
1.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: "Loop Contract循环协议"
created: 2026-06-29
updated: 2026-06-29
type: concept
tags: [loop-engineering, contract, safety, constraint]
sources: [[prompt-to-loop-engineering-2026]]
confidence: high
---
# Loop Contract
> 在 [[loop-engineering|Loop Engineering]] 中,策略层强制执行的一套协议,从六个维度严格约束自主循环系统,防止退化为失控的死循环。
## 六维约束
| 维度 | 含义 | 示例 |
|------|------|------|
| **TRIGGER** | 触发条件 | 每 15 分钟 / PR 评论 / CI 失败 |
| **SCOPE** | 作用范围 | 仅限特定仓库 / 仅处理自己提交的 PR |
| **ACTION** | 具体行为 | 运行测试 / 自动修复 Lint 错误 |
| **BUDGET** | 预算红线 | 单次最多 3 个子 Agent / 50k Tokens / $5 成本 |
| **STOP** | 停止条件 | 测试全绿 / 达到 10 轮上限 / 预算耗尽 |
| **REPORT** | 上报通道 | 异常时投递至 Slack |
## 固化为硬约束
BUDGET 和 STOP 直接固化为两道硬约束:
- [[circuit-breaker-pattern|熔断器Circuit Breaker]]:连续失败 N 次 → 跳闸 + 回退 + 转交人工;墙上时间超时无条件熔断
- [[watchdog-pattern|看门狗Watchdog]]:独立进程监控 CPU防自旋死循环越过应用层 SIGKILL 强杀
## 设计哲学
Loop Contract 体现了 [[mechanism-policy-separation|机制与策略分离]]底层提供熔断和看门狗机制具体阈值max_consecutive_failures、max_runtime_min由 [[loop-designer|Loop Designer]] 按业务逻辑配置。
## 相关概念
- [[loop-engineering|Loop Engineering]]
- [[mechanism-policy-separation|机制与策略分离]]
- [[circuit-breaker-pattern|熔断器]]
- [[watchdog-pattern|看门狗]]
- [[loop-designer|Loop Designer]]